Orcus
Loading...
Searching...
No Matches
xml_structure_tree.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8#ifndef INCLUDED_ORCUS_XML_STRUCTURE_TREE_HPP
9#define INCLUDED_ORCUS_XML_STRUCTURE_TREE_HPP
10
11#include "env.hpp"
12#include "types.hpp"
13
14#include <ostream>
15#include <memory>
16#include <functional>
17#include <any>
18
19namespace orcus {
20
21class xmlns_context;
22
23struct ORCUS_DLLPUBLIC xml_table_range_t
24{
25 std::vector<std::string> paths;
26 std::vector<std::string> row_groups;
27
28 xml_table_range_t();
29 xml_table_range_t(const xml_table_range_t& other);
30 xml_table_range_t(xml_table_range_t&& other) noexcept;
31 ~xml_table_range_t();
32
33 xml_table_range_t& operator=(xml_table_range_t other) noexcept;
34
35 void swap(xml_table_range_t& other) noexcept;
36};
37
44class ORCUS_DLLPUBLIC xml_structure_tree
45{
46 struct impl;
47 std::unique_ptr<impl> mp_impl;
48
49public:
50 xml_structure_tree() = delete;
51 xml_structure_tree(const xml_structure_tree&) = delete;
52 xml_structure_tree& operator= (const xml_structure_tree&) = delete;
53
57 enum class callback_type : uint8_t
58 {
60 unknown = 0,
61
67 on_repeat_node
68 };
69
75 using callback_handler_type = std::function<void(std::any)>;
76
77 using range_handler_type = std::function<void(xml_table_range_t&&)>;
78
79 struct ORCUS_DLLPUBLIC entity_name
80 {
81 xmlns_id_t ns;
82 std::string_view name;
83
84 entity_name();
85 entity_name(xmlns_id_t _ns, std::string_view _name);
86
87 bool operator< (const entity_name& r) const;
88 bool operator== (const entity_name& r) const;
89
90 struct ORCUS_DLLPUBLIC hash
91 {
92 size_t operator ()(const entity_name& val) const;
93 };
94 };
95
96 typedef std::vector<entity_name> entity_names_type;
97
98 struct ORCUS_DLLPUBLIC element
99 {
100 entity_name name;
101 bool repeat;
102 bool has_content;
103
104 element();
105 element(const entity_name& _name, bool _repeat, bool _has_content);
106 };
107
108 struct walker_impl;
109
113 class ORCUS_DLLPUBLIC walker
114 {
115 friend class xml_structure_tree;
116
117 std::unique_ptr<walker_impl> mp_impl;
118
119 walker(const xml_structure_tree::impl& parent_impl);
120 public:
121 walker() = delete;
122 walker(const walker& r);
123 ~walker();
124 walker& operator= (const walker& r);
125
133
145
150
160 element move_to(const std::string& path);
161
168 entity_names_type get_children();
169
176 entity_names_type get_attributes();
177
187 size_t get_xmlns_index(xmlns_id_t ns) const;
188
189 std::string get_xmlns_short_name(xmlns_id_t ns) const;
190
199 std::string to_string(const entity_name& name) const;
200
205 std::string get_path() const;
206 };
207
208 xml_structure_tree(xmlns_context& xmlns_cxt);
209 xml_structure_tree(xml_structure_tree&& other);
210 ~xml_structure_tree();
211
220
221 void parse(std::string_view s);
222
223 void dump_compact(std::ostream& os) const;
224
225 walker get_walker() const;
226
227 void process_ranges(range_handler_type rh) const;
228
229 void swap(xml_structure_tree& other);
230};
231
232}
233
234
235
236#endif
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition xml_structure_tree.hpp:114
entity_names_type get_attributes()
element move_to(const std::string &path)
element descend(const entity_name &name)
entity_names_type get_children()
size_t get_xmlns_index(xmlns_id_t ns) const
std::string to_string(const entity_name &name) const
std::function< void(std::any)> callback_handler_type
Definition xml_structure_tree.hpp:75
void set_callback(callback_type type, callback_handler_type callback)
callback_type
Definition xml_structure_tree.hpp:58
Definition xml_namespace.hpp:100
Definition xml_structure_tree.hpp:99
Definition xml_structure_tree.hpp:91
Definition xml_structure_tree.hpp:80
Definition xml_structure_tree.hpp:24