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