NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
tablecolumn.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "tablecolumn.hpp"
20#include "../ui/language.hpp"
21#include "../utils/tools.hpp"
22
23extern Language _lang;
24
25
34std::vector<std::string> TableColumn::getValueAsString(const VectorIndex& idx) const
35{
36 idx.setOpenEndIndex(size()-1);
37 std::vector<std::string> vVect(idx.size());
38
39 for (size_t i = 0; i < idx.size(); i++)
40 {
41 vVect[i] = getValueAsString(idx[i]);
42 }
43
44 return vVect;
45}
46
47
56std::vector<std::string> TableColumn::getValueAsInternalString(const VectorIndex& idx) const
57{
58 idx.setOpenEndIndex(size()-1);
59 std::vector<std::string> vVect(idx.size());
60
61 for (size_t i = 0; i < idx.size(); i++)
62 {
63 vVect[i] = getValueAsInternalString(idx[i]);
64 }
65
66 return vVect;
67}
68
69
78std::vector<mu::value_type> TableColumn::getValue(const VectorIndex& idx) const
79{
80 idx.setOpenEndIndex(size()-1);
81 std::vector<mu::value_type> vVect(idx.size());
82
83 for (size_t i = 0; i < idx.size(); i++)
84 {
85 vVect[i] = getValue(idx[i]);
86 }
87
88 return vVect;
89}
90
91
101void TableColumn::setValue(const VectorIndex& idx, const std::vector<std::string>& vValue)
102{
103 for (size_t i = 0; i < idx.size(); i++)
104 {
105 if (i >= vValue.size())
106 break;
107
108 setValue(idx[i], vValue[i]);
109 }
110}
111
112
122void TableColumn::setValue(const VectorIndex& idx, const std::vector<mu::value_type>& vValue)
123{
124 for (size_t i = 0; i < idx.size(); i++)
125 {
126 if (i >= vValue.size())
127 break;
128
129 setValue(idx[i], vValue[i]);
130 }
131}
132
133
144void TableColumn::setValue(const VectorIndex& idx, mu::value_type* _dData, unsigned int _nNum)
145{
146 for (size_t i = 0; i < idx.size(); i++)
147 {
148 if (i >= _nNum)
149 break;
150
151 setValue(idx[i], _dData[i]);
152 }
153}
154
155
164{
166}
167
168
177{
178 for (int i = size()-1; i >= 0; i--)
179 {
180 if (isValid(i))
181 {
182 resize(i+1);
183 return;
184 }
185 }
186
187 // If the code reaches this point, it is either empty
188 // or full of invalid values
189 resize(0);
190}
191
192
202{
203 for (size_t i = size(); i > 0; i--)
204 {
205 if (isValid(i-1))
206 return i;
207 }
208
209 return 0;
210}
211
212
222std::string TableColumn::getDefaultColumnHead(size_t colNo)
223{
224 return _lang.get("COMMON_COL") + "_" + toString(colNo+1);
225}
226
227
237{
238 switch (type)
239 {
240 case TYPE_NONE:
241 return "none";
242 case TYPE_VALUE:
243 return "value";
244 case TYPE_STRING:
245 return "string";
246 case TYPE_DATETIME:
247 return "datetime";
248 case TYPE_LOGICAL:
249 return "logical";
250 case TYPE_CATEGORICAL:
251 return "category";
252 default:
253 return "unknown";
254 }
255
256 return "";
257}
258
259
269{
270 if (sType == "value")
271 return TYPE_VALUE;
272 else if (sType == "string")
273 return TYPE_STRING;
274 else if (sType == "datetime")
275 return TYPE_DATETIME;
276 else if (sType == "logical")
277 return TYPE_LOGICAL;
278 else if (sType == "category")
279 return TYPE_CATEGORICAL;
280
281 return TYPE_NONE;
282}
283
284
292std::vector<std::string> TableColumn::getTypesAsString()
293{
294 return {"value", "string", "datetime", "logical", "category"};
295}
296
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
void setOpenEndIndex(int nLast) const
This member function can be used to replace the open end state with a defined index value although th...
Definition: structures.hpp:756
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
Abstract table column, which allows using it to compose the data table in each Memory instance.
Definition: tablecolumn.hpp:34
virtual bool isValid(int elem) const =0
void shrink()
Shrink the column by removing all invalid elements from the end.
std::vector< std::string > getValueAsInternalString(const VectorIndex &idx) const
Returns the table column's contents as a vector containing internal strings.
Definition: tablecolumn.cpp:56
size_t getNumFilledElements() const
Return the number of actual filled elements in this column, which can be different from the actual si...
TableColumn * copy() const
Simplification wrapper around the indiced copy method to copy the whole column.
static ColumnType stringToType(const std::string &sType)
Converts the passed string representation to a ColumnType value.
virtual size_t size() const =0
std::vector< mu::value_type > getValue(const VectorIndex &idx) const
Return the table column's contents as a vector of numerical types.
Definition: tablecolumn.cpp:78
virtual void resize(size_t elem)=0
static std::string getDefaultColumnHead(size_t colNo)
Creates a default column headline for a column, which can be used without an instance of this class.
static std::string typeToString(ColumnType type)
Converts the passed ColumnType value to a string representation.
std::vector< std::string > getValueAsString(const VectorIndex &idx) const
Return the table column's contents as a vector of strings.
Definition: tablecolumn.cpp:34
static std::vector< std::string > getTypesAsString()
Returns a list of all available column types as strings.
void setValue(const VectorIndex &idx, const std::vector< std::string > &vValue)
Sets a string vector at the specified indices.
std::string toString(int)
Converts an integer to a string without the Settings bloat.
Language _lang
Definition: kernel.cpp:39