Flow123d
release_1.8.2-1603-g0109a2b
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
input
path_json.hh
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4
*
5
* This program is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License version 3 as published by the
7
* Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
*
13
*
14
* @file path_json.hh
15
* @brief
16
*/
17
18
#ifndef PATH_JSON_HH_
19
#define PATH_JSON_HH_
20
21
#include <memory>
22
#include "
input/path_base.hh
"
23
#include "
json_spirit/json_spirit.h
"
24
25
26
namespace
Input
{
27
28
29
30
/**
31
* @brief Class used by ReaderToStorage class to iterate over the JSON tree provided by json_spirit library.
32
*
33
* This class keeps whole path from the root of the JSON tree to the current node. We store nodes along path in \p nodes_
34
* and address of the node in \p path_.
35
*
36
* The class also contains methods for processing of special keys 'REF' and 'TYPE'. The reference is record with only one key
37
* 'REF' with a string value that contains address of the reference. The string with the address is extracted and provided by
38
* method \p JSONtoStorage::find_ref_node.
39
*/
40
class
PathJSON
:
public
PathBase
{
41
public
:
42
43
44
/**
45
* @brief Constructor.
46
*
47
* Call JSON parser for given stream and create PathJSON for the root
48
* of parsed data tree.
49
*/
50
PathJSON
(std::istream &in);
51
52
/**
53
* @brief Destructor.
54
*
55
* Have to cleanup nodes_.
56
*/
57
~PathJSON
()
override
;
58
59
/**
60
* @brief Dive into json_spirit hierarchy.
61
*
62
* Implements @p PathBase::down(unsigned int)
63
*/
64
bool
down
(
unsigned
int
index)
override
;
65
66
/**
67
* @brief Dive into json_spirit hierarchy.
68
*
69
* Implements @p PathBase::down(const std::string&)
70
*/
71
bool
down
(
const
std::string& key)
override
;
72
73
/// Return one level up in the hierarchy.
74
void
up
()
override
;
75
76
/// Implements @p PathBase::level
77
inline
int
level
()
const
78
{
return
nodes_
.size() - 1; }
79
80
// These methods are derived from PathBase
81
bool
is_null_type
()
const override
;
///< Implements @p PathBase::is_null_type
82
bool
get_bool_value
()
const override
;
///< Implements @p PathBase::get_bool_value
83
std::int64_t
get_int_value
()
const override
;
///< Implements @p PathBase::get_int_value
84
double
get_double_value
()
const override
;
///< Implements @p PathBase::get_double_value
85
std::string
get_string_value
()
const override
;
///< Implements @p PathBase::get_string_value
86
unsigned
int
get_node_type_index
()
const override
;
///< Implements @p PathBase::get_node_type_index
87
bool
get_record_key_set
(std::set<std::string> &)
const override
;
///< Implements @p PathBase::get_record_key_set
88
int
get_array_size
()
const override
;
///< Implements @p PathBase::get_array_size
89
bool
is_record_type
()
const override
;
///< Implements @p PathBase::is_record_type
90
bool
is_array_type
()
const override
;
///< Implements @p PathBase::is_array_type
91
PathJSON
*
clone
()
const override
;
///< Implements @p PathBase::clone
92
std::string
get_descendant_name
()
const override
;
///< Implements @p PathBase::get_descendant_name
93
94
/// Implements reading of reference keys, and check of cyclic references.
95
PathBase
*
find_ref_node
()
override
;
96
97
/// Put address of actual reference to previous_references_ set
98
void
remember_reference
();
99
100
101
102
protected
:
103
104
/**
105
* @brief Default constructor.
106
*
107
* Provides common initialization for public constructors.
108
*/
109
PathJSON
();
110
111
/// Definition of JSON Spirit node.
112
typedef
json_spirit::mValue
Node
;
113
114
/// Pointer to JSON Value object at current path.
115
inline
const
Node *
head
()
const
116
{
return
nodes_
.back(); }
117
118
/**
119
* @brief Remember used references in order to avoid detect cyclic references.
120
*
121
* In JSON we allow usage of references using special key 'REF'.
122
*/
123
std::set<std::string>
previous_references_
;
124
125
// Root node has to be automatically deleted.
126
std::shared_ptr<Node>
root_node_
;
127
128
// Pointers to all nodes from the root up to the current path.
129
std::vector<const Node *>
nodes_
;
130
131
};
132
133
/**
134
* @brief Output operator for PathJSON.
135
*
136
* Mainly for debugging purposes and error messages.
137
*/
138
std::ostream&
operator<<
(std::ostream& stream,
const
PathJSON
& path);
139
140
141
142
}
// namespace Input
143
144
145
146
#endif
/* PATH_JSON_HH_ */
Input::PathJSON::Node
json_spirit::mValue Node
Definition of JSON Spirit node.
Definition:
path_json.hh:112
Input::PathJSON::is_array_type
bool is_array_type() const override
Implements PathBase::is_array_type.
Definition:
path_json.cc:286
Input::PathJSON
Class used by ReaderToStorage class to iterate over the JSON tree provided by json_spirit library...
Definition:
path_json.hh:40
Input::operator<<
std::ostream & operator<<(std::ostream &stream, const Address &address)
Definition:
accessors.hh:238
Input::PathBase
Base abstract class used by ReaderToStorage class to iterate over the input tree. ...
Definition:
path_base.hh:39
Input
Definition:
equation.hh:37
Input::PathJSON::find_ref_node
PathBase * find_ref_node() override
Implements reading of reference keys, and check of cyclic references.
Definition:
path_json.cc:118
Input::PathJSON::head
const Node * head() const
Pointer to JSON Value object at current path.
Definition:
path_json.hh:115
Input::PathJSON::clone
PathJSON * clone() const override
Implements PathBase::clone.
Definition:
path_json.cc:292
Input::PathJSON::nodes_
std::vector< const Node * > nodes_
Definition:
path_json.hh:129
Input::PathJSON::down
bool down(unsigned int index) override
Dive into json_spirit hierarchy.
Definition:
path_json.cc:77
std::vector
Definition:
doxy_dummy_defs.hh:7
json_spirit::Value_impl
Definition:
json_spirit_value.h:38
Input::PathJSON::up
void up() override
Return one level up in the hierarchy.
Definition:
path_json.cc:105
Input::PathJSON::remember_reference
void remember_reference()
Put address of actual reference to previous_references_ set.
Definition:
path_json.cc:317
Input::PathJSON::get_descendant_name
std::string get_descendant_name() const override
Implements PathBase::get_descendant_name.
Definition:
path_json.cc:298
Input::PathJSON::~PathJSON
~PathJSON() override
Destructor.
Definition:
path_json.cc:72
Input::PathJSON::get_double_value
double get_double_value() const override
Implements PathBase::get_double_value.
Definition:
path_json.cc:221
Input::PathJSON::level
int level() const
Implements PathBase::level.
Definition:
path_json.hh:77
Input::PathJSON::is_null_type
bool is_null_type() const override
Implements PathBase::is_null_type.
Definition:
path_json.cc:194
Input::PathJSON::is_record_type
bool is_record_type() const override
Implements PathBase::is_record_type.
Definition:
path_json.cc:280
json_spirit.h
path_base.hh
Input::PathJSON::get_int_value
std::int64_t get_int_value() const override
Implements PathBase::get_int_value.
Definition:
path_json.cc:210
Input::PathJSON::get_array_size
int get_array_size() const override
Implements PathBase::get_array_size.
Definition:
path_json.cc:269
Input::PathJSON::root_node_
std::shared_ptr< Node > root_node_
Definition:
path_json.hh:126
Input::PathJSON::get_record_key_set
bool get_record_key_set(std::set< std::string > &) const override
Implements PathBase::get_record_key_set.
Definition:
path_json.cc:251
Input::PathJSON::PathJSON
PathJSON()
Default constructor.
Definition:
path_json.cc:54
Input::PathJSON::get_string_value
std::string get_string_value() const override
Implements PathBase::get_string_value.
Definition:
path_json.cc:234
Input::PathJSON::previous_references_
std::set< std::string > previous_references_
Remember used references in order to avoid detect cyclic references.
Definition:
path_json.hh:123
Input::PathJSON::get_bool_value
bool get_bool_value() const override
Implements PathBase::get_bool_value.
Definition:
path_json.cc:199
Input::PathJSON::get_node_type_index
unsigned int get_node_type_index() const override
Implements PathBase::get_node_type_index.
Definition:
path_json.cc:245
Generated by
1.8.11