23 #include <sstream> |
23 #include <sstream> |
24 #include <locale> |
24 #include <locale> |
25 #include <codecvt> |
25 #include <codecvt> |
26 #include <stdexcept> |
26 #include <stdexcept> |
27 |
27 |
28 #include <relpipe/reader/typedefs.h> |
28 #include <relpipe/common/type/typedefs.h> |
29 #include <relpipe/reader/TypeId.h> |
29 #include <relpipe/reader/TypeId.h> |
30 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
30 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
31 #include <relpipe/reader/handlers/AttributeMetadata.h> |
31 #include <relpipe/reader/handlers/AttributeMetadata.h> |
32 |
32 |
33 #include "Configuration.h" |
33 #include "Configuration.h" |
34 |
34 |
35 namespace relpipe { |
35 namespace relpipe { |
36 namespace out { |
36 namespace out { |
37 namespace x11 { |
37 namespace x11 { |
38 |
38 |
39 using namespace relpipe; |
39 class X11Handler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
40 using namespace relpipe::reader; |
|
41 using namespace relpipe::reader::handlers; |
|
42 |
|
43 class X11Handler : public RelationalReaderStringHandler { |
|
44 private: |
40 private: |
45 std::ostream& output; |
41 std::ostream& output; |
46 Configuration& configuration; |
42 Configuration& configuration; |
47 const char QUOTE = '"'; |
43 const char QUOTE = '"'; |
48 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: probably not needed |
44 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: probably not needed |
49 std::vector<AttributeMetadata> firstAttributes; |
45 std::vector<relpipe::reader::handlers::AttributeMetadata> firstAttributes; |
50 integer_t valueCount = 0; |
46 relpipe::common::type::Integer valueCount = 0; |
51 public: |
47 public: |
52 |
48 |
53 X11Handler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) { |
49 X11Handler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) { |
54 } |
50 } |
55 |
51 |
56 void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override { |
52 void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override { |
57 if (firstAttributes.empty()) { |
53 if (firstAttributes.empty()) { |
58 firstAttributes = attributes; |
54 firstAttributes = attributes; |
59 if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName()); |
55 if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName()); |
60 } else { |
56 } else { |
61 throw std::logic_error("Only a single relation can be converted to the X11 format."); |
57 throw std::logic_error("Only a single relation can be converted to the X11 format."); |
62 } |
58 } |
63 } |
59 } |
64 |
60 |
65 void attribute(const string_t& value) override { |
61 void attribute(const relpipe::common::type::StringX& value) override { |
66 valueCount++; |
62 valueCount++; |
67 |
63 |
68 if (value.size() > 0) { |
64 if (value.size() > 0) { |
69 output << QUOTE; |
65 output << QUOTE; |
70 for (auto ch : convertor.to_bytes(value)) { |
66 for (auto ch : convertor.to_bytes(value)) { |