Flow123d  master-f44eb46
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Input::ReaderInternalCsvInclude Class Reference

Creates storage of part of subtree defined in CSV file. More...

#include <reader_internal_csv.hh>

Inheritance diagram for Input::ReaderInternalCsvInclude:
Inheritance graph
[legend]
Collaboration diagram for Input::ReaderInternalCsvInclude:
Collaboration graph
[legend]

Classes

struct  IncludeCsvData
 Data of one column of including CSV file. More...
 

Public Member Functions

 ReaderInternalCsvInclude ()
 Constructor. More...
 
StorageBaseread_storage (PathBase &p, const Type::Array *array)
 
- Public Member Functions inherited from Input::ReaderInternalBase
 TYPEDEF_ERR_INFO (EI_InputType, string)
 
 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)
 
 TYPEDEF_ERR_INFO (EI_JSONLine, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_JSONColumn, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_JSONReason, string)
 
 TYPEDEF_ERR_INFO (EI_InputErrorMessage, const string)
 
 TYPEDEF_ERR_INFO (EI_RecordName, const string)
 
 TYPEDEF_ERR_INFO (EI_Tag, string)
 
 TYPEDEF_ERR_INFO (EI_TokenizerMsg, std::string)
 
 TYPEDEF_ERR_INFO (EI_ColumnIndex, unsigned int)
 
 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)
 General exception during conversion from JSON/YAML tree to storage. More...
 
 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")
 
 DECLARE_INPUT_EXCEPTION (ExcAutomaticConversionError,<< "Error during automatic conversion of "<< EI_RecordName::val<< " record.\n "<< EI_InputErrorMessage::val<< "\n")
 
 DECLARE_INPUT_EXCEPTION (ExcForbiddenTag,<< "Tag "<< EI_Tag::qval<< " "<< EI_Specification::val<< "\n")
 
 DECLARE_INPUT_EXCEPTION (ExcDuplicitTag,<< "Error in input file: "<< EI_File::qval<< " at address: "<< EI_ErrorAddress::qval<< "\n"<< "Duplicit Tag: "<< EI_Tag::qval<< "\n")
 
 DECLARE_INPUT_EXCEPTION (ExcWrongCsvFormat,<< EI_Specification::val<< ",\n"<< EI_TokenizerMsg::val<< "\n")
 
 DECLARE_INPUT_EXCEPTION (ExcMultipleDefinitionCsvColumn,<< "Multiple definition of column with index "<< EI_ColumnIndex::qval<< " in included CSV file:\n"<< EI_File::val<< ",\n")
 
 ReaderInternalBase ()
 Constructor. More...
 

Protected Types

enum  IncludeDataTypes {
  type_int , type_double , type_bool , type_string ,
  type_sel
}
 List of data types, used for mapping columns in CSV include. More...
 

Protected Member Functions

StorageBasemake_sub_storage (PathBase &p, const Type::Array *array) override
 Create storage of Type::Array type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Selection *selection) override
 Create storage of Type::Selection type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Bool *bool_type) override
 Create storage of Type::Bool type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Integer *int_type) override
 Create storage of Type::Integer type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Double *double_type) override
 Create storage of Type::Double type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::String *string_type) override
 Create storage of Type::String type. More...
 
vector< unsigned int > create_indexes_vector (PathBase &p)
 Create vector which contains actual indexes of subtree imported in CSV file. More...
 
void set_storage_from_csv (unsigned int column_index, StorageBase *item_storage, StorageBase *new_storage)
 Set storage of simple input type with value given from CSV file. More...
 
bool check_and_read_position_index (PathBase &p, int &pos)
 Checks if value on head represents column position in CSV (starts with '#'). If yes, stores position into pos. More...
 
- Protected Member Functions inherited from Input::ReaderInternalBase
StorageBasemake_storage (PathBase &p, const Type::TypeBase *type)
 Create storage of given type. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Record *record)
 Create storage of Type::Record type. Common method of all descendants. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Tuple *tuple)
 Create storage of Type::Tuple type. Common method of all descendants. More...
 
StorageBasemake_sub_storage (PathBase &p, const Type::Abstract *abstr_rec)
 Create storage of Type::Abstract type. Common method of all descendants. 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_array_storage (PathBase &p, const Type::Array *array, int arr_size)
 Create storage of Type::Array with given size. 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...
 
StorageBasemake_include_storage (PathBase &p, const Type::TypeBase *type)
 Create storage of included YAML or JSON input file. More...
 
bool read_bool_value (PathBase &p, const Type::TypeBase *type)
 Read boolean value from path. More...
 
std::int64_t read_int_value (PathBase &p, const Type::TypeBase *type)
 Read integer value from path. More...
 
double read_double_value (PathBase &p, const Type::TypeBase *type)
 Read double value from path. More...
 
std::string read_string_value (PathBase &p, const Type::TypeBase *type)
 Read string value from path. More...
 
std::string get_included_file (PathBase &p)
 Helper method. Get string value of included file or throw exception if reading failed. More...
 
void generate_input_error (PathBase &p, const Type::TypeBase *type, std::string spec, bool add_type)
 Generate ExcInputError. More...
 
void complete_input_error (ExcInputError &e, PathBase &p, ValueTypes value_type)
 Complete specification, error address and JSON type error tags to ExcInputError. More...
 

Protected Attributes

unsigned int csv_subtree_depth_
 Depth of CSV included subtree. More...
 
map< unsigned int, IncludeCsvDatacsv_columns_map_
 Map of columns in CSV file to storage of subtree. More...
 

Detailed Description

Creates storage of part of subtree defined in CSV file.

We use this class if input tree contains included CSV file where Array is expected. This type must correspond with type_of_value of Array of Records.

Definition at line 42 of file reader_internal_csv.hh.

Member Enumeration Documentation

◆ IncludeDataTypes

List of data types, used for mapping columns in CSV include.

Enumerator
type_int 
type_double 
type_bool 
type_string 
type_sel 

Definition at line 65 of file reader_internal_csv.hh.

Constructor & Destructor Documentation

◆ ReaderInternalCsvInclude()

Input::ReaderInternalCsvInclude::ReaderInternalCsvInclude ( )

Constructor.

Definition at line 35 of file reader_internal_csv.cc.

Member Function Documentation

◆ check_and_read_position_index()

bool Input::ReaderInternalCsvInclude::check_and_read_position_index ( PathBase p,
int &  pos 
)
protected

Checks if value on head represents column position in CSV (starts with '#'). If yes, stores position into pos.

Definition at line 366 of file reader_internal_csv.cc.

◆ create_indexes_vector()

vector< unsigned int > Input::ReaderInternalCsvInclude::create_indexes_vector ( PathBase p)
protected

Create vector which contains actual indexes of subtree imported in CSV file.

Definition at line 345 of file reader_internal_csv.cc.

◆ make_sub_storage() [1/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::Array array 
)
overrideprotectedvirtual

Create storage of Type::Array type.

Implements Input::ReaderInternalBase.

Definition at line 226 of file reader_internal_csv.cc.

◆ make_sub_storage() [2/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::Bool bool_type 
)
overrideprotectedvirtual

Create storage of Type::Bool type.

Implements Input::ReaderInternalBase.

Definition at line 265 of file reader_internal_csv.cc.

◆ make_sub_storage() [3/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::Double double_type 
)
overrideprotectedvirtual

Create storage of Type::Double type.

Implements Input::ReaderInternalBase.

Definition at line 305 of file reader_internal_csv.cc.

◆ make_sub_storage() [4/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::Integer int_type 
)
overrideprotectedvirtual

Create storage of Type::Integer type.

Implements Input::ReaderInternalBase.

Definition at line 285 of file reader_internal_csv.cc.

◆ make_sub_storage() [5/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::Selection selection 
)
overrideprotectedvirtual

Create storage of Type::Selection type.

Implements Input::ReaderInternalBase.

Definition at line 238 of file reader_internal_csv.cc.

◆ make_sub_storage() [6/6]

StorageBase * Input::ReaderInternalCsvInclude::make_sub_storage ( PathBase p,
const Type::String string_type 
)
overrideprotectedvirtual

Create storage of Type::String type.

Implements Input::ReaderInternalBase.

Definition at line 325 of file reader_internal_csv.cc.

◆ read_storage()

StorageBase * Input::ReaderInternalCsvInclude::read_storage ( PathBase p,
const Type::Array array 
)

Create storage of subtree defined in CSV file of given array.

Processing of subtree included CSV file:

  1. We expect Record with special structure and tag 'include_csv' in place of Array.
  2. We load path to CSV file and number of head lines to skip in this file.
  3. We load Record 'format' which determines positions of columns in CSV file. Structure of this Record must be equal with subtype of array.
  4. We fill helper csv_columns_map_ which allows mapping between columns in CSV file and storage of array subtype. We return helper storage of this subtype with default values (only determines structure).
  5. We iterate through CSV file. For every line we fill data into helper storage and copy this helper storage to storage represents included array.

Definition at line 38 of file reader_internal_csv.cc.

Here is the caller graph for this function:

◆ set_storage_from_csv()

void Input::ReaderInternalCsvInclude::set_storage_from_csv ( unsigned int  column_index,
StorageBase item_storage,
StorageBase new_storage 
)
protected

Set storage of simple input type with value given from CSV file.

Definition at line 355 of file reader_internal_csv.cc.

Member Data Documentation

◆ csv_columns_map_

map<unsigned int, IncludeCsvData> Input::ReaderInternalCsvInclude::csv_columns_map_
protected

Map of columns in CSV file to storage of subtree.

Definition at line 96 of file reader_internal_csv.hh.

◆ csv_subtree_depth_

unsigned int Input::ReaderInternalCsvInclude::csv_subtree_depth_
protected

Depth of CSV included subtree.

Definition at line 93 of file reader_internal_csv.hh.


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