equal
deleted
inserted
replaced
37 namespace ini { |
37 namespace ini { |
38 |
38 |
39 class INILiteralHandler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
39 class INILiteralHandler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
40 private: |
40 private: |
41 INIWriter& writer; |
41 INIWriter& writer; |
42 relpipe::common::type::StringX sectionAttributeName; |
42 bool hasSections = false; |
43 relpipe::common::type::StringX currentSection; |
43 relpipe::common::type::StringX currentSection; |
44 std::vector<relpipe::reader::handlers::AttributeMetadata> currentAttributes; |
44 std::vector<relpipe::reader::handlers::AttributeMetadata> currentAttributes; |
45 relpipe::common::type::Integer relationCount = 0; |
45 relpipe::common::type::Integer relationCount = 0; |
46 relpipe::common::type::Integer currentAttributeIndex = 0; |
46 relpipe::common::type::Integer currentAttributeIndex = 0; |
47 public: |
47 public: |
48 |
48 |
49 INILiteralHandler(INIWriter& writer, relpipe::common::type::StringX sectionAttributeName = L"") : writer(writer), sectionAttributeName(sectionAttributeName) { |
49 INILiteralHandler(INIWriter& writer) : writer(writer) { |
50 } |
50 } |
51 |
51 |
52 virtual ~INILiteralHandler() { |
52 virtual ~INILiteralHandler() { |
53 } |
53 } |
54 |
54 |
57 currentSection = name; |
57 currentSection = name; |
58 currentAttributes = attributes; |
58 currentAttributes = attributes; |
59 INIWriter::SectionStartEvent e; |
59 INIWriter::SectionStartEvent e; |
60 e.name = name; |
60 e.name = name; |
61 writer.startSection(e); |
61 writer.startSection(e); |
|
62 hasSections = true; |
62 relationCount++; |
63 relationCount++; |
63 } |
64 } |
64 |
65 |
65 void attribute(const relpipe::common::type::StringX& value) override { |
66 void attribute(const relpipe::common::type::StringX& value) override { |
66 if (currentAttributeIndex && currentAttributeIndex % currentAttributes.size() == 0) { |
67 if (currentAttributeIndex && currentAttributeIndex % currentAttributes.size() == 0) { |
70 // But if there are more of them, we will rather create multiple sections with same name (makes more sense) |
71 // But if there are more of them, we will rather create multiple sections with same name (makes more sense) |
71 // than duplicate keys in a single section. |
72 // than duplicate keys in a single section. |
72 INIWriter::SectionStartEvent e; |
73 INIWriter::SectionStartEvent e; |
73 e.name = currentSection; |
74 e.name = currentSection; |
74 writer.startSection(e); |
75 writer.startSection(e); |
|
76 hasSections = true; |
75 } |
77 } |
76 |
78 |
77 INIWriter::EntryEvent e; |
79 INIWriter::EntryEvent e; |
78 e.key = currentAttributes[currentAttributeIndex].getAttributeName(); |
80 e.key = currentAttributes[currentAttributeIndex].getAttributeName(); |
79 e.value = value; |
81 e.value = value; |
81 |
83 |
82 currentAttributeIndex++; |
84 currentAttributeIndex++; |
83 } |
85 } |
84 |
86 |
85 void endOfPipe() { |
87 void endOfPipe() { |
86 writer.endSection(); |
88 if (hasSections) writer.endSection(); |
87 } |
89 } |
88 |
90 |
89 }; |
91 }; |
90 |
92 |
91 } |
93 } |