Orcus
Loading...
Searching...
No Matches
json_structure_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_STRUCTURE_TREE_HPP
9#define INCLUDED_ORCUS_JSON_STRUCTURE_TREE_HPP
10
11#include "orcus/env.hpp"
12#include "orcus/types.hpp"
13
14#include <ostream>
15#include <memory>
16#include <vector>
17#include <functional>
18#include <any>
19
20namespace orcus { namespace json {
21
22struct ORCUS_DLLPUBLIC table_range_t
23{
24 std::vector<std::string> paths;
25 std::vector<std::string> row_groups;
26};
27
28class ORCUS_DLLPUBLIC structure_tree
29{
30 struct impl;
31 std::unique_ptr<impl> mp_impl;
32
33public:
34
35 enum class node_type : uint8_t { unknown = 0, array = 1, object = 2, object_key = 3, value = 4 };
36
40 enum class callback_type : uint8_t
41 {
43 unknown = 0,
44
51 on_repeat_node
52 };
53
59 using callback_handler_type = std::function<void(std::any)>;
60
61 using range_handler_type = std::function<void(table_range_t&&)>;
62
64 {
65 node_type type;
66 bool repeat;
67 };
68
69 class ORCUS_DLLPUBLIC walker
70 {
71 friend class structure_tree;
72
73 struct impl;
74 std::unique_ptr<impl> mp_impl;
75
76 walker(const structure_tree::impl* parent_impl);
77 public:
78 walker();
79 walker(const walker& other);
80 ~walker();
81
86 void root();
87
96 void descend(size_t child_pos);
97
101 void ascend();
102
108 size_t child_count() const;
109
114
123 std::vector<std::string> build_field_paths() const;
124
132 std::string build_row_group_path() const;
133 };
134
135 structure_tree(const structure_tree&) = delete;
136 structure_tree& operator= (const structure_tree&) = delete;
137
138 structure_tree();
139 ~structure_tree();
140
149
150 void parse(std::string_view stream);
151
157
158 void dump_compact(std::ostream& os) const;
159
160 walker get_walker() const;
161
162 void process_ranges(range_handler_type rh) const;
163};
164
165ORCUS_DLLPUBLIC std::ostream& operator<< (std::ostream& os, structure_tree::node_type nt);
166
167}}
168
169#endif
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition json_document_tree.hpp:387
Definition json_structure_tree.hpp:70
void descend(size_t child_pos)
std::vector< std::string > build_field_paths() const
std::string build_row_group_path() const
node_properties get_node() const
callback_type
Definition json_structure_tree.hpp:41
void set_callback(callback_type type, callback_handler_type callback)
std::function< void(std::any)> callback_handler_type
Definition json_structure_tree.hpp:59
Definition json_structure_tree.hpp:64
Definition json_structure_tree.hpp:23