64 virtual ~FlatINIContentHandler() { |
64 virtual ~FlatINIContentHandler() { |
65 } |
65 } |
66 |
66 |
67 void startDocument() override { |
67 void startDocument() override { |
68 vector<AttributeMetadata> metadata; |
68 vector<AttributeMetadata> metadata; |
69 metadata.push_back({L"section", TypeId::STRING}); |
69 if (configuration.enableLineNumbers) metadata.push_back({L"line", TypeId::INTEGER}); |
|
70 if (configuration.enableEventNumbers) metadata.push_back({L"event", TypeId::INTEGER}); |
|
71 if (configuration.enableSections) metadata.push_back({L"section", TypeId::STRING}); |
70 metadata.push_back({L"key", TypeId::STRING}); |
72 metadata.push_back({L"key", TypeId::STRING}); |
71 metadata.push_back({L"subkey", TypeId::STRING}); |
73 if (configuration.enableSubkeys) metadata.push_back({L"subkey", TypeId::STRING}); |
72 metadata.push_back({L"value", TypeId::STRING}); |
74 metadata.push_back({L"value", TypeId::STRING}); |
|
75 if (configuration.enableComments) metadata.push_back({L"comment", TypeId::STRING}); |
73 writer->startRelation(configuration.relation, metadata, true); |
76 writer->startRelation(configuration.relation, metadata, true); |
74 }; |
77 }; |
75 |
78 |
76 void endDocument() override { |
79 void endDocument() override { |
77 currentSection.clear(); |
80 currentSection.clear(); |
78 }; |
81 }; |
79 |
82 |
80 void startSection(const std::string& name) override { |
83 void startSection(const SectionStartEvent& event) override { |
81 currentSection.push_back(name); |
84 currentSection.push_back(event.name); |
82 }; |
85 }; |
83 |
86 |
84 void endSection() override { |
87 void endSection() override { |
85 currentSection.pop_back(); |
88 currentSection.pop_back(); |
86 }; |
89 }; |
87 |
90 |
88 void entry(const std::string& key, const std::string& subkey, const std::string& value) override { |
91 void entry(const EntryEvent& event) override { |
89 writer->writeAttribute(convertor.from_bytes(getCurrentSectionFullName())); |
92 if (configuration.enableLineNumbers) writer->writeAttribute(&event.lineNumber, typeid (event.lineNumber)); |
|
93 if (configuration.enableEventNumbers) writer->writeAttribute(&event.eventNumber, typeid (event.eventNumber)); |
|
94 |
|
95 std::string section = getCurrentSectionFullName(); |
|
96 std::string key = configuration.enableSubkeys ? event.key : event.fullKey; |
|
97 |
|
98 if (configuration.enableSections) writer->writeAttribute(convertor.from_bytes(section)); |
|
99 else if (section.size()) key = section + "/" + key; |
90 writer->writeAttribute(convertor.from_bytes(key)); |
100 writer->writeAttribute(convertor.from_bytes(key)); |
91 writer->writeAttribute(convertor.from_bytes(subkey)); |
101 if (configuration.enableSubkeys) writer->writeAttribute(convertor.from_bytes(event.subKey)); |
92 writer->writeAttribute(convertor.from_bytes(value)); |
102 |
|
103 writer->writeAttribute(convertor.from_bytes(event.value)); |
|
104 if (configuration.enableComments) writer->writeAttribute(convertor.from_bytes(event.comment)); |
93 }; |
105 }; |
94 |
106 |
95 // TODO: handle also comments and whitespace (to allow lossless transformation from INI and back to INI) |
107 // TODO: handle also comments and whitespace (to allow lossless transformation from INI and back to INI) |
96 // TODO: make subkeys (in [] brackets in the key) optional/configurable |
|
97 |
108 |
98 }; |
109 }; |
99 |
110 |
100 void INICommand::process(std::istream& input, std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
111 void INICommand::process(std::istream& input, std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
101 FlatINIContentHandler handler(writer, configuration); |
112 FlatINIContentHandler handler(writer, configuration); |