Flow123d  JS_before_hm-1804-gf2ad740aa
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Input::PathJSON Class Reference

Class used by ReaderToStorage class to iterate over the JSON tree provided by json_spirit library. More...

#include <path_json.hh>

Inheritance diagram for Input::PathJSON:
Inheritance graph
[legend]
Collaboration diagram for Input::PathJSON:
Collaboration graph
[legend]

Public Member Functions

 PathJSON (std::istream &in)
 Constructor. More...
 
 ~PathJSON () override
 Destructor. More...
 
bool down (unsigned int index) override
 Dive into json_spirit hierarchy. More...
 
bool down (const std::string &key, int index=-1) override
 Dive into json_spirit hierarchy. More...
 
void up () override
 Return one level up in the hierarchy. More...
 
int level () const
 Implements PathBase::level. More...
 
bool is_null_type () const override
 Implements PathBase::is_null_type. More...
 
bool get_bool_value () const override
 Implements PathBase::get_bool_value. More...
 
std::int64_t get_int_value () const override
 Implements PathBase::get_int_value. More...
 
double get_double_value () const override
 Implements PathBase::get_double_value. More...
 
std::string get_string_value () const override
 Implements PathBase::get_string_value. More...
 
unsigned int get_node_type_index () const override
 Implements PathBase::get_node_type_index. More...
 
bool get_record_key_set (std::set< std::string > &) const override
 Implements PathBase::get_record_key_set. More...
 
bool is_effectively_null () const override
 Implements PathBase::is_effectively_null. More...
 
int get_array_size () const override
 Implements PathBase::get_array_size. More...
 
bool is_record_type () const override
 Implements PathBase::is_record_type. More...
 
bool is_array_type () const override
 Implements PathBase::is_array_type. More...
 
PathJSONclone () const override
 Implements PathBase::clone. More...
 
std::string get_record_tag () const override
 Implements PathBase::get_record_tag. More...
 
PathBasefind_ref_node () override
 Implements reading of reference keys, and check of cyclic references. More...
 
void remember_reference ()
 Put address of actual reference to previous_references_ set. More...
 
- Public Member Functions inherited from Input::PathBase
 TYPEDEF_ERR_INFO (EI_ErrorAddress, std::string)
 
 TYPEDEF_ERR_INFO (EI_RefAddress, std::string)
 
 TYPEDEF_ERR_INFO (EI_JsonFile, std::string)
 
 TYPEDEF_ERR_INFO (EI_RefStr, std::string)
 
 TYPEDEF_ERR_INFO (EI_Specification, std::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)
 
virtual ~PathBase ()
 Must have virtual destructor to call the right one form child. More...
 
void output (std::ostream &stream) const
 Output to the given stream. More...
 
std::string get_node_type (unsigned int type_idx) const
 Get short string description of node type, method is used for printout of messages. More...
 
void go_to_root ()
 Move to root node. More...
 
std::string as_string () const
 Returns string address of current position. More...
 

Protected Types

typedef json_spirit::mValue Node
 Definition of JSON Spirit node. More...
 

Protected Member Functions

 PathJSON ()
 Default constructor. More...
 
const Nodehead () const
 Pointer to JSON Value object at current path. More...
 
- Protected Member Functions inherited from Input::PathBase
 PathBase ()
 Forbid default constructor. More...
 

Protected Attributes

std::set< std::string > previous_references_
 Remember used references in order to avoid detect cyclic references. More...
 
std::shared_ptr< Noderoot_node_
 
std::vector< const Node * > nodes_
 
- Protected Attributes inherited from Input::PathBase
std::vector< std::pair< int, std::string > > path_
 One level of the path_ is either index (nonnegative int) in array or string key in a json object. More...
 
std::vector< std::string > json_type_names
 Names of all possible node types in parsed input tree. More...
 

Detailed Description

Class used by ReaderToStorage 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 and provided by method JSONtoStorage::find_ref_node.

Definition at line 46 of file path_json.hh.

Member Typedef Documentation

◆ Node

Definition of JSON Spirit node.

Definition at line 121 of file path_json.hh.

Constructor & Destructor Documentation

◆ PathJSON() [1/2]

Input::PathJSON::PathJSON ( std::istream &  in)

Constructor.

Call JSON parser for given stream and create PathJSON for the root of parsed data tree.

◆ ~PathJSON()

Input::PathJSON::~PathJSON ( )
override

Destructor.

Have to cleanup nodes_.

Definition at line 74 of file path_json.cc.

◆ PathJSON() [2/2]

Input::PathJSON::PathJSON ( )
protected

Default constructor.

Provides common initialization for public constructors.

Definition at line 56 of file path_json.cc.

Here is the caller graph for this function:

Member Function Documentation

◆ clone()

PathJSON * Input::PathJSON::clone ( ) const
overridevirtual

Implements PathBase::clone.

Implements Input::PathBase.

Definition at line 294 of file path_json.cc.

Here is the caller graph for this function:

