Flow123d  jenkins-Flow123d-windows-release-multijob-285
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")
 
 TYPEDEF_ERR_INFO (EI_InputErrorMessage, const string)
 
 TYPEDEF_ERR_INFO (EI_RecordName, const string)
 
 DECLARE_INPUT_EXCEPTION (ExcAutomaticConversionError,<< "Error during automatic conversion of "<< EI_RecordName::val<< " record.\n "<< EI_InputErrorMessage::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)
 
StorageBaserecord_automatic_conversion (JSONPath &p, const Type::Record *record)
 
StorageBaseabstract_rec_automatic_conversion (JSONPath &p, const Type::AbstractRecord *abstr_rec)
 
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 223 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 231 of file json_to_storage.cc.

Input::JSONToStorage::JSONToStorage ( )
protected

Default constructor. Provides common initialization for public constructors.

Definition at line 205 of file json_to_storage.cc.

Member Function Documentation

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

Definition at line 479 of file json_to_storage.cc.

Here is the caller graph for this function:

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"   
)
Input::JSONToStorage::DECLARE_INPUT_EXCEPTION ( ExcAutomaticConversionError  ,
<< "Error during automatic conversion of "<< EI_RecordName::val<< " record.\n "<< EI_InputErrorMessage::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 291 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 234 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 284 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 335 of file json_to_storage.cc.

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

Definition at line 443 of file json_to_storage.cc.

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

Definition at line 493 of file json_to_storage.cc.

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

Definition at line 533 of file json_to_storage.cc.

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

Definition at line 555 of file json_to_storage.cc.

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

Definition at line 568 of file json_to_storage.cc.

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

Definition at line 592 of file json_to_storage.cc.

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

Definition at line 616 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 635 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 244 of file json_to_storage.cc.

Here is the caller graph for this function:

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

Definition at line 406 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   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_InputErrorMessage  ,
const string   
)
Input::JSONToStorage::TYPEDEF_ERR_INFO ( EI_RecordName  ,
const 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 276 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 269 of file json_to_storage.hh.

StorageBase* Input::JSONToStorage::storage_
protected

Storage of the read and checked input data.

Definition at line 266 of file json_to_storage.hh.


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