OpenWalnut  1.5.0dev
WProtonData.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROTONDATA_H
26 #define WPROTONDATA_H
27 
28 #include <list>
29 #include <map>
30 #include <memory>
31 #include <regex>
32 #include <string>
33 #include <vector>
34 
35 #include "WDataType.h"
36 #include "core/dataHandler/WDataSetCSV.h"
37 
38 
39 /**
40  * Holds the csv data.
41  */
43 {
44  /**
45  * only test class may be friend
46  */
47  friend class WProtonDataTest;
48 public:
49  /**
50  * shared_ptr that points to itself
51  */
52  typedef std::shared_ptr< WProtonData > SPtr;
53 
54  /**
55  * constructor
56  *
57  * \param csvHeader pointer to a column-header of the CSV-file
58  * \param csvData pointer to a content of the CSV file
59  */
60  explicit WProtonData( WDataSetCSV::ContentSPtr csvHeader, WDataSetCSV::ContentSPtr csvData );
61 
62  /**
63  * getter
64  *
65  * \return pointer to a column-header of the CSV-file
66  */
68 
69  /**
70  * getter
71  *
72  * \return pointer to a content of the CSV file
73  */
75 
76  /**
77  * setter
78  *
79  * \param csvHeader set m_csvHeader
80  */
81  void setCSVHeader( WDataSetCSV::ContentSPtr csvHeader );
82 
83  /**
84  * setter
85  *
86  * \param csvData set m_csvData
87  */
88  void setCSVData( WDataSetCSV::ContentSPtr csvData );
89 
90  /**
91  * setter
92  *
93  * \param columnName Name of column-header of the CSV-file
94  * \param index position of column-header of the CSV-file
95  */
96  void setStateIndex( std::string columnName, int index );
97 
98  /**
99  * getter
100  *
101  * \param selectedName Name of selected name of single-selection
102  * \return return the position current selected item
103  */
104  int getColumnIndexBySelection( std::string selectedName );
105 
106  /**
107  * getter
108  *
109  * \param columnName Name of column-header of the CSV-file
110  * \return return the position of column-header of the CSV-file as int
111  */
112  int getColumnIndex( std::string columnName );
113 
114  /**
115  * checks whether columns are available
116  * \param columnName THe name of the column.
117  * \return true if column is available, false if column is not available
118  */
119  bool isColumnAvailable( std::string columnName );
120 
121  /**
122  * Get column types, stored in a string vector.
123  * Positions within this vector are linked to positions in m_csvHeader
124  * \return a shared pointer to m_columnTypes
125  */
127 
128  /**
129  * Return a vector of filtered Headers
130  * \param typeNames Types of filter
131  * \return Return a vector of filtered Headers
132  */
133  std::vector< std::string > getHeaderFromType( std::list< std::string > typeNames );
134 
135 private:
136  /**
137  * Stores column index of data.
138  */
140 
141  /**
142  * Stores data from obtained input file.
143  */
145 
146  /**
147  * Stores data as map
148  */
149  std::map< std::string, int > m_columnMap;
150 
151  /**
152  * Stores index of the selected single-selector (ColumnPropertyHandler)
153  */
154  std::map< std::string, int > m_ColumnMapSelectedIndex;
155 
156  /**
157  * Stores the information, which data type is stored in associated column
158  */
160 
161  /**
162  * Reads csv data and stores column types in m_columnTypes
163  * \param csvData the input csv data
164  */
166 
167  /**
168  * Determines column type due to cellValue
169  * \param cellValue the value of a cell on the basis of which the column type is to be determined
170  * \return either "int", "double" or "string"
171  */
172  std::string determineColumnTypeByString( std::string cellValue );
173 
174  /**
175  * Checks, if values of a column, containing double values, can be converted to integers
176  * \param columnNumber the column number within m_csvHeader
177  * \return true, if all double values of a column ends with ".0"; false otherwise
178  */
179  bool checkIfDoubleColumnCanBeInteger( int columnNumber );
180 };
181 
182 #endif // WPROTONDATA_H
std::shared_ptr< std::vector< std::vector< std::string > > > ContentSPtr
represents a pointer to the Content
Definition: WDataSetCSV.h:52
std::shared_ptr< std::vector< std::string > > ContentElemSPtr
represents a shared pointer to a ContentElem object.
Definition: WDataSetCSV.h:67
Test class of WMProtonData class.
Holds the csv data.
Definition: WProtonData.h:43
WDataSetCSV::ContentElemSPtr m_columnTypes
Stores the information, which data type is stored in associated column.
Definition: WProtonData.h:159
int getColumnIndex(std::string columnName)
getter
std::shared_ptr< WProtonData > SPtr
shared_ptr that points to itself
Definition: WProtonData.h:52
WDataSetCSV::ContentElemSPtr getColumnTypes()
Get column types, stored in a string vector.
WDataSetCSV::ContentSPtr m_csvData
Stores data from obtained input file.
Definition: WProtonData.h:144
void detectColumnTypesFromCsvData(WDataSetCSV::ContentSPtr csvData)
Reads csv data and stores column types in m_columnTypes.
std::map< std::string, int > m_ColumnMapSelectedIndex
Stores index of the selected single-selector (ColumnPropertyHandler)
Definition: WProtonData.h:154
int getColumnIndexBySelection(std::string selectedName)
getter
WDataSetCSV::ContentSPtr m_csvHeader
Stores column index of data.
Definition: WProtonData.h:139
std::string determineColumnTypeByString(std::string cellValue)
Determines column type due to cellValue.
WProtonData(WDataSetCSV::ContentSPtr csvHeader, WDataSetCSV::ContentSPtr csvData)
constructor
Definition: WProtonData.cpp:34
void setCSVData(WDataSetCSV::ContentSPtr csvData)
setter
Definition: WProtonData.cpp:64
void setStateIndex(std::string columnName, int index)
setter
Definition: WProtonData.cpp:91
WDataSetCSV::ContentSPtr getCSVHeader()
getter
Definition: WProtonData.cpp:86
void setCSVHeader(WDataSetCSV::ContentSPtr csvHeader)
setter
Definition: WProtonData.cpp:40
bool checkIfDoubleColumnCanBeInteger(int columnNumber)
Checks, if values of a column, containing double values, can be converted to integers.
WDataSetCSV::ContentSPtr getCSVData()
getter
Definition: WProtonData.cpp:81
std::vector< std::string > getHeaderFromType(std::list< std::string > typeNames)
Return a vector of filtered Headers.
std::map< std::string, int > m_columnMap
Stores data as map.
Definition: WProtonData.h:149
bool isColumnAvailable(std::string columnName)
checks whether columns are available
Definition: WProtonData.cpp:97