|
1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <iostream> |
|
5 #include <vector> |
|
6 |
|
7 #include "../include/typedefs.h" |
|
8 #include "../include/RelationalWriter.h" |
|
9 #include "DataTypeWriterBase.h" |
|
10 #include "BooleanDataTypeWriter.h" |
|
11 #include "IntegerDataTypeWriter.h" |
|
12 #include "StringDataTypeWriter.h" |
|
13 |
|
14 namespace relpipe { |
|
15 namespace writer { |
|
16 |
|
17 class StreamRelationalWriter : public RelationalWriter { |
|
18 private: |
|
19 std::ostream &output; |
|
20 BooleanDataTypeWriter booleanWriter; |
|
21 IntegerDataTypeWriter integerWriter; |
|
22 StringDataTypeWriter stringWriter; |
|
23 vector<DataTypeWriterBase*> writers = {&booleanWriter, &integerWriter, &stringWriter}; |
|
24 |
|
25 void writeString(const string_t &stringValue, const integer_t typeId) { |
|
26 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeString(output, stringValue); |
|
27 throw RelpipeWriterException(L"Unsupported data type: " + typeId); |
|
28 } |
|
29 |
|
30 public: |
|
31 |
|
32 StreamRelationalWriter(std::ostream &output) : |
|
33 output(output) { |
|
34 } |
|
35 |
|
36 integer_t toTypeId(const string_t typeCode) override { |
|
37 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId(); |
|
38 throw RelpipeWriterException(L"Unsupported data type: " + typeCode); |
|
39 } |
|
40 |
|
41 string_t toTypeCode(const integer_t typeId) override { |
|
42 for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode(); |
|
43 throw RelpipeWriterException(L"Unsupported data type: " + typeId); |
|
44 } |
|
45 |
|
46 void startRelation(std::vector<std::pair<string_t, string_t> > attributes, boolean_t writeHeader) override { |
|
47 output << "startRelation(…)" << std::endl; |
|
48 } |
|
49 |
|
50 void writeRecord(std::vector<string_t> attributes) override { |
|
51 output << "writeRecord(…)" << std::endl; |
|
52 } |
|
53 |
|
54 }; |
|
55 |
|
56 } |
|
57 } |