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 __ORCUS_XML_STRUCTURE_TREE_HPP__
9 #define __ORCUS_XML_STRUCTURE_TREE_HPP__
10 
11 #include "env.hpp"
12 #include "types.hpp"
13 
14 #include <ostream>
15 
16 namespace orcus {
17 
18 class xmlns_context;
19 struct xml_structure_tree_impl;
20 
27 class ORCUS_DLLPUBLIC xml_structure_tree
28 {
29  xml_structure_tree(const xml_structure_tree&); // disabled;
30  xml_structure_tree& operator= (const xml_structure_tree&); // disabled
31 
32 public:
33 
34  struct ORCUS_DLLPUBLIC entity_name
35  {
36  xmlns_id_t ns;
37  pstring name;
38 
39  entity_name();
40  entity_name(xmlns_id_t _ns, const pstring& _name);
41 
42  bool operator< (const entity_name& r) const;
43  bool operator== (const entity_name& r) const;
44 
45  struct ORCUS_DLLPUBLIC hash
46  {
47  size_t operator ()(const entity_name& val) const;
48  };
49  };
50 
51  typedef std::vector<entity_name> entity_names_type;
52 
53  struct ORCUS_DLLPUBLIC element
54  {
55  entity_name name;
56  bool repeat;
57 
58  element();
59  element(const entity_name& _name, bool _repeat);
60  };
61 
62  struct walker_impl;
63 
67  class ORCUS_DLLPUBLIC walker
68  {
69  friend class xml_structure_tree;
70  walker_impl* mp_impl;
71 
72  walker(); // disabled
73  walker(const xml_structure_tree_impl& parent_impl);
74  public:
75  walker(const walker& r);
76  ~walker();
77  walker& operator= (const walker& r);
78 
85  element root();
86 
95  element descend(const entity_name& name);
96 
100  element ascend();
101 
108  void get_children(entity_names_type& names);
109 
116  void get_attributes(entity_names_type& names);
117 
127  size_t get_xmlns_index(xmlns_id_t ns) const;
128 
129  std::string get_xmlns_short_name(xmlns_id_t ns) const;
130 
135  std::string get_path() const;
136 
143  element select_by_path(const std::string& path);
144  };
145 
146  xml_structure_tree(xmlns_context& xmlns_cxt);
148 
149  void parse(const char* p, size_t n);
150 
151  void dump_compact(std::ostream& os) const;
152 
153  walker get_walker() const;
154 
155 private:
156  xml_structure_tree_impl* mp_impl;
157 };
158 
159 }
160 
161 
162 
163 #endif
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::xmlns_context
Definition: xml_namespace.hpp:82
orcus::xml_structure_tree
Definition: xml_structure_tree.hpp:27
orcus::xml_structure_tree::element
Definition: xml_structure_tree.hpp:53
orcus::xml_structure_tree::entity_name
Definition: xml_structure_tree.hpp:34
orcus::pstring
Definition: pstring.hpp:24
orcus::xml_structure_tree::walker
Definition: xml_structure_tree.hpp:67
orcus::xml_structure_tree::entity_name::hash
Definition: xml_structure_tree.hpp:45