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
29};
30
37class ORCUS_DLLPUBLIC xml_structure_tree
38{
39 struct impl;
40 std::unique_ptr<impl> mp_impl;
41
42public:
43 xml_structure_tree() = delete;
45 xml_structure_tree& operator= (const xml_structure_tree&) = delete;
46
47 struct ORCUS_DLLPUBLIC entity_name
48 {
49 xmlns_id_t ns;
50 std::string_view name;
51
53 entity_name(xmlns_id_t _ns, std::string_view _name);
54
55 bool operator< (const entity_name& r) const;
56 bool operator== (const entity_name& r) const;
57
58 struct ORCUS_DLLPUBLIC hash
59 {
60 size_t operator ()(const entity_name& val) const;
61 };
62 };
63
64 typedef std::vector<entity_name> entity_names_type;
65
66 struct ORCUS_DLLPUBLIC element
67 {
68 entity_name name;
69 bool repeat;
70 bool has_content;
71
72 element();
73 element(const entity_name& _name, bool _repeat, bool _has_content);
74 };
75
76 struct walker_impl;
77
81 class ORCUS_DLLPUBLIC walker
82 {
83 friend class xml_structure_tree;
84
85 std::unique_ptr<walker_impl> mp_impl;
86
87 walker(const xml_structure_tree::impl& parent_impl);
88 public:
89 walker() = delete;
90 walker(const walker& r);
91 ~walker();
92 walker& operator= (const walker& r);
93
101
113
118
128 element move_to(const std::string& path);
129
136 entity_names_type get_children();
137
144 entity_names_type get_attributes();
145
155 size_t get_xmlns_index(xmlns_id_t ns) const;
156
157 std::string get_xmlns_short_name(xmlns_id_t ns) const;
158
167 std::string to_string(const entity_name& name) const;
168
173 std::string get_path() const;
174 };
175
179
180 void parse(std::string_view s);
181
182 void dump_compact(std::ostream& os) const;
183
184 walker get_walker() const;
185
186 using range_handler_type = std::function<void(xml_table_range_t&&)>;
187
188 void process_ranges(range_handler_type rh) const;
189
190 void swap(xml_structure_tree& other);
191};
192
193}
194
195
196
197#endif
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition xml_structure_tree.hpp:82
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_structure_tree.hpp:38
Definition xml_namespace.hpp:82
Definition xml_structure_tree.hpp:67
Definition xml_structure_tree.hpp:59
Definition xml_structure_tree.hpp:48
Definition xml_structure_tree.hpp:23