Orcus
Toggle main menu visibility
Loading...
Searching...
No Matches
include
orcus
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
19
namespace
orcus {
20
21
class
xmlns_context
;
22
23
struct
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
44
class
ORCUS_DLLPUBLIC xml_structure_tree
45
{
46
struct
impl;
47
std::unique_ptr<impl> mp_impl;
48
49
public
:
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
132
element
root
();
133
144
element
descend
(
const
entity_name
& name);
145
149
element
ascend
();
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
219
void
set_callback
(
callback_type
type,
callback_handler_type
callback);
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: */
orcus::xml_structure_tree::walker
Definition
xml_structure_tree.hpp:114
orcus::xml_structure_tree::walker::ascend
element ascend()
orcus::xml_structure_tree::walker::root
element root()
orcus::xml_structure_tree::walker::get_attributes
entity_names_type get_attributes()
orcus::xml_structure_tree::walker::move_to
element move_to(const std::string &path)
orcus::xml_structure_tree::walker::descend
element descend(const entity_name &name)
orcus::xml_structure_tree::walker::get_children
entity_names_type get_children()
orcus::xml_structure_tree::walker::get_path
std::string get_path() const
orcus::xml_structure_tree::walker::get_xmlns_index
size_t get_xmlns_index(xmlns_id_t ns) const
orcus::xml_structure_tree::walker::to_string
std::string to_string(const entity_name &name) const
orcus::xml_structure_tree::callback_handler_type
std::function< void(std::any)> callback_handler_type
Definition
xml_structure_tree.hpp:75
orcus::xml_structure_tree::set_callback
void set_callback(callback_type type, callback_handler_type callback)
orcus::xml_structure_tree::callback_type
callback_type
Definition
xml_structure_tree.hpp:58
orcus::xmlns_context
Definition
xml_namespace.hpp:100
orcus::xml_structure_tree::element
Definition
xml_structure_tree.hpp:99
orcus::xml_structure_tree::entity_name::hash
Definition
xml_structure_tree.hpp:91
orcus::xml_structure_tree::entity_name
Definition
xml_structure_tree.hpp:80
orcus::xml_table_range_t
Definition
xml_structure_tree.hpp:24
Generated on
for Orcus by
1.17.0