1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <iostream> |
|
5 #include <vector> |
|
6 |
|
7 #include "common.h" |
|
8 #include "DataType.h" |
|
9 #include "BooleanDataType.h" |
|
10 #include "IntegerDataType.h" |
|
11 #include "StringDataType.h" |
|
12 |
|
13 using namespace std; |
|
14 |
|
15 namespace rp_prototype { |
|
16 |
|
17 class DataTypeCatalog { |
|
18 private: |
|
19 BooleanDataType booleanType; |
|
20 IntegerDataType integerType; |
|
21 StringDataType stringType; |
|
22 vector<DataTypeBase*> types = {&booleanType, &integerType, &stringType}; |
|
23 public: |
|
24 |
|
25 integer_t toTypeId(const wstring typeCode) { |
|
26 for (DataTypeBase* dataType : types) if (dataType->supports(typeCode)) return dataType->getTypeId(); |
|
27 throw RelpipeException(L"Unsupported data type: " + typeCode, EXIT_CODE_DATA_ERROR); |
|
28 } |
|
29 |
|
30 wstring toTypeCode(const integer_t typeId) { |
|
31 for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->getTypeCode(); |
|
32 throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR); |
|
33 } |
|
34 |
|
35 void writeString(ostream &output, const wstring &stringValue, const integer_t typeId) { |
|
36 for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->writeString(output, stringValue); |
|
37 throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR); |
|
38 } |
|
39 |
|
40 wstring readString(istream &input, const integer_t typeId) { |
|
41 for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->readString(input); |
|
42 throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR); |
|
43 } |
|
44 |
|
45 }; |
|
46 |
|
47 } |
|