Orcus
json_document_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_JSON_DOCUMENT_TREE_HPP
9 #define INCLUDED_ORCUS_JSON_DOCUMENT_TREE_HPP
10 
11 #include "orcus/env.hpp"
12 #include "orcus/exception.hpp"
13 
14 #include <string>
15 #include <memory>
16 #include <vector>
17 
18 namespace orcus {
19 
20 class string_pool;
21 
22 class ORCUS_DLLPUBLIC json_document_error : public general_error
23 {
24 public:
25  json_document_error(const std::string& msg);
26  virtual ~json_document_error() throw();
27 };
28 
29 struct json_config;
30 class json_document_tree;
31 class pstring;
32 
33 namespace json { namespace detail {
34 
35 struct json_value;
36 
37 enum class node_t
38 {
40  unset,
42  string,
44  number,
49  object,
53  array,
57  boolean_true,
61  boolean_false,
65  null
66 };
67 
72 class ORCUS_DLLPUBLIC node
73 {
74  friend class ::orcus::json_document_tree;
75 
76  struct impl;
77  std::unique_ptr<impl> mp_impl;
78 
79  node(const json_value* jv);
80 
81 public:
82  node() = delete;
83 
84  node(const node& other);
85  node(node&& rhs);
86  ~node();
87 
93  node_t type() const;
94 
100  size_t child_count() const;
101 
109  std::vector<pstring> keys() const;
110 
125  pstring key(size_t index) const;
126 
140  node child(size_t index) const;
141 
152  node child(const pstring& key) const;
153 
162  node parent() const;
163 
172  pstring string_value() const;
173 
182  double numeric_value() const;
183 
184  node& operator=(const node& other);
185 
193  uintptr_t identity() const;
194 };
195 
196 }}
197 
198 typedef json::detail::node_t json_node_t;
199 
203 class ORCUS_DLLPUBLIC json_document_tree
204 {
205  struct impl;
206  std::unique_ptr<impl> mp_impl;
207 
208 public:
209  typedef json::detail::node node;
210 
214 
222  void load(const std::string& strm, const json_config& config);
223 
232  void load(const char* p, size_t n, const json_config& config);
233 
239  node get_document_root() const;
240 
246  std::string dump() const;
247 
254  std::string dump_xml() const;
255 };
256 
257 }
258 
259 #endif
260 
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: pstring.hpp:24
Definition: json_document_tree.hpp:22
Definition: exception.hpp:18
Definition: json_document_tree.hpp:72
Definition: config.hpp:17
Definition: string_pool.hpp:22
Definition: config.hpp:34
Definition: json_document_tree.hpp:203
Definition: base64.hpp:15