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
18namespace orcus {
19
20class xmlns_context;
21
22struct ORCUS_DLLPUBLIC xml_table_range_t
23{
24 std::vector<std::string> paths;
25 std::vector<std::string> row_groups;
26
27 xml_table_range_t();
28 xml_table_range_t(const xml_table_range_t& other);
29 xml_table_range_t(xml_table_range_t&& other) noexcept;
30 ~xml_table_range_t();
31
32 xml_table_range_t& operator=(xml_table_range_t other) noexcept;
33
34 void swap(xml_table_range_t& other) noexcept;
35};
36
43class ORCUS_DLLPUBLIC xml_structure_tree
44{
45 struct impl;
46 std::unique_ptr<impl> mp_impl;
47
48public:
49 xml_structure_tree() = delete;
50 xml_structure_tree(const xml_structure_tree&) = delete;
51 xml_structure_tree& operator= (const xml_structure_tree&) = delete;
52
53 struct ORCUS_DLLPUBLIC entity_name
54 {
55 xmlns_id_t ns;
56 std::string_view name;
57
58 entity_name();
59 entity_name(xmlns_id_t _ns, std::string_view _name);
60
61 bool operator< (const entity_name& r) const;
62 bool operator== (const entity_name& r) const;
63
64 struct ORCUS_DLLPUBLIC hash
65 {
66 size_t operator ()(const entity_name& val) const;
67 };
68 };
69
70 typedef std::vector<entity_name> entity_names_type;
71
72 struct ORCUS_DLLPUBLIC element
73 {
74 entity_name name;
75 bool repeat;
76 bool has_content;
77
78 element();
79 element(const entity_name& _name, bool _repeat, bool _has_content);
80 };
81
82 struct walker_impl;
83
87 class ORCUS_DLLPUBLIC walker
88 {
89 friend class xml_structure_tree;
90
91 std::unique_ptr<walker_impl> mp_impl;
92
93 walker(const xml_structure_tree::impl& parent_impl);
94 public:
95 walker() = delete;
96 walker(const walker& r);
97 ~walker();
98 walker& operator= (const walker& r);
99
107
119
124
134 element move_to(const std::string& path);
135
142 entity_names_type get_children();
143
150 entity_names_type get_attributes();
151
161 size_t get_xmlns_index(xmlns_id_t ns) const;
162
163 std::string get_xmlns_short_name(xmlns_id_t ns) const;
164
173 std::string to_string(const entity_name& name) const;
174
179 std::string get_path() const;
180 };
181
182 xml_structure_tree(xmlns_context& xmlns_cxt);
183 xml_structure_tree(xml_structure_tree&& other);
184 ~xml_structure_tree();
185
186 void parse(std::string_view s);
187
188 void dump_compact(std::ostream& os) const;
189
190 walker get_walker() const;
191
192 using range_handler_type = std::function<void(xml_table_range_t&&)>;
193
194 void process_ranges(range_handler_type rh) const;
195
196 void swap(xml_structure_tree& other);
197};
198
199}
200
201
202
203#endif
204/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition xml_structure_tree.hpp:88
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
Definition xml_namespace.hpp:100
Definition xml_structure_tree.hpp:73
Definition xml_structure_tree.hpp:65
Definition xml_structure_tree.hpp:54
Definition xml_structure_tree.hpp:23