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 #include <functional>
17 
18 namespace orcus {
19 
20 class xmlns_context;
21 
22 struct ORCUS_DLLPUBLIC xml_table_range_t
23 {
24  std::vector<std::string> paths;
25  std::vector<std::string> row_groups;
26 
29 };
30 
37 class ORCUS_DLLPUBLIC xml_structure_tree
38 {
39  struct impl;
40  std::unique_ptr<impl> mp_impl;
41 
42 public:
43  xml_structure_tree() = delete;
44  xml_structure_tree(const 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  pstring name;
51 
52  entity_name();
53  entity_name(xmlns_id_t _ns, const pstring& _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 
100  element root();
101 
110  element descend(const entity_name& name);
111 
115  element ascend();
116 
126  element move_to(const std::string& path);
127 
134  entity_names_type get_children();
135 
142  entity_names_type get_attributes();
143 
153  size_t get_xmlns_index(xmlns_id_t ns) const;
154 
155  std::string get_xmlns_short_name(xmlns_id_t ns) const;
156 
165  std::string to_string(const entity_name& name) const;
166 
171  std::string get_path() const;
172  };
173 
174  xml_structure_tree(xmlns_context& xmlns_cxt);
177 
178  void parse(const char* p, size_t n);
179 
180  void dump_compact(std::ostream& os) const;
181 
182  walker get_walker() const;
183 
184  using range_handler_type = std::function<void(xml_table_range_t&&)>;
185 
186  void process_ranges(range_handler_type rh) const;
187 
188  void swap(xml_structure_tree& other);
189 };
190 
191 }
192 
193 
194 
195 #endif
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: pstring.hpp:27
Definition: xml_structure_tree.hpp:37
Definition: xml_structure_tree.hpp:22
Definition: xml_namespace.hpp:82
Definition: xml_structure_tree.hpp:58
Definition: xml_structure_tree.hpp:66
Definition: xml_structure_tree.hpp:47
Definition: xml_structure_tree.hpp:81
Definition: base64.hpp:15