src/XMLDocumentConstructor.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 30 May 2021 20:12:05 +0200
branchv_0
changeset 30 f5ac2d29eeb4
parent 29 9254988f9382
child 31 273faff8b848
permissions -rw-r--r--
read CBOR and convert it to a flat XML DOM structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    29
#include "XMLNameCodec.h"
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    30
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    31
namespace relpipe {
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    32
namespace in {
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    33
namespace xmltable {
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    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
053054f9f702 XML name escaping
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    39
	XMLNameCodec nameCodec;
16
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    40
29
9254988f9382 CBOR skeleton: remove YAML library, add CBOR one
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    41
	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
    42
	xmlpp::Element* current;
26
84ff7c97bfdc add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    43
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
    44
	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
    45
16
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    46
	/**
29
9254988f9382 CBOR skeleton: remove YAML library, add CBOR one
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    47
	 * 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
    48
	 */
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
    49
	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
    50
		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
    51
	}
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    52
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
    53
	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
    54
		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
    55
	}
75c6685cceb9 YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    56
75c6685cceb9 YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    57
	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
    58
		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
    59
	}
75c6685cceb9 YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    60
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
public:
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	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
    64
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    65
#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
    66
#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
    67
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    68
		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
    69
			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
    70
			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
    71
			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
    72
		};
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    73
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    74
		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
    75
			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
    76
			xmlpp::Element* element = instance->current->add_child("boolean");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    77
			element->add_child_text(value ? "true" : "false");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    78
			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
    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
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
		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
    82
			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
    83
			xmlpp::Element* element = instance->current->add_child("byte-string");
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
			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
    85
			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
    86
			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
    87
			for (uint64_t i = 0; i < size; i++) hex << (int) value[i];
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
			element->add_child_text(hex.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
    89
			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
    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
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
		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
    93
			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
    94
			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
    95
			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
    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
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
		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
    99
			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
   100
			xmlpp::Element* element = instance->current->add_child("float2");
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
			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
   102
			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
   103
		};
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
		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
   106
			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
   107
			xmlpp::Element* element = instance->current->add_child("float4");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   108
			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
   109
			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
   110
		};
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
		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
   113
			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
   114
			xmlpp::Element* element = instance->current->add_child("float8");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   115
			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
   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.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
   120
			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
   121
			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
   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.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
   126
			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
   127
			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
   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_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
   132
			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
   133
			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
   134
			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
   135
		};
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
		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
   138
			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
   139
			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
   140
			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
   141
			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
   142
		};
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
		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
   145
			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
   146
			xmlpp::Element* element = instance->current->add_child("negative-int8");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   147
			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
   148
			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
   149
		};
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
		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
   152
			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
   153
			xmlpp::Element* element = instance->current->add_child("negative-int16");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   154
			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
   155
			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
   156
		};
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
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
		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
   159
			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
   160
			xmlpp::Element* element = instance->current->add_child("negative-int32");
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
			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
   162
			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
   163
		};
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
		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
   166
			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
   167
			xmlpp::Element* element = instance->current->add_child("negative-int64");
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   168
			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
   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.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
   173
			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
   174
			xmlpp::Element* element = instance->current->add_child("null");
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.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
   179
			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
   180
			xmlpp::Element* element = instance->current->add_child("string");
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
			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
   182
			element->add_child_text(c2x(value, 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
   183
			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
   184
		};
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
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   186
		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
   187
			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
   188
			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
   189
			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
   190
		};
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
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   192
		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
   193
			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
   194
			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
   195
			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
   196
			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
   197
		};
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   198
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
		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
   200
			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
   201
			xmlpp::Element* element = instance->current->add_child("uint8");
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
			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
   203
			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
   204
		};
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   205
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
		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
   207
			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
   208
			xmlpp::Element* element = instance->current->add_child("uint16");
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
			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
   210
			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
   211
		};
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
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   213
		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
   214
			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
   215
			xmlpp::Element* element = instance->current->add_child("uint32");
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
			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
   217
			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
   218
		};
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   219
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
		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
   221
			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
   222
			xmlpp::Element* element = instance->current->add_child("uint64");
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
			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
   224
			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
   225
		};
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
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
		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
   228
			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
   229
			xmlpp::Element* element = instance->current->add_child("undefined");
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_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
   231
		};
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
16
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   233
	}
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   234
3b197bf7a231 raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   235
	virtual ~XMLDocumentConstructor() {
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   236
	}
26
84ff7c97bfdc add --parser-option 'root-name' 'custom-root-element-name'
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
   237
25
0e8a58946c48 add --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   238
	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
   239
		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
   240
		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
   241
	}
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   242
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   243
	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
   244
		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
   245
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   246
		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
   247
		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
   248
		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
   249
f5ac2d29eeb4 read CBOR and convert it to a flat XML DOM structure
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
   250
		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
   251
		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
   252
		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
   253
			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
   254
			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
   255
		}
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
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
		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
   258
	}
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   259
};
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   260
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   261
}
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   262
}
17
75c6685cceb9 YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   263
}