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
19namespace orcus { namespace json {
20
21struct ORCUS_DLLPUBLIC table_range_t
22{
23 std::vector<std::string> paths;
24 std::vector<std::string> row_groups;
25};
26
27class ORCUS_DLLPUBLIC structure_tree
28{
29 struct impl;
30 std::unique_ptr<impl> mp_impl;
31
32public:
33
34 enum class node_type : short { unknown = 0, array = 1, object = 2, object_key = 3, value = 4 };
35
37 {
38 node_type type;
39 bool repeat;
40 };
41
42 class ORCUS_DLLPUBLIC walker
43 {
44 friend class structure_tree;
45
46 struct impl;
47 std::unique_ptr<impl> mp_impl;
48
49 walker(const structure_tree::impl* parent_impl);
50 public:
51 walker();
52 walker(const walker& other);
53 ~walker();
54
59 void root();
60
69 void descend(size_t child_pos);
70
74 void ascend();
75
81 size_t child_count() const;
82
87
96 std::vector<std::string> build_field_paths() const;
97
105 std::string build_row_group_path() const;
106 };
107
108 structure_tree(const structure_tree&) = delete;
109 structure_tree& operator= (const structure_tree&) = delete;
110
113
114 void parse(std::string_view stream);
115
121
122 void dump_compact(std::ostream& os) const;
123
124 walker get_walker() const;
125
126 using range_handler_type = std::function<void(table_range_t&&)>;
127
128 void process_ranges(range_handler_type rh) const;
129};
130
131ORCUS_DLLPUBLIC std::ostream& operator<< (std::ostream& os, structure_tree::node_type nt);
132
133}}
134
135#endif
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition json_document_tree.hpp:353
Definition json_structure_tree.hpp:43
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
Definition json_structure_tree.hpp:28
Definition json_structure_tree.hpp:37
Definition json_structure_tree.hpp:22