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
17namespace orcus {
18
19class xmlns_context;
20
27class ORCUS_DLLPUBLIC xml_structure_tree
28{
29 struct impl;
30 std::unique_ptr<impl> mp_impl;
31
32public:
34 xml_structure_tree& operator= (const xml_structure_tree&) = delete;
35
36 struct ORCUS_DLLPUBLIC entity_name
37 {
38 xmlns_id_t ns;
39 pstring name;
40
42 entity_name(xmlns_id_t _ns, const pstring& _name);
43
44 bool operator< (const entity_name& r) const;
45 bool operator== (const entity_name& r) const;
46
47 struct ORCUS_DLLPUBLIC hash
48 {
49 size_t operator ()(const entity_name& val) const;
50 };
51 };
52
53 typedef std::vector<entity_name> entity_names_type;
54
55 struct ORCUS_DLLPUBLIC element
56 {
57 entity_name name;
58 bool repeat;
59
60 element();
61 element(const entity_name& _name, bool _repeat);
62 };
63
64 struct walker_impl;
65
69 class ORCUS_DLLPUBLIC walker
70 {
71 friend class xml_structure_tree;
72
73 std::unique_ptr<walker_impl> mp_impl;
74
75 walker(const xml_structure_tree::impl& parent_impl);
76 public:
77 walker() = delete;
78 walker(const walker& r);
79 ~walker();
80 walker& operator= (const walker& r);
81
89
99
104
111 void get_children(entity_names_type& names);
112
119 void get_attributes(entity_names_type& names);
120
130 size_t get_xmlns_index(xmlns_id_t ns) const;
131
132 std::string get_xmlns_short_name(xmlns_id_t ns) const;
133
138 std::string get_path() const;
139
146 element select_by_path(const std::string& path);
147 };
148
151
152 void parse(const char* p, size_t n);
153
154 void dump_compact(std::ostream& os) const;
155
156 walker get_walker() const;
157};
158
159}
160
161
162
163#endif
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: pstring.hpp:28
Definition: xml_structure_tree.hpp:70
element descend(const entity_name &name)
void get_attributes(entity_names_type &names)
void get_children(entity_names_type &names)
element select_by_path(const std::string &path)
size_t get_xmlns_index(xmlns_id_t ns) const
Definition: xml_structure_tree.hpp:28
Definition: xml_namespace.hpp:83
Definition: xml_structure_tree.hpp:56
Definition: xml_structure_tree.hpp:48
Definition: xml_structure_tree.hpp:37