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 
17 namespace orcus {
18 
19 class xmlns_context;
20 
27 class ORCUS_DLLPUBLIC xml_structure_tree
28 {
29  struct impl;
30  std::unique_ptr<impl> mp_impl;
31 
32 public:
33  xml_structure_tree(const xml_structure_tree&) = delete;
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 
41  entity_name();
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 
98  element descend(const entity_name& name);
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 
149  xml_structure_tree(xmlns_context& xmlns_cxt);
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: */
orcus::xmlns_context
Definition: xml_namespace.hpp:83
orcus::xml_structure_tree
Definition: xml_structure_tree.hpp:28
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::ascend
element ascend()
orcus::xml_structure_tree::walker::select_by_path
element select_by_path(const std::string &path)
orcus::xml_structure_tree::element
Definition: xml_structure_tree.hpp:56
orcus::xml_structure_tree::entity_name
Definition: xml_structure_tree.hpp:37
orcus::pstring
Definition: pstring.hpp:28
orcus::xml_structure_tree::walker::root
element root()
orcus::xml_structure_tree::walker::descend
element descend(const entity_name &name)
orcus::xml_structure_tree::walker::get_children
void get_children(entity_names_type &names)
orcus::xml_structure_tree::walker::get_attributes
void get_attributes(entity_names_type &names)
orcus::xml_structure_tree::walker
Definition: xml_structure_tree.hpp:70
orcus::xml_structure_tree::entity_name::hash
Definition: xml_structure_tree.hpp:48