Flow123d  jenkins-Flow123d-windows32-release-multijob-51
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Input::JSONToStorage Class Reference

Reader for (slightly) modified JSON files. More...

#include <json_to_storage.hh>

Collaboration diagram for Input::JSONToStorage:
Collaboration graph
[legend]

Public Member Functions

 TYPEDEF_ERR_INFO (EI_InputType, string)
 General exception during conversion from JSON tree to storage. More...
 
 TYPEDEF_ERR_INFO (EI_File, const string)
 
 TYPEDEF_ERR_INFO (EI_Specification, const string)
 
 TYPEDEF_ERR_INFO (EI_JSON_Type, const string)
 
 TYPEDEF_ERR_INFO (EI_ErrorAddress, JSONPath)
 
 DECLARE_INPUT_EXCEPTION (ExcInputError,<< "Error in input file: "<< EI_File::qval<< " at address: "<< EI_ErrorAddress::qval<<"\n"<< EI_Specification::val<< "\n"<< "JSON type: "<< EI_JSON_Type::qval<< "\n"<< "Expected type:\n"<< EI_InputType::val)
 
 TYPEDEF_ERR_INFO (EI_JSONLine, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_JSONColumn, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_JSONReason, string)
 
 DECLARE_INPUT_EXCEPTION (ExcNotJSONFormat,<< "Not valid JSON file "<< EI_File::qval<< ". Error at line "<< EI_JSONLine::val<< " : col "<< EI_JSONColumn::val<< " ; reason: "<< EI_JSONReason::val<< "\n")
 
 JSONToStorage (istream &in, const Type::TypeBase &root_type)
 
 JSONToStorage (const string &default_str, const Type::TypeBase &root_type)
 
template<class T >
get_root_interface () const
 

Protected Member Functions

 JSONToStorage ()
 
void read_stream (istream &in, const Type::TypeBase &root_type)
 
const StorageBaseget_storage ()
 
StorageBasemake_storage (JSONPath &p, const Type::TypeBase *type)
 
StorageBasemake_storage (JSONPath &p, const Type::Record *record)
 
StorageBasemake_storage (JSONPath &p, const Type::AbstractRecord *abstr_rec)
 
StorageBasemake_storage (JSONPath &p, const Type::Array *array)
 
StorageBasemake_selection_storage_without_catch (JSONPath &p, const Type::Selection *selection)
 
StorageBasemake_storage (JSONPath &p, const Type::Selection *selection)
 
StorageBasemake_storage (JSONPath &p, const Type::Bool *bool_type)
 
StorageBasemake_storage (JSONPath &p, const Type::Integer *int_type)
 
StorageBasemake_storage (JSONPath &p, const Type::Double *double_type)
 
StorageBasemake_storage (JSONPath &p, const Type::String *string_type)
 
StorageBasemake_storage_from_default (const string &dflt_str, const Type::TypeBase *type)
 

Protected Attributes

StorageBasestorage_
 Storage of the read and checked input data. More...
 
const Type::TypeBaseroot_type_
 Root of the declaration tree of the data in the storage. More...
 
vector< string > json_type_names
 

Detailed Description

Reader for (slightly) modified JSON files.

This class implements a reader of modified JSON file format. The modifications include shell-like comments (using hash '#' character), this is implemented in comment_filter.hh, optional quoting of keys in JSON objects that do not contain spaces, and possibility to use '=' instead of ':'. So you can write:

{ key1="text", key2=2, "key 3"=4 }

Note, however, that our input interface allows only C identifiers for keys. The reader use json_spirit library (based on Spirit parser from Boost) with slightly modified grammar.

The input file is at first read and parsed by json_spirit. Then JSONToStorage pass through tree with parsed data along with passing through declaration tree. The input data are check against declaration and stored in the Storage tree.

Accessor to the root record is provided by JSONToStorage::get_root_interface<T> method template.

Definition at line 168 of file json_to_storage.hh.

Constructor & Destructor Documentation

Input::JSONToStorage::JSONToStorage ( istream &  in,
const Type::TypeBase root_type 
)

