src/DataTypeCatalog.h
branchv_0
changeset 7 489e52138771
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DataTypeCatalog.h	Sat Jul 14 23:24:22 2018 +0200
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "common.h"
+#include "DataType.h"
+#include "BooleanDataType.h"
+#include "IntegerDataType.h"
+#include "StringDataType.h"
+
+using namespace std;
+
+namespace rp_prototype {
+
+class DataTypeCatalog {
+private:
+	BooleanDataType booleanType;
+	IntegerDataType integerType;
+	StringDataType stringType;
+	vector<DataTypeBase*> types = {&booleanType, &integerType, &stringType};
+public:
+
+	integer_t toTypeId(const wstring typeCode) {
+		for (DataTypeBase* dataType : types) if (dataType->supports(typeCode)) return dataType->getTypeId();
+		throw RelpipeException(L"Unsupported data type: " + typeCode, EXIT_CODE_DATA_ERROR);
+	}
+
+	wstring toTypeCode(const integer_t typeId) {
+		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->getTypeCode();
+		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
+	}
+
+	void writeString(ostream &output, const wstring &stringValue, const integer_t typeId) {
+		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->writeString(output, stringValue);
+		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
+	}
+
+	wstring readString(istream &input, const integer_t typeId) {
+		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->readString(input);
+		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
+	}
+
+};
+
+}
\ No newline at end of file