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