Read a storage from input stream. Parameter root_type provides input type tree declaration. See read_from_stream for details.

Definition at line 221 of file json_to_storage.cc.

Input::JSONToStorage::JSONToStorage ( const string &  default_str,
const Type::TypeBase root_type 
)

Read a storage from string (e.g. complex default value).

Definition at line 229 of file json_to_storage.cc.

Input::JSONToStorage::JSONToStorage ( )
protected

Default constructor. Provides common initialization for public constructors.

Definition at line 203 of file json_to_storage.cc.

Member Function Documentation

Input::JSONToStorage::DECLARE_INPUT_EXCEPTION ( ExcInputError  ,
<< "Error in input file: "<< EI_File::qval<< " at address: "<< EI_ErrorAddress::qval<<"\n"<< EI_Specification::val<< "\n"<< "JSON type: "<< EI_JSON_Type::qval<< "\n"<< "Expected type:\n"<< EI_InputType::val   
)
Input::JSONToStorage::DECLARE_INPUT_EXCEPTION ( ExcNotJSONFormat  ,
<< "Not valid JSON file "<< EI_File::qval<< ". Error at line "<< EI_JSONLine::val<< " : col "<< EI_JSONColumn::val<< " ; reason: "<< EI_JSONReason::val<< "\n"   
)
template<class T >
T Input::JSONToStorage::get_root_interface ( ) const

Returns the root accessor. The template type T should correspond to the kind of the input type at root of the declaration tree.

Definition at line 283 of file json_to_storage.hh.

Here is the caller graph for this function:

const StorageBase* Input::JSONToStorage::get_storage ( )
inlineprotected

Getter for root of the storage tree.

Definition at line 229 of file json_to_storage.hh.

StorageBase* Input::JSONToStorage::make_selection_storage_without_catch ( JSONPath p,
const Type::Selection selection 
)
protected
StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::TypeBase type 
)
protected

Check correctness of the input given by json_spirit node at head() of JSONPath p against type specification type. Die on input error (and return NULL). For correct input, creates the storage tree and returns pointer to its root node.

Definition at line 282 of file json_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Record record 
)
protected

Definition at line 333 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::AbstractRecord abstr_rec 
)
protected

Definition at line 416 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Array array 
)
protected

Definition at line 455 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Selection selection 
)
protected

Definition at line 495 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Bool bool_type 
)
protected

Definition at line 517 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Integer int_type 
)
protected

Definition at line 530 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::Double double_type 
)
protected

Definition at line 551 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage ( JSONPath p,
const Type::String string_type 
)
protected

Definition at line 575 of file json_to_storage.cc.

StorageBase * Input::JSONToStorage::make_storage_from_default ( const string &  dflt_str,
const Type::TypeBase type 
)
protected

Dispatch according to type and create corresponding storage from the given string.

Definition at line 594 of file json_to_storage.cc.

Here is the caller graph for this function:

void Input::JSONToStorage::read_stream ( istream &  in,
const Type::TypeBase root_type 
)
protected

This method actually reads the given stream in, checks the data just read against the declaration tree given by root_type, and store the data into private storage tree using StorageBase classes.

Definition at line 242 of file json_to_storage.cc.

Here is the caller graph for this function:

Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_InputType  ,
string   
)

General exception during conversion from JSON tree to storage.

Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_File  ,
const string   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_Specification  ,
const string   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_JSON_Type  ,
const string   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_ErrorAddress  ,
JSONPath   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_JSONLine  ,
unsigned  int 
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_JSONColumn  ,
unsigned  int 
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_JSONReason  ,
string   
)

Member Data Documentation

vector<string> Input::JSONToStorage::json_type_names
protected

Names of all possible node types in parsed JSON tree provided by JSON Spirit library. Initialized in constructor.

Definition at line 268 of file json_to_storage.hh.

const Type::TypeBase* Input::JSONToStorage::root_type_
protected

Root of the declaration tree of the data in the storage.

Definition at line 261 of file json_to_storage.hh.

StorageBase* Input::JSONToStorage::storage_
protected

Storage of the read and checked input data.

Definition at line 258 of file json_to_storage.hh.


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