◆ down() [1/2]

bool Input::PathJSON::down ( const std::string &  key,
int  index = -1 
)
overridevirtual

Dive into json_spirit hierarchy.

Implements PathBase::down(const std::string&)

Implements Input::PathBase.

◆ down() [2/2]

bool Input::PathJSON::down ( unsigned int  index)
overridevirtual

Dive into json_spirit hierarchy.

Implements PathBase::down(unsigned int)

Implements Input::PathBase.

Definition at line 79 of file path_json.cc.

Here is the caller graph for this function:

◆ find_ref_node()

PathBase * Input::PathJSON::find_ref_node ( )
overridevirtual

Implements reading of reference keys, and check of cyclic references.

This returns path to reference given by address in ref_address.

Implements Input::PathBase.

Definition at line 120 of file path_json.cc.

Here is the caller graph for this function:

◆ get_array_size()

int Input::PathJSON::get_array_size ( ) const
overridevirtual

Implements PathBase::get_array_size.

Implements Input::PathBase.

Definition at line 271 of file path_json.cc.

◆ get_bool_value()

bool Input::PathJSON::get_bool_value ( ) const
overridevirtual

Implements PathBase::get_bool_value.

Implements Input::PathBase.

Definition at line 201 of file path_json.cc.

◆ get_double_value()

double Input::PathJSON::get_double_value ( ) const
overridevirtual

Implements PathBase::get_double_value.

Implements Input::PathBase.

Definition at line 223 of file path_json.cc.

◆ get_int_value()

std::int64_t Input::PathJSON::get_int_value ( ) const
overridevirtual

Implements PathBase::get_int_value.

Implements Input::PathBase.

Definition at line 212 of file path_json.cc.

◆ get_node_type_index()

unsigned int Input::PathJSON::get_node_type_index ( ) const
overridevirtual

Implements PathBase::get_node_type_index.

Implements Input::PathBase.

Definition at line 247 of file path_json.cc.

◆ get_record_key_set()

bool Input::PathJSON::get_record_key_set ( std::set< std::string > &  keys_list) const
overridevirtual

Implements PathBase::get_record_key_set.

Implements Input::PathBase.

Definition at line 253 of file path_json.cc.

◆ get_record_tag()

std::string Input::PathJSON::get_record_tag ( ) const
overridevirtual

Implements PathBase::get_record_tag.

Implements Input::PathBase.

Definition at line 300 of file path_json.cc.

◆ get_string_value()

std::string Input::PathJSON::get_string_value ( ) const
overridevirtual

Implements PathBase::get_string_value.

Implements Input::PathBase.

Definition at line 236 of file path_json.cc.

Here is the caller graph for this function:

◆ head()

const Node* Input::PathJSON::head ( ) const
inlineprotected

Pointer to JSON Value object at current path.

Definition at line 124 of file path_json.hh.

Here is the caller graph for this function:

◆ is_array_type()

bool Input::PathJSON::is_array_type ( ) const
overridevirtual

Implements PathBase::is_array_type.

Implements Input::PathBase.

Definition at line 288 of file path_json.cc.

Here is the caller graph for this function:

◆ is_effectively_null()

bool Input::PathJSON::is_effectively_null ( ) const
overridevirtual

Implements PathBase::is_effectively_null.

Implements Input::PathBase.

Definition at line 329 of file path_json.cc.

◆ is_null_type()

bool Input::PathJSON::is_null_type ( ) const
overridevirtual

Implements PathBase::is_null_type.

Implements Input::PathBase.

Definition at line 196 of file path_json.cc.

◆ is_record_type()

bool Input::PathJSON::is_record_type ( ) const
overridevirtual

Implements PathBase::is_record_type.

Implements Input::PathBase.

Definition at line 282 of file path_json.cc.

Here is the caller graph for this function:

◆ level()

int Input::PathJSON::level ( ) const
inlinevirtual

Implements PathBase::level.

Implements Input::PathBase.

Definition at line 83 of file path_json.hh.

Here is the caller graph for this function:

◆ remember_reference()

void Input::PathJSON::remember_reference ( )

Put address of actual reference to previous_references_ set.

Definition at line 323 of file path_json.cc.

◆ up()

void Input::PathJSON::up ( )
overridevirtual

Return one level up in the hierarchy.

Implements Input::PathBase.

Definition at line 107 of file path_json.cc.

Here is the caller graph for this function:

Member Data Documentation

◆ nodes_

std::vector<const Node *> Input::PathJSON::nodes_
protected

Definition at line 138 of file path_json.hh.

◆ previous_references_

std::set<std::string> Input::PathJSON::previous_references_
protected

Remember used references in order to avoid detect cyclic references.

In JSON we allow usage of references using special key 'REF'.

Definition at line 132 of file path_json.hh.

◆ root_node_

std::shared_ptr<Node> Input::PathJSON::root_node_
protected

Definition at line 135 of file path_json.hh.


The documentation for this class was generated from the following files: