Flow123d  3.9.0-9663d1cde
reader_internal_csv.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file reader_internal_csv.hh
15  * @brief
16  */
17 
18 #ifndef READER_INTERNAL_CSV_HH_
19 #define READER_INTERNAL_CSV_HH_
20 
21 
22 //#include "input/input_type_forward.hh"
23 
24 //#include "input/storage.hh"
25 //#include "input/path_base.hh"
27 
28 
29 namespace Input {
30 
31 using namespace std;
32 
33 
34 /**
35  * @brief Creates storage of part of subtree defined in CSV file.
36  *
37  * We use this class if input tree contains included CSV file where Array
38  * is expected. This type must correspond with type_of_value of Array of Records.
39  *
40  * @ingroup input
41  */
43 public:
44  /// Constructor
46 
47  /**
48  * Create storage of subtree defined in CSV file of given @p array.
49  *
50  * Processing of subtree included CSV file:
51  * 1. We expect Record with special structure and tag 'include_csv' in place of Array.
52  * 2. We load path to CSV file and number of head lines to skip in this file.
53  * 3. We load Record 'format' which determines positions of columns in CSV file.
54  * Structure of this Record must be equal with subtype of array.
55  * 4. We fill helper @p csv_columns_map_ which allows mapping between columns in CSV
56  * file and storage of array subtype. We return helper storage of this subtype with
57  * default values (only determines structure).
58  * 5. We iterate through CSV file. For every line we fill data into helper storage and
59  * copy this helper storage to storage represents included array.
60  */
61  StorageBase * read_storage(PathBase &p, const Type::Array *array);
62 
63 protected:
64  /// List of data types, used for mapping columns in CSV include.
65  typedef enum {
66  type_int, type_double, type_bool, type_string, type_sel
67  } IncludeDataTypes;
68 
69  /// Data of one column of including CSV file.
70  struct IncludeCsvData {
74  };
75 
76  StorageBase * make_sub_storage(PathBase &p, const Type::Array *array) override; ///< Create storage of Type::Array type
77  StorageBase * make_sub_storage(PathBase &p, const Type::Selection *selection) override; ///< Create storage of Type::Selection type
78  StorageBase * make_sub_storage(PathBase &p, const Type::Bool *bool_type) override; ///< Create storage of Type::Bool type
79  StorageBase * make_sub_storage(PathBase &p, const Type::Integer *int_type) override; ///< Create storage of Type::Integer type
80  StorageBase * make_sub_storage(PathBase &p, const Type::Double *double_type) override; ///< Create storage of Type::Double type
81  StorageBase * make_sub_storage(PathBase &p, const Type::String *string_type) override; ///< Create storage of Type::String type
82 
83  /// Create vector which contains actual indexes of subtree imported in CSV file.
84  vector<unsigned int> create_indexes_vector(PathBase &p);
85 
86  /// Set storage of simple input type with value given from CSV file.
87  void set_storage_from_csv(unsigned int column_index, StorageBase * item_storage, StorageBase * new_storage);
88 
89  /// Checks if value on head represents column position in CSV (starts with '#'). If yes, stores position into \p pos.
90  bool check_and_read_position_index(PathBase &p, int &pos);
91 
92  /// Depth of CSV included subtree
93  unsigned int csv_subtree_depth_;
94 
95  /// Map of columns in CSV file to storage of subtree
97 
98 };
99 
100 
101 } // namespace Input
102 
103 #endif /* READER_INTERNAL_CSV_HH_ */
Input::StorageBase
Base class for nodes of a data storage tree.
Definition: storage.hh:68
Input::Type::Bool
Class for declaration of the input of type Bool.
Definition: type_base.hh:452
Input::int_type
@ int_type
Definition: reader_to_storage.hh:72
Input::ReaderInternalCsvInclude::csv_subtree_depth_
unsigned int csv_subtree_depth_
Depth of CSV included subtree.
Definition: reader_internal_csv.hh:93
Input::ReaderInternalCsvInclude::IncludeCsvData::data_type
IncludeDataTypes data_type
Definition: reader_internal_csv.hh:71
Input
Abstract linear system class.
Definition: balance.hh:40
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
Input::PathBase
Base abstract class used by ReaderToStorage class to iterate over the input tree.
Definition: path_base.hh:41
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
Armor::array
Array< double > array
Definition: armor.hh:890
std::vector< unsigned int >
reader_internal_base.hh
Input::bool_type
@ bool_type
Definition: reader_to_storage.hh:72
Input::ReaderInternalCsvInclude::IncludeCsvData::type
const Type::TypeBase * type
Definition: reader_internal_csv.hh:73
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
std::map
Definition: doxy_dummy_defs.hh:11
Input::ReaderInternalCsvInclude::IncludeDataTypes
IncludeDataTypes
List of data types, used for mapping columns in CSV include.
Definition: reader_internal_csv.hh:65
Input::ReaderInternalCsvInclude::csv_columns_map_
map< unsigned int, IncludeCsvData > csv_columns_map_
Map of columns in CSV file to storage of subtree.
Definition: reader_internal_csv.hh:96
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
Input::ReaderInternalCsvInclude
Creates storage of part of subtree defined in CSV file.
Definition: reader_internal_csv.hh:42
std
Definition: doxy_dummy_defs.hh:5
Input::ReaderInternalCsvInclude::IncludeCsvData::storage_indexes
vector< unsigned int > storage_indexes
Definition: reader_internal_csv.hh:72
Input::ReaderInternalCsvInclude::IncludeCsvData
Data of one column of including CSV file.
Definition: reader_internal_csv.hh:70
Input::Type::TypeBase
Base of classes for declaring structure of the input data.
Definition: type_base.hh:92
Input::ReaderInternalCsvInclude::type_string
@ type_string
Definition: reader_internal_csv.hh:66
Input::ReaderInternalBase
Internal part of IST reader.
Definition: reader_internal_base.hh:42