Flow123d
jenkins-Flow123d-windows32-release-multijob-51
|
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") | |
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 Member Functions | |
JSONToStorage () | |
void | read_stream (istream &in, const Type::TypeBase &root_type) |
const StorageBase * | get_storage () |
StorageBase * | make_storage (JSONPath &p, const Type::TypeBase *type) |
StorageBase * | make_storage (JSONPath &p, const Type::Record *record) |
StorageBase * | make_storage (JSONPath &p, const Type::AbstractRecord *abstr_rec) |
StorageBase * | make_storage (JSONPath &p, const Type::Array *array) |
StorageBase * | make_selection_storage_without_catch (JSONPath &p, const Type::Selection *selection) |
StorageBase * | make_storage (JSONPath &p, const Type::Selection *selection) |
StorageBase * | make_storage (JSONPath &p, const Type::Bool *bool_type) |
StorageBase * | make_storage (JSONPath &p, const Type::Integer *int_type) |
StorageBase * | make_storage (JSONPath &p, const Type::Double *double_type) |
StorageBase * | make_storage (JSONPath &p, const Type::String *string_type) |
StorageBase * | make_storage_from_default (const string &dflt_str, const Type::TypeBase *type) |
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 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.
|
protected |
Default constructor. Provides common initialization for public constructors.
Definition at line 203 of file json_to_storage.cc.
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" | |||
) |
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.
|
inlineprotected |
Getter for root of the storage tree.
Definition at line 229 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 282 of file json_to_storage.cc.
|
protected |
Definition at line 333 of file json_to_storage.cc.
|
protected |
Definition at line 416 of file json_to_storage.cc.
|
protected |
Definition at line 455 of file json_to_storage.cc.
|
protected |
Definition at line 495 of file json_to_storage.cc.
|
protected |
Definition at line 517 of file json_to_storage.cc.
|
protected |
Definition at line 530 of file json_to_storage.cc.
|
protected |
Definition at line 551 of file json_to_storage.cc.
|
protected |
Definition at line 575 of file json_to_storage.cc.
|
protected |
Dispatch according to type
and create corresponding storage from the given string.
Definition at line 594 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 242 of file json_to_storage.cc.
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 | |||
) |
|
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.
|
protected |
Root of the declaration tree of the data in the storage.
Definition at line 261 of file json_to_storage.hh.
|
protected |
Storage of the read and checked input data.
Definition at line 258 of file json_to_storage.hh.