Flow123d
jenkins-Flow123d-linux-release-multijob-198
|
Reader for (slightly) modified JSON files. More...
#include <json_to_storage.hh>
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 > | |
T | get_root_interface () const |
Protected Attributes | |
StorageBase * | storage_ |
Storage of the read and checked input data. More... | |
const Type::TypeBase * | root_type_ |
Root of the declaration tree of the data in the storage. More... | |
vector< string > | json_type_names |
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:
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.
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.
|
protected |
Default constructor. Provides common initialization for public constructors.
Definition at line 205 of file json_to_storage.cc.
|
protected |
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" | |||
) |
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.
|
inlineprotected |
Getter for root of the storage tree.
Definition at line 234 of file json_to_storage.hh.
|
protected |
|
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.
|
protected |
Definition at line 335 of file json_to_storage.cc.
|
protected |
Definition at line 443 of file json_to_storage.cc.
|
protected |
Definition at line 493 of file json_to_storage.cc.
|
protected |
Definition at line 533 of file json_to_storage.cc.
|
protected |
Definition at line 555 of file json_to_storage.cc.
|
protected |
Definition at line 568 of file json_to_storage.cc.
|
protected |
Definition at line 592 of file json_to_storage.cc.
|
protected |
Definition at line 616 of file json_to_storage.cc.
|
protected |
Dispatch according to type
and create corresponding storage from the given string.
Definition at line 635 of file json_to_storage.cc.
|
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.
|
protected |
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 | |||
) |
|
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.
|
protected |
Root of the declaration tree of the data in the storage.
Definition at line 269 of file json_to_storage.hh.
|
protected |
Storage of the read and checked input data.
Definition at line 266 of file json_to_storage.hh.