author | František Kučera <franta-hg@frantovo.cz> |
Tue, 01 Jun 2021 19:25:12 +0200 | |
branch | v_0 |
changeset 31 | 273faff8b848 |
parent 30 | f5ac2d29eeb4 |
child 32 | 82b7f6e41a65 |
permissions | -rw-r--r-- |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#pragma once |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
19 |
#include <codecvt> |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
20 |
#include <vector> |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
21 |
#include <sstream> |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
22 |
#include <iomanip> |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
23 |
|
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <libxml++-2.6/libxml++/libxml++.h> |
29
9254988f9382
CBOR skeleton: remove YAML library, add CBOR one
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
25 |
#include <cbor.h> |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
27 |
#include <relpipe/writer/RelpipeWriterException.h> |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
28 |
|
21 | 29 |
#include "XMLNameCodec.h" |
30 |
||
31 |
namespace relpipe { |
|
32 |
namespace in { |
|
33 |
namespace xmltable { |
|
34 |
||
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
class XMLDocumentConstructor { |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
private: |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
std::istream* input = nullptr; |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
xmlpp::DomParser* parser = nullptr; |
21 | 39 |
XMLNameCodec nameCodec; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
40 |
|
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
41 |
enum class Mode { |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
42 |
ROOT, |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
43 |
SEQUENCE, |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
44 |
MAPPING, |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
45 |
MAP_KEY |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
46 |
}; |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
47 |
|
29
9254988f9382
CBOR skeleton: remove YAML library, add CBOR one
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
48 |
std::string rootName = "cbor"; |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
49 |
xmlpp::Element* current; |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
50 |
std::vector<Mode> mode; |
26
84ff7c97bfdc
add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
51 |
|
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
52 |
cbor_callbacks callbacks = cbor_empty_callbacks; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
53 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
54 |
/** |
29
9254988f9382
CBOR skeleton: remove YAML library, add CBOR one
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
55 |
* Both CBOR and XML strings are in UTF-8. |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
56 |
*/ |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
57 |
static std::string c2x(cbor_data value, uint64_t length) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
58 |
return value && length > 0 ? std::string((const char*) value, length) : ""; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
59 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
60 |
|
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
61 |
const Glib::ustring c2xname(cbor_data value, uint64_t length) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
62 |
return nameCodec.encode(c2x(value, length)); |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
63 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
64 |
|
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
65 |
xmlpp::Element* parentOrSelf(xmlpp::Element* current) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
66 |
return current->get_parent() == nullptr ? current : current->get_parent(); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
67 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
68 |
|
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
69 |
void appendScalarValue(Glib::ustring value, Glib::ustring cborType, bool isNull = false) { |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
70 |
// TODO: different behavior depending on mode |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
71 |
xmlpp::Element* element = current->add_child("scalar"); |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
72 |
element->add_child_text(value); |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
73 |
element->set_attribute("type", cborType); |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
74 |
} |
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
75 |
|
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
public: |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
79 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
80 |
#define CBOR_CALLBACK_START if (XMLDocumentConstructor* instance = static_cast<XMLDocumentConstructor*> (context)) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
81 |
#define CBOR_CALLBACK_END } else throw relpipe::writer::RelpipeWriterException(L"Invalid context in the CBOR callback."); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
82 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
83 |
callbacks.array_start = [](void* context, size_t size) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
84 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
85 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
86 |
xmlpp::Element* element = instance->current->add_child("array-start"); |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
87 |
element->set_attribute("size", std::to_string(size)); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
88 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
89 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
90 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
91 |
callbacks.boolean = [](void* context, bool value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
92 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
93 |
instance->appendScalarValue(value ? "true" : "false", "boolean"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
94 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
95 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
96 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
97 |
callbacks.byte_string = [](void* context, cbor_data value, uint64_t size) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
98 |
CBOR_CALLBACK_START |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
99 |
std::stringstream hex; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
100 |
hex << std::hex << std::setfill('0') << std::setw(2); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
101 |
for (uint64_t i = 0; i < size; i++) hex << (int) value[i]; |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
102 |
instance->appendScalarValue(hex.str(), "byte-string"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
103 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
104 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
105 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
106 |
callbacks.byte_string_start = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
107 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
108 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
109 |
xmlpp::Element* element = instance->current->add_child("byte-string-start"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
110 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
111 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
112 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
113 |
callbacks.float2 = [](void* context, float value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
114 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
115 |
instance->appendScalarValue(std::to_string(value), "float2"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
116 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
117 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
118 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
119 |
callbacks.float4 = [](void* context, float value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
120 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
121 |
instance->appendScalarValue(std::to_string(value), "float4"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
122 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
123 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
124 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
125 |
callbacks.float8 = [](void* context, double value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
126 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
127 |
instance->appendScalarValue(std::to_string(value), "float8"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
128 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
129 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
130 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
131 |
callbacks.indef_array_start = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
132 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
133 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
134 |
xmlpp::Element* element = instance->current->add_child("array-start"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
135 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
136 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
137 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
138 |
callbacks.indef_map_start = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
139 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
140 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
141 |
xmlpp::Element* element = instance->current->add_child("map-start"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
142 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
143 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
144 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
145 |
callbacks.indef_break = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
146 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
147 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
148 |
xmlpp::Element* element = instance->current->add_child("indef-break"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
149 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
150 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
151 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
152 |
callbacks.map_start = [](void* context, size_t size) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
153 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
154 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
155 |
xmlpp::Element* element = instance->current->add_child("map-start"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
156 |
element->set_attribute("size", std::to_string(size)); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
157 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
158 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
159 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
160 |
callbacks.negint8 = [](void* context, uint8_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
161 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
162 |
instance->appendScalarValue(std::to_string(value), "negative-int8"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
163 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
164 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
165 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
166 |
callbacks.negint16 = [](void* context, uint16_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
167 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
168 |
instance->appendScalarValue(std::to_string(value), "negative-int16"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
169 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
170 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
171 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
172 |
callbacks.negint32 = [](void* context, uint32_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
173 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
174 |
instance->appendScalarValue(std::to_string(value), "negative-int32"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
175 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
176 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
177 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
178 |
callbacks.negint64 = [](void* context, uint64_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
179 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
180 |
instance->appendScalarValue(std::to_string(value), "negative-int64"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
181 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
182 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
183 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
184 |
callbacks.null = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
185 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
186 |
instance->appendScalarValue("", "null", true); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
187 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
188 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
189 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
190 |
callbacks.string = [](void* context, cbor_data value, uint64_t size) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
191 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
192 |
instance->appendScalarValue(c2x(value, size), "string"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
193 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
194 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
195 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
196 |
callbacks.string_start = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
197 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
198 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
199 |
xmlpp::Element* element = instance->current->add_child("string-start"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
200 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
201 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
202 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
203 |
callbacks.tag = [](void* context, uint64_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
204 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
205 |
// TODO: implement |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
206 |
xmlpp::Element* element = instance->current->add_child("tag"); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
207 |
element->add_child_text(std::to_string(value)); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
208 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
209 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
210 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
211 |
callbacks.uint8 = [](void* context, uint8_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
212 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
213 |
instance->appendScalarValue(std::to_string(value), "uint8"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
214 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
215 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
216 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
217 |
callbacks.uint16 = [](void* context, uint16_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
218 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
219 |
instance->appendScalarValue(std::to_string(value), "uint16"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
220 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
221 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
222 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
223 |
callbacks.uint32 = [](void* context, uint32_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
224 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
225 |
instance->appendScalarValue(std::to_string(value), "uint32"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
226 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
227 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
228 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
229 |
callbacks.uint64 = [](void* context, uint64_t value) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
230 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
231 |
instance->appendScalarValue(std::to_string(value), "uint64"); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
232 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
233 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
234 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
235 |
callbacks.undefined = [](void* context) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
236 |
CBOR_CALLBACK_START |
31
273faff8b848
pass all scalar values through a single method
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
237 |
instance->appendScalarValue("undefined", "undefined", true); // FIXME: throw exception? |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
238 |
CBOR_CALLBACK_END |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
239 |
}; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
240 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
241 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
242 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
243 |
virtual ~XMLDocumentConstructor() { |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
244 |
} |
26
84ff7c97bfdc
add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
245 |
|
25
0e8a58946c48
add --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
246 |
void setOption(const std::string& uri, const std::string& value) { |
26
84ff7c97bfdc
add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
247 |
if (uri == "root-name") rootName = value; |
84ff7c97bfdc
add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
248 |
else throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“"); |
25
0e8a58946c48
add --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
249 |
} |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
250 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
251 |
void process() { |
26
84ff7c97bfdc
add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
252 |
current = parser->get_document()->create_root_node(rootName); |
30
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
253 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
254 |
std::stringstream bufferStream; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
255 |
for (char ch = input->get(); input->good(); ch = input->get()) bufferStream.put(ch); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
256 |
std::string buffer = bufferStream.str(); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
257 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
258 |
size_t bytesRead = 0; |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
259 |
size_t length = buffer.size(); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
260 |
for (cbor_decoder_result result; bytesRead < length; bytesRead += result.read) { |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
261 |
result = cbor_stream_decode((cbor_data) buffer.c_str() + bytesRead, length - bytesRead, &callbacks, this); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
262 |
if (result.status != cbor_decoder_status::CBOR_DECODER_FINISHED) throw relpipe::writer::RelpipeWriterException(L"CBOR parsing failed: status = " + std::to_wstring(result.status)); |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
263 |
} |
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
264 |
|
f5ac2d29eeb4
read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
265 |
parser->get_document()->get_root_node()->set_attribute("bytes-read", std::to_string(bytesRead)); |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
266 |
} |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
267 |
}; |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
268 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
269 |
} |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
270 |
} |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
271 |
} |