Flow123d
jenkins-Flow123d-linux-release-multijob-198
|
Class used by JSONToStorage class to iterate over the JSON tree provided by json_spirit library. More...
#include <json_to_storage.hh>
Public Types | |
typedef json_spirit::mValue | Node |
Public Member Functions | |
TYPEDEF_ERR_INFO (EI_ErrorAddress, JSONPath) | |
TYPEDEF_ERR_INFO (EI_RefAddress, JSONPath) | |
TYPEDEF_ERR_INFO (EI_JsonFile, const string) | |
TYPEDEF_ERR_INFO (EI_RefStr, const string) | |
TYPEDEF_ERR_INFO (EI_Specification, const string) | |
DECLARE_INPUT_EXCEPTION (ExcRefOfWrongType,<< "Reference at address "<< EI_ErrorAddress::qval<< " has wrong type, should by string.") | |
DECLARE_INPUT_EXCEPTION (ExcReferenceNotFound,<< "Error in input file: "<< EI_JsonFile::qval<< "\nReference {REF=\""<< EI_RefStr::val<< "\"} at address "<< EI_RefAddress::qval<< " not found.\n"<< "failed to follow at address: "<< EI_ErrorAddress::qval<< " because "<< EI_Specification::val) | |
JSONPath (const Node &root_node) | |
const Node * | down (unsigned int index) |
const Node * | down (const string &key) |
void | up () |
void | go_to_root () |
const Node * | head () const |
int | level () const |
bool | get_ref_from_head (string &ref_address) |
JSONPath | find_ref_node (const string &ref_address) |
void | output (ostream &stream) const |
string | str () |
void | put_address () |
Private Attributes | |
vector< pair< int, string > > | path_ |
vector< const Node * > | nodes_ |
std::set< string > | previous_references_ |
Class used by JSONToStorage class to iterate over the JSON tree provided by json_spirit library.
This class keeps whole path from the root of the JSON tree to the current node. We store nodes along path in nodes_
and address of the node in path_
.
The class also contains methods for processing of special keys 'REF' and 'TYPE'. The reference is record with only one key 'REF' with a string value that contains address of the reference. The string with the address is extracted by JSONToStorage::get_ref_from_head
then the JSONPath corresponding to the address is provided by method JSONtoStorage::find_ref_node
.
Definition at line 50 of file json_to_storage.hh.
Definition at line 70 of file json_to_storage.hh.
Input::JSONPath::JSONPath | ( | const Node & | root_node | ) |
Definition at line 29 of file json_to_storage.cc.
Input::JSONPath::DECLARE_INPUT_EXCEPTION | ( | ExcRefOfWrongType | , |
<< "Reference at address "<< EI_ErrorAddress::qval<< " has wrong | type, | ||
should by string." | |||
) |
Input::JSONPath::DECLARE_INPUT_EXCEPTION | ( | ExcReferenceNotFound | , |
<< "Error in input file: "<< EI_JsonFile::qval<< "\nReference {REF=\""<< EI_RefStr::val<< "\"} at address "<< EI_RefAddress::qval<< " not found.\n"<< "failed to follow at address: "<< EI_ErrorAddress::qval<< " because "<< EI_Specification::val | |||
) |
const JSONPath::Node * Input::JSONPath::down | ( | unsigned int | index | ) |
Dive into json_spirit hierarchy. Store current path and returns pointer to new json_spirit node. If the json_spirit type do not match returns NULL.
Definition at line 35 of file json_to_storage.cc.
const JSONPath::Node * Input::JSONPath::down | ( | const string & | key | ) |
Definition at line 48 of file json_to_storage.cc.
JSONPath Input::JSONPath::find_ref_node | ( | const string & | ref_address | ) |
Creates a new JSONPath object given by address string possibly relative to the current path.
This returns path to reference given by address in ref_address.
Definition at line 100 of file json_to_storage.cc.
bool Input::JSONPath::get_ref_from_head | ( | string & | ref_address | ) |
Check if current head node is a JSON Object containing one key REF of type string. If yes, returns the string through reference ref_address
.
Definition at line 78 of file json_to_storage.cc.
void Input::JSONPath::go_to_root | ( | ) |
Move to root node.
Definition at line 72 of file json_to_storage.cc.
|
inline |
Pointer to JSON Value object at current path.
Definition at line 94 of file json_to_storage.hh.
|
inline |
Returns level of actual path. Root has level == 0.
Definition at line 100 of file json_to_storage.hh.
void Input::JSONPath::output | ( | ostream & | stream | ) | const |
Output to the given stream.
Definition at line 164 of file json_to_storage.cc.
void Input::JSONPath::put_address | ( | ) |
Put actual address to previous_references_ set
Definition at line 189 of file json_to_storage.cc.
string Input::JSONPath::str | ( | ) |
Returns string address of current position.
Definition at line 181 of file json_to_storage.cc.
Input::JSONPath::TYPEDEF_ERR_INFO | ( | EI_ErrorAddress | , |
JSONPath | |||
) |
Thrown if a reference in the input file
Input::JSONPath::TYPEDEF_ERR_INFO | ( | EI_RefAddress | , |
JSONPath | |||
) |
Input::JSONPath::TYPEDEF_ERR_INFO | ( | EI_JsonFile | , |
const string | |||
) |
Input::JSONPath::TYPEDEF_ERR_INFO | ( | EI_RefStr | , |
const string | |||
) |
Input::JSONPath::TYPEDEF_ERR_INFO | ( | EI_Specification | , |
const string | |||
) |
void Input::JSONPath::up | ( | ) |
Return one level up in the hierrarchy.
Definition at line 64 of file json_to_storage.cc.
Definition at line 137 of file json_to_storage.hh.
|
private |
One level of the path_
is either index (nonnegative int) in array or string key in a json object. For the first type we save index into first part of the pair and empty string to the second. For the later type of level, we save -1 for index and the key into the secodn part of the pair.
Definition at line 136 of file json_to_storage.hh.
|
private |
Definition at line 138 of file json_to_storage.hh.