Orcus
yaml_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_YAML_DOCUMENT_TREE_HPP
9 #define INCLUDED_ORCUS_YAML_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 pstring;
21 class yaml_document_tree;
22 
23 class ORCUS_DLLPUBLIC yaml_document_error : public general_error
24 {
25 public:
26  yaml_document_error(const std::string& msg);
27  virtual ~yaml_document_error() throw();
28 };
29 
30 namespace yaml { namespace detail {
31 
32 class node;
33 struct yaml_value;
34 
35 enum class node_t
36 {
37  unset,
38  string,
39  number,
40  map,
41  sequence,
42  boolean_true,
43  boolean_false,
44  null
45 };
46 
47 class ORCUS_DLLPUBLIC node
48 {
49  friend class ::orcus::yaml_document_tree;
50 
51  struct impl;
52  std::unique_ptr<impl> mp_impl;
53 
54  node(const yaml_value* yv);
55 
56 public:
57  node() = delete;
58 
59  node(const node& other);
60  node(node&& rhs);
61  ~node();
62 
63  node_t type() const;
64 
65  size_t child_count() const;
66 
67  std::vector<node> keys() const;
68 
69  node key(size_t index) const;
70 
71  node child(size_t index) const;
72 
73  node child(const node& key) const;
74 
75  node parent() const;
76 
77  pstring string_value() const;
78  double numeric_value() const;
79 
80  node& operator=(const node& other);
81 
82  uintptr_t identity() const;
83 };
84 
85 }}
86 
87 using yaml_node_t = yaml::detail::node_t;
88 
89 class ORCUS_DLLPUBLIC yaml_document_tree
90 {
91  struct impl;
92  std::unique_ptr<impl> mp_impl;
93 
94 public:
95  using node = yaml::detail::node;
96 
99 
100  void load(const std::string& strm);
101 
102  size_t get_document_count() const;
103 
104  node get_document_root(size_t index) const;
105 
106  std::string dump_yaml() const;
107 
108  std::string dump_json() const;
109 };
110 
111 }
112 
113 #endif
114 
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: yaml_document_tree.hpp:23
Definition: yaml_document_tree.hpp:47
Definition: pstring.hpp:24
Definition: exception.hpp:18
Definition: yaml_document_tree.hpp:89
Definition: base64.hpp:15