Flow123d  release_2.2.0-26-ge868538
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
68 
69  /// Data of one column of including CSV file.
70  struct IncludeCsvData {
71  IncludeDataTypes data_type;
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_ */
IncludeDataTypes
List of data types, used for mapping columns in CSV include.
Base of classes for declaring structure of the input data.
Definition: type_base.hh:99
Base class for nodes of a data storage tree.
Definition: storage.hh:68
Class for declaration of the input of type Bool.
Definition: type_base.hh:458
Base abstract class used by ReaderToStorage class to iterate over the input tree. ...
Definition: path_base.hh:41
Data of one column of including CSV file.
Class for declaration of the integral input data.
Definition: type_base.hh:489
Class for declaration of inputs sequences.
Definition: type_base.hh:345
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:540
map< unsigned int, IncludeCsvData > csv_columns_map_
Map of columns in CSV file to storage of subtree.
unsigned int csv_subtree_depth_
Depth of CSV included subtree.
Creates storage of part of subtree defined in CSV file.
Internal part of IST reader.
Class for declaration of the input data that are in string format.
Definition: type_base.hh:588
Template for classes storing finite set of named values.