Flow123d
last_with_con_2.0.0-4-g42e6930
|
Reader for (slightly) modified input files. More...
#include <reader_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_Format, const string) | |
TYPEDEF_ERR_INFO (EI_JSON_Type, const string) | |
TYPEDEF_ERR_INFO (EI_ErrorAddress, string) | |
TYPEDEF_ERR_INFO (EI_TransposeIndex, unsigned int) | |
TYPEDEF_ERR_INFO (EI_TransposeAddress, string) | |
DECLARE_INPUT_EXCEPTION (ExcInputError,<< "Error in input file: "<< EI_File::qval<< " at address: "<< EI_ErrorAddress::qval<< "\n"<< EI_Specification::val<< "\n"<< EI_Format::val<< " 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") | |
ReaderToStorage (const FilePath &in_file, const Type::TypeBase &root_type) | |
Read a storage from input stream. More... | |
ReaderToStorage (const string &default_str, const Type::TypeBase &root_type, FileFormat format) | |
Read a storage from string (e.g. complex default value). More... | |
template<class T > | |
T | get_root_interface () const |
Returns the root accessor. More... | |
Protected Member Functions | |
ReaderToStorage () | |
Default constructor. More... | |
void | read_stream (istream &in, const Type::TypeBase &root_type, FileFormat format) |
This method actually reads the given stream in . More... | |
StorageBase * | get_storage () |
Getter for root of the storage tree. More... | |
StorageBase * | make_storage (PathBase &p, const Type::TypeBase *type) |
Create storage of given type . More... | |
StorageBase * | make_storage (PathBase &p, const Type::Record *record) |
Create storage of Type::Record type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Abstract *abstr_rec) |
Create storage of Type::Abstract type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Array *array) |
Create storage of Type::Array type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Tuple *tuple) |
Create storage of Type::Tuple type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Selection *selection) |
Create storage of Type::Selection type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Bool *bool_type) |
Create storage of Type::Bool type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Integer *int_type) |
Create storage of Type::Integer type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::Double *double_type) |
Create storage of Type::Double type. More... | |
StorageBase * | make_storage (PathBase &p, const Type::String *string_type) |
Create storage of Type::String type. More... | |
StorageBase * | make_transposed_storage (PathBase &p, const Type::TypeBase *type) |
Apply transposition and create storage of Type::Array type. More... | |
StorageBase * | make_autoconversion_array_storage (PathBase &p, const Type::Array *array, StorageBase *item) |
Apply conversion to one element storage of Type::Array type. More... | |
StorageBase * | record_automatic_conversion (PathBase &p, const Type::Record *record) |
Apply automatic conversion of Type::Record type. More... | |
StorageBase * | abstract_automatic_conversion (PathBase &p, const Type::Abstract *abstr_rec) |
Apply automatic conversion of Type::Abstract type. More... | |
StorageBase * | make_storage_from_default (const string &dflt_str, std::shared_ptr< Type::TypeBase > type) |
Dispatch according to type and create corresponding storage from the given string. More... | |
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... | |
bool | try_transpose_read_ |
Flag signed that "expected" transposed part of input tree is processed. More... | |
unsigned int | transpose_index_ |
Index of processed item in transposed part of input tree. More... | |
vector< unsigned int > | transpose_array_sizes_ |
Helper vector what allows check sizes of all transposed Arrays. More... | |
Friends | |
class | Type::Default |
Reader for (slightly) modified input files.
This class implements a reader of modified input file format (JSON or YAML). 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 ReaderToStorage 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 ReaderToStorage::get_root_interface<T> method template.
Definition at line 77 of file reader_to_storage.hh.
Input::ReaderToStorage::ReaderToStorage | ( | const FilePath & | in_file, |
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 49 of file reader_to_storage.cc.
Input::ReaderToStorage::ReaderToStorage | ( | const string & | default_str, |
const Type::TypeBase & | root_type, | ||
FileFormat | format | ||
) |
Read a storage from string (e.g. complex default value).
Definition at line 74 of file reader_to_storage.cc.
|
protected |
Default constructor.
Provides common initialization for public constructors.
Definition at line 40 of file reader_to_storage.cc.
|
protected |
Apply automatic conversion of Type::Abstract type.
Definition at line 335 of file reader_to_storage.cc.
Input::ReaderToStorage::DECLARE_INPUT_EXCEPTION | ( | ExcInputError | , |
<< "Error in input file: "<< EI_File::qval<< " at address: "<< EI_ErrorAddress::qval<< "\n"<< EI_Specification::val<< "\n"<< EI_Format::val<< " type: "<< EI_JSON_Type::qval<< "\n"<< "Expected type:\n"<< EI_InputType::val | |||
) |
Input::ReaderToStorage::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::ReaderToStorage::DECLARE_INPUT_EXCEPTION | ( | ExcAutomaticConversionError | , |
<< "Error during automatic conversion of "<< EI_RecordName::val<< " record.\n "<< EI_InputErrorMessage::val<< "\n" | |||
) |
T Input::ReaderToStorage::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 708 of file reader_to_storage.cc.
|
inlineprotected |
Getter for root of the storage tree.
Definition at line 147 of file reader_to_storage.hh.
|
protected |
Apply conversion to one element storage of Type::Array type.
Definition at line 685 of file reader_to_storage.cc.
|
protected |
Create storage of given type
.
Check correctness of the input given by json_spirit or YAML-cpp node at head() of PathBase 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 129 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Record type.
Definition at line 187 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Abstract type.
Definition at line 302 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Array type.
Definition at line 348 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Tuple type.
Definition at line 450 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Selection type.
Definition at line 501 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Bool type.
Definition at line 528 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Integer type.
Definition at line 549 of file reader_to_storage.cc.
|
protected |
Create storage of Type::Double type.
Definition at line 580 of file reader_to_storage.cc.
|
protected |
Create storage of Type::String type.
Definition at line 611 of file reader_to_storage.cc.
|
protected |
Dispatch according to type
and create corresponding storage from the given string.
Definition at line 643 of file reader_to_storage.cc.
|
protected |
Apply transposition and create storage of Type::Array type.
Definition at line 664 of file reader_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 90 of file reader_to_storage.cc.
|
protected |
Apply automatic conversion of Type::Record type.
Definition at line 265 of file reader_to_storage.cc.
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_InputType | , |
string | |||
) |
General exception during conversion from JSON tree to storage.
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_File | , |
const string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_Specification | , |
const string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_Format | , |
const string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_JSON_Type | , |
const string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_ErrorAddress | , |
string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_TransposeIndex | , |
unsigned | int | ||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_TransposeAddress | , |
string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_JSONLine | , |
unsigned | int | ||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_JSONColumn | , |
unsigned | int | ||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_JSONReason | , |
string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_InputErrorMessage | , |
const string | |||
) |
Input::ReaderToStorage::TYPEDEF_ERR_INFO | ( | EI_RecordName | , |
const string | |||
) |
|
friend |
Definition at line 221 of file reader_to_storage.hh.
|
protected |
Root of the declaration tree of the data in the storage.
Definition at line 190 of file reader_to_storage.hh.
|
protected |
Storage of the read and checked input data.
Definition at line 187 of file reader_to_storage.hh.
|
protected |
Helper vector what allows check sizes of all transposed Arrays.
Definition at line 219 of file reader_to_storage.hh.
|
protected |
Index of processed item in transposed part of input tree.
Definition at line 216 of file reader_to_storage.hh.
|
protected |
Flag signed that "expected" transposed part of input tree is processed.
We set this flag if input tree contains another type at position where Array is expected. This type must correspond with type_of_value of Array.
Subsequently:
transpose_index_
to value '0' (transposition of first Array item).transpose_index_
.transpose_array_sizes_
.transpose_index_
). Definition at line 213 of file reader_to_storage.hh.