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