equal
deleted
inserted
replaced
|
1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <iostream> |
|
5 #include <vector> |
|
6 |
|
7 #include "../include/typedefs.h" |
|
8 #include "../include/DataTypeWriterBase.h" |
|
9 #include "BooleanDataTypeWriter.h" |
|
10 #include "IntegerDataTypeWriter.h" |
|
11 #include "StringDataTypeWriter.h" |
|
12 |
|
13 namespace relpipe { |
|
14 namespace writer { |
|
15 |
|
16 class DataTypeCatalog { |
|
17 private: |
|
18 BooleanDataTypeWriter booleanWriter; |
|
19 IntegerDataTypeWriter integerWriter; |
|
20 StringDataTypeWriter stringWriter; |
|
21 vector<DataTypeWriterBase*> writers = {&booleanWriter, &integerWriter, &stringWriter}; |
|
22 public: |
|
23 |
|
24 integer_t toTypeId(const string_t typeCode) { |
|
25 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId(); |
|
26 throw RelpipeWriterException(L"Unsupported data type: " + typeCode); |
|
27 } |
|
28 |
|
29 string_t toTypeCode(const integer_t typeId) { |
|
30 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode(); |
|
31 throw RelpipeWriterException(L"Unsupported data type: " + typeId); |
|
32 } |
|
33 |
|
34 void writeString(std::ostream &output, const string_t &stringValue, const integer_t typeId) { |
|
35 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeString(output, stringValue); |
|
36 throw RelpipeWriterException(L"Unsupported data type: " + typeId); |
|
37 } |
|
38 |
|
39 }; |
|
40 |
|
41 } |
|
42 } |