Flow123d  release_2.1.0-84-g6a13a75
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Input::ReaderToStorage Class Reference

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

#include <reader_to_storage.hh>

Collaboration diagram for Input::ReaderToStorage:
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_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, Type::TypeBase &root_type)
 Read a storage from input stream. More...
 
 ReaderToStorage (const string &default_str, Type::TypeBase &root_type, FileFormat format)
 Read a storage from string (e.g. complex default value). More...
 
template<class T >
get_root_interface () const
 Returns the root accessor. More...
 
 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...
 

Protected Member Functions

StorageBaseget_storage ()
 Getter for root of the storage tree. More...
 
StorageBasemake_storage (PathBase &p, const Type::TypeBase *type)
 Create storage of given type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Record *record)
 Create storage of Type::Record type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Abstract *abstr_rec)
 Create storage of Type::Abstract type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Array *array)
 Create storage of Type::Array type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Tuple *tuple)
 Create storage of Type::Tuple type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Selection *selection)
 Create storage of Type::Selection type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Bool *bool_type)
 Create storage of Type::Bool type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Integer *int_type)
 Create storage of Type::Integer type. More...
 
StorageBasemake_storage (PathBase &p, const Type::Double *double_type)
 Create storage of Type::Double type. More...
 
StorageBasemake_storage (PathBase &p, const Type::String *string_type)
 Create storage of Type::String type. More...
 
StorageBasemake_transposed_storage (PathBase &p, const Type::TypeBase *type)
 Apply transposition and create storage of Type::Array type. More...
 
StorageBasemake_autoconversion_array_storage (PathBase &p, const Type::Array *array, StorageBase *item)
 Apply conversion to one element storage of Type::Array type. More...
 
StorageBaserecord_automatic_conversion (PathBase &p, const Type::Record *record)
 Apply automatic conversion of Type::Record type. More...
 
StorageBaseabstract_automatic_conversion (PathBase &p, const Type::Abstract *abstr_rec)
 Apply automatic conversion of Type::Abstract type. More...
 
StorageBasemake_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

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...
 
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
 

Detailed Description

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:

{ 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 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.

Constructor & Destructor Documentation

Input::ReaderToStorage::ReaderToStorage ( const FilePath in_file,
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,
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.

Input::ReaderToStorage::ReaderToStorage ( )

Default constructor.

Provides common initialization for public constructors.

Definition at line 40 of file reader_to_storage.cc.

Member Function Documentation

StorageBase * Input::ReaderToStorage::abstract_automatic_conversion ( PathBase p,
const Type::Abstract abstr_rec 
)
protected

Apply automatic conversion of Type::Abstract type.

Definition at line 338 of file reader_to_storage.cc.

Here is the caller graph for this function:

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"   
)
template<class T >
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 711 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::get_storage ( )
protected

Getter for root of the storage tree.

Definition at line 90 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::make_autoconversion_array_storage ( PathBase p,
const Type::Array array,
StorageBase item 
)
protected

Apply conversion to one element storage of Type::Array type.

Definition at line 688 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::TypeBase type 
)
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 136 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Record record 
)
protected

Create storage of Type::Record type.

Definition at line 194 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Abstract abstr_rec 
)
protected

Create storage of Type::Abstract type.

Definition at line 314 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Array array 
)
protected

Create storage of Type::Array type.

Definition at line 351 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Tuple tuple 
)
protected

Create storage of Type::Tuple type.

Definition at line 453 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Selection selection 
)
protected

Create storage of Type::Selection type.

Definition at line 504 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Bool bool_type 
)
protected

Create storage of Type::Bool type.

Definition at line 531 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Integer int_type 
)
protected

Create storage of Type::Integer type.

Definition at line 552 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::Double double_type 
)
protected

Create storage of Type::Double type.

Definition at line 583 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage ( PathBase p,
const Type::String string_type 
)
protected

Create storage of Type::String type.

Definition at line 614 of file reader_to_storage.cc.

StorageBase * Input::ReaderToStorage::make_storage_from_default ( const string &  dflt_str,
std::shared_ptr< Type::TypeBase type 
)
protected

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

Definition at line 646 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::make_transposed_storage ( PathBase p,
const Type::TypeBase type 
)
protected

Apply transposition and create storage of Type::Array type.

Definition at line 667 of file reader_to_storage.cc.

Here is the caller graph for this function:

void Input::ReaderToStorage::read_stream ( istream &  in,
const Type::TypeBase root_type,
FileFormat  format 
)

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 97 of file reader_to_storage.cc.

Here is the caller graph for this function:

StorageBase * Input::ReaderToStorage::record_automatic_conversion ( PathBase p,
const Type::Record record 
)
protected

Apply automatic conversion of Type::Record type.

Definition at line 277 of file reader_to_storage.cc.

Here is the caller graph for this function:

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   
)

Friends And Related Function Documentation

friend class Type::Default
friend

Definition at line 220 of file reader_to_storage.hh.

Member Data Documentation

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

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

Definition at line 189 of file reader_to_storage.hh.

StorageBase* Input::ReaderToStorage::storage_
protected

Storage of the read and checked input data.

Definition at line 186 of file reader_to_storage.hh.

vector<unsigned int> Input::ReaderToStorage::transpose_array_sizes_
protected

Helper vector what allows check sizes of all transposed Arrays.

Definition at line 218 of file reader_to_storage.hh.

unsigned int Input::ReaderToStorage::transpose_index_
protected

Index of processed item in transposed part of input tree.

Definition at line 215 of file reader_to_storage.hh.

bool Input::ReaderToStorage::try_transpose_read_
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:

  1. We set transpose_index_ to value '0' (transposition of first Array item).
  2. We retrieve whole subtree and find Array types that are located at position where other type is expected (type_of_value of found Array must corresponds with excepted type). We create storage corresponding with subtree (unexpected Arrays are replaced by item at position given by transpose_index_.
  3. Together with paragraph 2 we store sizes of found Arrays to transpose_array_sizes_.
  4. We check sizes stored in transpose_array_sizes_ (all must be in equal and may not be equal to zero). This size determines size of transposed Array type.
  5. We repeat paragraph 2 for all items of transposed Array (gradual increase of transpose_index_).

Definition at line 212 of file reader_to_storage.hh.


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