NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
tablecolumnimpl.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 "tablecolumnimpl.hpp"
20#include "../utils/tools.hpp"
21#include "../ui/error.hpp"
22#include "../../kernel.hpp"
23
24
33std::string ValueColumn::getValueAsString(size_t elem) const
34{
35 if (elem < m_data.size())
36 return toString(m_data[elem], NumeReKernel::getInstance()->getSettings().getPrecision());
37
38 return "nan";
39}
40
41
50std::string ValueColumn::getValueAsInternalString(size_t elem) const
51{
52 return getValueAsString(elem);
53}
54
55
64std::string ValueColumn::getValueAsParserString(size_t elem) const
65{
66 return getValueAsString(elem);
67}
68
69
78std::string ValueColumn::getValueAsStringLiteral(size_t elem) const
79{
80 return getValueAsString(elem);
81}
82
83
94{
95 if (elem < m_data.size())
96 return m_data[elem];
97
98 return NAN;
99}
100
101
110void ValueColumn::setValue(size_t elem, const std::string& sValue)
111{
112 if (isConvertible(sValue, CONVTYPE_VALUE))
113 setValue(elem, StrToCmplx(toInternalString(sValue)));
114 else
115 throw SyntaxError(SyntaxError::STRING_ERROR, sValue, sValue);
116}
117
118
127void ValueColumn::setValue(size_t elem, const mu::value_type& vValue)
128{
129 if (elem >= m_data.size() && mu::isnan(vValue))
130 return;
131
132 if (elem >= m_data.size())
133 m_data.resize(elem+1, NAN);
134
135 m_data[elem] = vValue;
136}
137
138
149{
150 idx.setOpenEndIndex(size()-1);
151
152 ValueColumn* col = new ValueColumn(idx.size());
154
155 for (size_t i = 0; i < idx.size(); i++)
156 {
157 col->m_data[i] = getValue(idx[i]);
158 }
159
160 return col;
161}
162
163
173{
174 if (column->m_type == TableColumn::TYPE_VALUE)
175 {
176 m_sHeadLine = column->m_sHeadLine;
177 m_data = static_cast<const ValueColumn*>(column)->m_data;
178 }
179 else
181}
182
183
193void ValueColumn::insert(const VectorIndex& idx, const TableColumn* column)
194{
195 if (column->m_type == TableColumn::TYPE_VALUE)
196 TableColumn::setValue(idx, static_cast<const ValueColumn*>(column)->m_data);
197 else
199}
200
201
212{
213 idx.setOpenEndIndex(size()-1);
214
215 // Shortcut, if everything shall be deleted
216 if (idx.isExpanded() && idx.front() == 0 && idx.last() >= (int)m_data.size()-1)
217 {
218 m_data.clear();
219 return;
220 }
221
222 for (size_t i = 0; i < idx.size(); i++)
223 {
224 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
225 m_data[idx[i]] = NAN;
226 }
227
228 shrink();
229}
230
231
243void ValueColumn::insertElements(size_t pos, size_t elem)
244{
245 if (pos < m_data.size())
246 m_data.insert(m_data.begin()+pos, elem, NAN);
247}
248
249
258{
259 m_data.insert(m_data.end(), elem, NAN);
260}
261
262
273void ValueColumn::removeElements(size_t pos, size_t elem)
274{
275 if (pos < m_data.size())
276 m_data.erase(m_data.begin()+pos, m_data.begin()+pos+elem);
277}
278
279
287void ValueColumn::resize(size_t elem)
288{
289 if (!elem)
290 m_data.clear();
291 else
292 m_data.resize(elem, NAN);
293}
294
295
307int ValueColumn::compare(int i, int j, bool unused) const
308{
309 if ((int)m_data.size() <= std::max(i, j))
310 return 0;
311
312 if (m_data[i] == m_data[j])
313 return 0;
314 else if (m_data[i].real() < m_data[j].real())
315 return -1;
316
317 return 1;
318}
319
320
329bool ValueColumn::isValid(int elem) const
330{
331 if (elem >= (int)m_data.size() || mu::isnan(m_data[elem]))
332 return false;
333
334 return true;
335}
336
337
345bool ValueColumn::asBool(int elem) const
346{
347 if (elem < 0 || elem >= (int)m_data.size())
348 return false;
349
350 return m_data[elem] != 0.0;
351}
352
353
364{
365 TableColumn* col = nullptr;
366
367 switch (type)
368 {
371 {
372 col = new StringColumn(m_data.size());
373
374 for (size_t i = 0; i < m_data.size(); i++)
375 {
376 if (!mu::isnan(m_data[i]))
377 col->setValue(i, toString(m_data[i], NumeReKernel::getInstance()->getSettings().getPrecision()));
378 }
379
380 break;
381 }
383 {
384 col = new CategoricalColumn(m_data.size());
385
386 for (size_t i = 0; i < m_data.size(); i++)
387 {
388 if (!mu::isnan(m_data[i]))
389 col->setValue(i, toString(m_data[i], NumeReKernel::getInstance()->getSettings().getPrecision()));
390 }
391
392 break;
393 }
395 {
396 col = new DateTimeColumn(m_data.size());
397
398 for (size_t i = 0; i < m_data.size(); i++)
399 {
400 if (!mu::isnan(m_data[i]))
401 col->setValue(i, m_data[i]);
402 }
403
404 break;
405 }
407 {
408 col = new LogicalColumn(m_data.size());
409
410 for (size_t i = 0; i < m_data.size(); i++)
411 {
412 if (!mu::isnan(m_data[i]))
413 col->setValue(i, m_data[i]);
414 }
415
416 break;
417 }
419 return this;
420 default:
421 return nullptr;
422 }
423
425 return col;
426}
427
428
429
430
431
432
433
442std::string DateTimeColumn::getValueAsString(size_t elem) const
443{
444 if (elem < m_data.size() && !mu::isnan(m_data[elem]))
445 return toCmdString(m_data[elem]);
446
447 return "nan";
448}
449
450
459std::string DateTimeColumn::getValueAsInternalString(size_t elem) const
460{
461 if (elem < m_data.size() && !mu::isnan(m_data[elem]))
462 return toString(to_timePoint(m_data[elem]), 0);
463
464 return "nan";
465}
466
467
476std::string DateTimeColumn::getValueAsParserString(size_t elem) const
477{
478 return "\"" + getValueAsInternalString(elem) + "\"";
479}
480
481
490std::string DateTimeColumn::getValueAsStringLiteral(size_t elem) const
491{
492 return getValueAsInternalString(elem);
493}
494
495
506{
507 if (elem < m_data.size())
508 return m_data[elem];
509
510 return NAN;
511}
512
513
522void DateTimeColumn::setValue(size_t elem, const std::string& sValue)
523{
526 else
527 throw SyntaxError(SyntaxError::STRING_ERROR, sValue, sValue);
528}
529
530
539void DateTimeColumn::setValue(size_t elem, const mu::value_type& vValue)
540{
541 if (elem >= m_data.size() && mu::isnan(vValue))
542 return;
543
544 if (elem >= m_data.size())
545 m_data.resize(elem+1, NAN);
546
547 m_data[elem] = vValue.real();
548}
549
550
561{
562 idx.setOpenEndIndex(size()-1);
563
564 DateTimeColumn* col = new DateTimeColumn(idx.size());
566
567 for (size_t i = 0; i < idx.size(); i++)
568 {
569 col->m_data[i] = getValue(idx[i]).real();
570 }
571
572 return col;
573}
574
575
585{
587 {
588 m_sHeadLine = column->m_sHeadLine;
589 m_data.clear();
590
591 for (const auto& val : static_cast<const DateTimeColumn*>(column)->m_data)
592 m_data.push_back(val);
593 }
594 else
596}
597
598
608void DateTimeColumn::insert(const VectorIndex& idx, const TableColumn* column)
609{
612 else
614}
615
616
627{
628 idx.setOpenEndIndex(size()-1);
629
630 // Shortcut, if everything shall be deleted
631 if (idx.isExpanded() && idx.front() == 0 && idx.last() >= (int)m_data.size()-1)
632 {
633 m_data.clear();
634 return;
635 }
636
637 for (size_t i = 0; i < idx.size(); i++)
638 {
639 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
640 m_data[idx[i]] = NAN;
641 }
642
643 shrink();
644}
645
646
658void DateTimeColumn::insertElements(size_t pos, size_t elem)
659{
660 if (pos < m_data.size())
661 m_data.insert(m_data.begin()+pos, elem, NAN);
662}
663
664
673{
674 m_data.insert(m_data.end(), elem, NAN);
675}
676
677
688void DateTimeColumn::removeElements(size_t pos, size_t elem)
689{
690 if (pos < m_data.size())
691 m_data.erase(m_data.begin()+pos, m_data.begin()+pos+elem);
692}
693
694
702void DateTimeColumn::resize(size_t elem)
703{
704 if (!elem)
705 m_data.clear();
706 else
707 m_data.resize(elem, NAN);
708}
709
710
722int DateTimeColumn::compare(int i, int j, bool unused) const
723{
724 if ((int)m_data.size() <= std::max(i, j))
725 return 0;
726
727 if (m_data[i] == m_data[j])
728 return 0;
729 else if (m_data[i] < m_data[j])
730 return -1;
731
732 return 1;
733}
734
735
744bool DateTimeColumn::isValid(int elem) const
745{
746 if (elem >= (int)m_data.size() || std::isnan(m_data[elem]))
747 return false;
748
749 return true;
750}
751
752
760bool DateTimeColumn::asBool(int elem) const
761{
762 if (elem < 0 || elem >= (int)m_data.size())
763 return false;
764
765 return m_data[elem] != 0.0;
766}
767
768
779{
780 TableColumn* col = nullptr;
781
782 switch (type)
783 {
786 {
787 col = new StringColumn(m_data.size());
788
789 for (size_t i = 0; i < m_data.size(); i++)
790 {
791 if (!mu::isnan(m_data[i]))
792 col->setValue(i, toString(to_timePoint(m_data[i]), 0));
793 }
794
795 break;
796 }
798 {
799 col = new CategoricalColumn(m_data.size());
800
801 for (size_t i = 0; i < m_data.size(); i++)
802 {
803 if (!mu::isnan(m_data[i]))
804 col->setValue(i, toString(to_timePoint(m_data[i]), 0));
805 }
806
807 break;
808 }
810 {
811 col = new ValueColumn(m_data.size());
812
813 for (size_t i = 0; i < m_data.size(); i++)
814 {
815 if (!mu::isnan(m_data[i]))
816 col->setValue(i, m_data[i]);
817 }
818
819 break;
820 }
822 return this;
823 default:
824 return nullptr;
825 }
826
828 return col;
829}
830
831
832
833
834
835
836
837
846std::string LogicalColumn::getValueAsString(size_t elem) const
847{
848 if (elem < m_data.size())
849 {
850 if (m_data[elem] == LOGICAL_FALSE)
851 return "false";
852 else if (m_data[elem] == LOGICAL_TRUE)
853 return "true";
854 }
855
856 return "nan";
857}
858
859
868std::string LogicalColumn::getValueAsInternalString(size_t elem) const
869{
870 return getValueAsString(elem);
871}
872
873
882std::string LogicalColumn::getValueAsParserString(size_t elem) const
883{
884 return getValueAsString(elem);
885}
886
887
896std::string LogicalColumn::getValueAsStringLiteral(size_t elem) const
897{
898 return getValueAsString(elem);
899}
900
901
912{
913 if (elem < m_data.size() && m_data[elem] != LOGICAL_NAN)
914 return m_data[elem] ? 1.0 : 0.0;
915
916 return NAN;
917}
918
919
928void LogicalColumn::setValue(size_t elem, const std::string& sValue)
929{
930 if (isConvertible(sValue, CONVTYPE_LOGICAL))
931 setValue(elem, StrToLogical(toInternalString(sValue)));
932 else
933 throw SyntaxError(SyntaxError::STRING_ERROR, sValue, sValue);
934}
935
936
945void LogicalColumn::setValue(size_t elem, const mu::value_type& vValue)
946{
947 if (elem >= m_data.size() && mu::isnan(vValue))
948 return;
949
950 if (elem >= m_data.size())
951 m_data.resize(elem+1, LOGICAL_NAN);
952
953 m_data[elem] = vValue != 0.0 ? LOGICAL_TRUE : LOGICAL_FALSE;
954}
955
956
967{
968 idx.setOpenEndIndex(size()-1);
969
970 LogicalColumn* col = new LogicalColumn(idx.size());
972
973 for (size_t i = 0; i < idx.size(); i++)
974 {
975 col->m_data[i] = m_data[i];
976 }
977
978 return col;
979}
980
981
991{
992 if (column->m_type == TableColumn::TYPE_LOGICAL)
993 {
994 m_sHeadLine = column->m_sHeadLine;
995 m_data = static_cast<const LogicalColumn*>(column)->m_data;
996 }
997 else
999}
1000
1001
1011void LogicalColumn::insert(const VectorIndex& idx, const TableColumn* column)
1012{
1013 if (column->m_type == TableColumn::TYPE_LOGICAL)
1015 else
1017}
1018
1019
1030{
1031 idx.setOpenEndIndex(size()-1);
1032
1033 // Shortcut, if everything shall be deleted
1034 if (idx.isExpanded() && idx.front() == 0 && idx.last() >= (int)m_data.size()-1)
1035 {
1036 m_data.clear();
1037 return;
1038 }
1039
1040 for (size_t i = 0; i < idx.size(); i++)
1041 {
1042 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
1043 m_data[idx[i]] = LOGICAL_NAN;
1044 }
1045
1046 shrink();
1047}
1048
1049
1061void LogicalColumn::insertElements(size_t pos, size_t elem)
1062{
1063 if (pos < m_data.size())
1064 m_data.insert(m_data.begin()+pos, elem, LOGICAL_NAN);
1065}
1066
1067
1076{
1077 m_data.insert(m_data.end(), elem, LOGICAL_NAN);
1078}
1079
1080
1091void LogicalColumn::removeElements(size_t pos, size_t elem)
1092{
1093 if (pos < m_data.size())
1094 m_data.erase(m_data.begin()+pos, m_data.begin()+pos+elem);
1095}
1096
1097
1105void LogicalColumn::resize(size_t elem)
1106{
1107 if (!elem)
1108 m_data.clear();
1109 else
1110 m_data.resize(elem, LOGICAL_NAN);
1111}
1112
1113
1125int LogicalColumn::compare(int i, int j, bool unused) const
1126{
1127 if ((int)m_data.size() <= std::max(i, j))
1128 return 0;
1129
1130 if (m_data[i] == m_data[j])
1131 return 0;
1132 else if (m_data[i] < m_data[j])
1133 return -1;
1134
1135 return 1;
1136}
1137
1138
1147bool LogicalColumn::isValid(int elem) const
1148{
1149 if (elem >= (int)m_data.size() || m_data[elem] == LOGICAL_NAN)
1150 return false;
1151
1152 return true;
1153}
1154
1155
1163bool LogicalColumn::asBool(int elem) const
1164{
1165 if (elem < 0 || elem >= (int)m_data.size())
1166 return false;
1167
1168 return m_data[elem] == LOGICAL_TRUE;
1169}
1170
1171
1182{
1183 TableColumn* col = nullptr;
1184
1185 switch (type)
1186 {
1189 {
1190 col = new StringColumn(m_data.size());
1191
1192 for (size_t i = 0; i < m_data.size(); i++)
1193 {
1194 if (m_data[i] != LOGICAL_NAN)
1195 col->setValue(i, m_data[i] == LOGICAL_TRUE ? "true" : "false");
1196 }
1197
1198 break;
1199 }
1201 {
1202 col = new CategoricalColumn(m_data.size());
1203
1204 for (size_t i = 0; i < m_data.size(); i++)
1205 {
1206 if (m_data[i] != LOGICAL_NAN)
1207 col->setValue(i, m_data[i] == LOGICAL_TRUE ? "true" : "false");
1208 }
1209
1210 break;
1211 }
1213 {
1214 col = new ValueColumn(m_data.size());
1215
1216 for (size_t i = 0; i < m_data.size(); i++)
1217 {
1218 if (m_data[i] != LOGICAL_NAN)
1219 col->setValue(i, m_data[i] == LOGICAL_TRUE ? 1.0 : 0.0);
1220 }
1221
1222 break;
1223 }
1225 return this;
1226 default:
1227 return nullptr;
1228 }
1229
1230 col->m_sHeadLine = m_sHeadLine;
1231 return col;
1232}
1233
1234
1235
1236
1237
1238
1239
1248std::string StringColumn::getValueAsString(size_t elem) const
1249{
1250 return getValueAsParserString(elem);
1251}
1252
1253
1262std::string StringColumn::getValueAsInternalString(size_t elem) const
1263{
1264 if (elem < m_data.size())
1265 return m_data[elem];
1266
1267 return "";
1268}
1269
1270
1279std::string StringColumn::getValueAsParserString(size_t elem) const
1280{
1281 return "\"" + getValueAsInternalString(elem) + "\"";
1282}
1283
1284
1293std::string StringColumn::getValueAsStringLiteral(size_t elem) const
1294{
1296}
1297
1298
1308{
1309 return NAN;
1310}
1311
1312
1321void StringColumn::setValue(size_t elem, const std::string& sValue)
1322{
1323 if (elem >= m_data.size() && !sValue.length())
1324 return;
1325
1326 if (elem >= m_data.size())
1327 m_data.resize(elem+1);
1328
1329 m_data[elem] = sValue;
1330}
1331
1332
1341void StringColumn::setValue(size_t elem, const mu::value_type& vValue)
1342{
1343 if (elem >= m_data.size() && mu::isnan(vValue))
1344 return;
1345
1346 if (elem >= m_data.size())
1347 m_data.resize(elem+1);
1348
1349 m_data[elem] = toString(vValue, NumeReKernel::getInstance()->getSettings().getPrecision());
1350}
1351
1352
1363{
1364 idx.setOpenEndIndex(size()-1);
1365
1366 StringColumn* col = new StringColumn(idx.size());
1367 col->m_sHeadLine = m_sHeadLine;
1368
1369 for (size_t i = 0; i < idx.size(); i++)
1370 {
1371 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
1372 col->m_data[i] = m_data[idx[i]];
1373 }
1374
1375 return col;
1376}
1377
1378
1388{
1389 if (column->m_type == TableColumn::TYPE_STRING)
1390 {
1391 m_sHeadLine = column->m_sHeadLine;
1392 m_data = static_cast<const StringColumn*>(column)->m_data;
1393 }
1394 else
1396}
1397
1398
1408void StringColumn::insert(const VectorIndex& idx, const TableColumn* column)
1409{
1410 if (column->m_type == TableColumn::TYPE_STRING)
1411 TableColumn::setValue(idx, static_cast<const StringColumn*>(column)->m_data);
1412 else
1414}
1415
1416
1427{
1428 idx.setOpenEndIndex(size()-1);
1429
1430 // Shortcut, if everything shall be deleted
1431 if (idx.isExpanded() && idx.front() == 0 && idx.last() >= (int)m_data.size()-1)
1432 {
1433 m_data.clear();
1434 return;
1435 }
1436
1437 for (size_t i = 0; i < idx.size(); i++)
1438 {
1439 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
1440 m_data[idx[i]].clear();
1441 }
1442
1443 shrink();
1444}
1445
1446
1458void StringColumn::insertElements(size_t pos, size_t elem)
1459{
1460 if (pos < m_data.size())
1461 m_data.insert(m_data.begin()+pos, elem, "");
1462}
1463
1464
1473{
1474 m_data.insert(m_data.end(), elem, "");
1475}
1476
1477
1488void StringColumn::removeElements(size_t pos, size_t elem)
1489{
1490 if (pos < m_data.size())
1491 m_data.erase(m_data.begin()+pos, m_data.begin()+pos+elem);
1492}
1493
1494
1502void StringColumn::resize(size_t elem)
1503{
1504 if (!elem)
1505 m_data.clear();
1506 else
1507 m_data.resize(elem, "");
1508}
1509
1510
1522int StringColumn::compare(int i, int j, bool caseinsensitive) const
1523{
1524 if ((int)m_data.size() <= std::max(i, j))
1525 return 0;
1526
1527 if (caseinsensitive)
1528 {
1529 if (toLowerCase(m_data[i]) == toLowerCase(m_data[j]))
1530 return 0;
1531 else if (toLowerCase(m_data[i]) < toLowerCase(m_data[j]))
1532 return -1;
1533 }
1534 else
1535 {
1536 if (m_data[i] == m_data[j])
1537 return 0;
1538 else if (m_data[i] < m_data[j])
1539 return -1;
1540 }
1541
1542 return 1;
1543}
1544
1545
1554bool StringColumn::isValid(int elem) const
1555{
1556 if (elem >= (int)m_data.size() || !m_data[elem].length())
1557 return false;
1558
1559 return true;
1560}
1561
1562
1570bool StringColumn::asBool(int elem) const
1571{
1572 if (elem < 0 || elem >= (int)m_data.size())
1573 return false;
1574
1575 return m_data[elem].length() != 0;
1576}
1577
1578
1587{
1588 size_t bytes = 0;
1589
1590 for (const auto& val : m_data)
1591 bytes += val.length() * sizeof(char);
1592
1593 return bytes + m_sHeadLine.length() * sizeof(char);
1594}
1595
1596
1607{
1608 TableColumn* col = nullptr;
1609
1610 ConvertibleType convType = CONVTYPE_NONE;
1611
1612 // Determine first, if a conversion is possible
1613 for (size_t i = 0; i < m_data.size(); i++)
1614 {
1615 if (!m_data[i].length())
1616 continue;
1617
1618 if (convType == CONVTYPE_NONE)
1619 {
1621 convType = CONVTYPE_VALUE;
1623 convType = CONVTYPE_LOGICAL;
1625 convType = CONVTYPE_DATE_TIME;
1626 else
1627 break;
1628 }
1629 else if (!isConvertible(m_data[i], convType))
1630 {
1631 if (convType == CONVTYPE_VALUE && isConvertible(m_data[i], CONVTYPE_LOGICAL))
1632 convType = CONVTYPE_LOGICAL;
1633 else
1634 {
1635 convType = CONVTYPE_NONE;
1636 break;
1637 }
1638 }
1639 }
1640
1641 switch (type)
1642 {
1644 {
1645 if (convType == CONVTYPE_NONE)
1646 return nullptr;
1647
1648 break;
1649 }
1651 {
1652 if (convType != CONVTYPE_DATE_TIME)
1653 return nullptr;
1654
1655 break;
1656 }
1658 {
1659 if (convType != CONVTYPE_VALUE && convType != CONVTYPE_LOGICAL)
1660 return nullptr;
1661
1662 break;
1663 }
1665 {
1666 if (convType != CONVTYPE_VALUE && convType != CONVTYPE_LOGICAL)
1667 return nullptr;
1668
1669 break;
1670 }
1672 return this;
1674 {
1675 col = new CategoricalColumn(m_data.size());
1677 col->m_sHeadLine = m_sHeadLine;
1678 return col;
1679 }
1680 default:
1681 return nullptr;
1682 }
1683
1684 if (convType == CONVTYPE_DATE_TIME)
1685 col = new DateTimeColumn(m_data.size());
1686 else if (convType == CONVTYPE_VALUE)
1687 col = new ValueColumn(m_data.size());
1688 else if (convType == CONVTYPE_LOGICAL)
1689 col = new LogicalColumn(m_data.size());
1690
1691 for (size_t i = 0; i < m_data.size(); i++)
1692 {
1693 if (!m_data[i].length() || toLowerCase(m_data[i]) == "nan" || m_data[i] == "---")
1694 col->setValue(i, NAN);
1695 else if (toLowerCase(m_data[i]) == "inf")
1696 col->setValue(i, INFINITY);
1697 else if (toLowerCase(m_data[i]) == "-inf")
1698 col->setValue(i, -INFINITY);
1699 else if (convType == CONVTYPE_VALUE)
1700 {
1701 std::string strval = m_data[i];
1702 replaceAll(strval, ",", ".");
1703 col->setValue(i, StrToCmplx(strval));
1704 }
1705 else if (convType == CONVTYPE_LOGICAL)
1706 {
1707 std::string strval = m_data[i];
1708 replaceAll(strval, ",", ".");
1709 col->setValue(i, StrToLogical(strval));
1710 }
1711 else if (convType == CONVTYPE_DATE_TIME)
1712 {
1713 col->setValue(i, to_double(StrToTime(m_data[i])));
1714 }
1715 }
1716
1717 col->m_sHeadLine = m_sHeadLine;
1718 return col;
1719}
1720
1721
1722
1723
1724
1733std::string CategoricalColumn::getValueAsString(size_t elem) const
1734{
1735 if (elem < m_data.size() && m_data[elem] != CATEGORICAL_NAN)
1736 return toString(m_data[elem]+1);
1737
1738 return "nan";
1739}
1740
1741
1751{
1752 if (elem < m_data.size() && m_data[elem] != CATEGORICAL_NAN)
1753 return m_categories[m_data[elem]];
1754
1755 return "";
1756}
1757
1758
1767std::string CategoricalColumn::getValueAsParserString(size_t elem) const
1768{
1769 return "\"" + getValueAsInternalString(elem) + "\"";
1770}
1771
1772
1782{
1783 return getValueAsInternalString(elem);
1784}
1785
1786
1796{
1797 if (elem < m_data.size() && m_data[elem] != CATEGORICAL_NAN)
1798 return m_data[elem]+1;
1799
1800 return NAN;
1801}
1802
1803
1812void CategoricalColumn::setValue(size_t elem, const std::string& sValue)
1813{
1814 if (elem >= m_data.size() && !sValue.length())
1815 return;
1816
1817 if (elem >= m_data.size())
1818 m_data.resize(elem+1, CATEGORICAL_NAN);
1819
1820 auto iter = std::find(m_categories.begin(), m_categories.end(), sValue);
1821
1822 if (iter != m_categories.end())
1823 m_data[elem] = iter - m_categories.begin();
1824 else
1825 {
1826 m_categories.push_back(sValue);
1827 m_data[elem] = m_categories.size()-1;
1828 }
1829}
1830
1831
1840void CategoricalColumn::setValue(size_t elem, const mu::value_type& vValue)
1841{
1842 if (elem >= m_data.size() && mu::isnan(vValue))
1843 return;
1844
1845 if (elem >= m_data.size())
1846 m_data.resize(elem+1, CATEGORICAL_NAN);
1847
1848 if (isInt(vValue) && (size_t)intCast(vValue) <= m_categories.size())
1849 m_data[elem] = intCast(vValue)-1;
1850 else if (mu::isnan(vValue))
1851 m_data[elem] = CATEGORICAL_NAN;
1852 else
1853 setValue(elem, toString(vValue, NumeReKernel::getInstance()->getSettings().getPrecision()));
1854}
1855
1856
1867{
1868 idx.setOpenEndIndex(size()-1);
1869
1870 CategoricalColumn* col = new CategoricalColumn(idx.size());
1871 col->m_sHeadLine = m_sHeadLine;
1872
1873 for (size_t i = 0; i < idx.size(); i++)
1874 {
1875 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
1876 col->m_data[i] = m_data[idx[i]];
1877
1879 }
1880
1881 return col;
1882}
1883
1884
1894{
1896 {
1897 m_sHeadLine = column->m_sHeadLine;
1898 m_data = static_cast<const CategoricalColumn*>(column)->m_data;
1899 m_categories = static_cast<const CategoricalColumn*>(column)->m_categories;
1900 }
1901 else
1903}
1904
1905
1916{
1919 else
1921}
1922
1923
1934{
1935 idx.setOpenEndIndex(size()-1);
1936
1937 // Shortcut, if everything shall be deleted
1938 if (idx.isExpanded() && idx.front() == 0 && idx.last() >= (int)m_data.size()-1)
1939 {
1940 m_data.clear();
1941 m_categories.clear();
1942 return;
1943 }
1944
1945 for (size_t i = 0; i < idx.size(); i++)
1946 {
1947 if (idx[i] >= 0 && idx[i] < (int)m_data.size())
1948 {
1949 m_data[idx[i]] = CATEGORICAL_NAN;
1950 }
1951 }
1952
1953 shrink();
1954}
1955
1956
1968void CategoricalColumn::insertElements(size_t pos, size_t elem)
1969{
1970 if (pos < m_data.size())
1971 m_data.insert(m_data.begin()+pos, elem, CATEGORICAL_NAN);
1972}
1973
1974
1983{
1984 m_data.insert(m_data.end(), elem, CATEGORICAL_NAN);
1985}
1986
1987
1998void CategoricalColumn::removeElements(size_t pos, size_t elem)
1999{
2000 if (pos < m_data.size())
2001 m_data.erase(m_data.begin()+pos, m_data.begin()+pos+elem);
2002}
2003
2004
2013{
2014 if (!elem)
2015 m_data.clear();
2016 else
2017 m_data.resize(elem, CATEGORICAL_NAN);
2018}
2019
2020
2032int CategoricalColumn::compare(int i, int j, bool caseinsensitive) const
2033{
2034 if ((int)m_data.size() <= std::max(i, j))
2035 return 0;
2036
2037 if (caseinsensitive)
2038 {
2040 return 0;
2042 return -1;
2043 }
2044 else
2045 {
2046 if (m_categories[m_data[i]] == m_categories[m_data[j]])
2047 return 0;
2048 else if (m_categories[m_data[i]] < m_categories[m_data[j]])
2049 return -1;
2050 }
2051
2052 return 1;
2053}
2054
2055
2064bool CategoricalColumn::isValid(int elem) const
2065{
2066 if (elem >= (int)m_data.size() || m_data[elem] == CATEGORICAL_NAN)
2067 return false;
2068
2069 return true;
2070}
2071
2072
2080bool CategoricalColumn::asBool(int elem) const
2081{
2082 if (elem < 0 || elem >= (int)m_data.size())
2083 return false;
2084
2085 return m_data[elem] != CATEGORICAL_NAN && m_categories[m_data[elem]].length() != 0;
2086}
2087
2088
2097{
2098 size_t bytes = 0;
2099
2100 for (const auto& val : m_categories)
2101 bytes += val.length() * sizeof(char);
2102
2103 return size() * sizeof(int) + bytes + m_sHeadLine.length() * sizeof(char);
2104}
2105
2106
2117{
2118 TableColumn* col = nullptr;
2119
2120 ConvertibleType convType = CONVTYPE_NONE;
2121
2122 // Determine first, if a conversion is possible
2123 for (size_t i = 0; i < m_categories.size(); i++)
2124 {
2125 if (!m_categories[i].length())
2126 continue;
2127
2128 if (convType == CONVTYPE_NONE)
2129 {
2131 convType = CONVTYPE_VALUE;
2133 convType = CONVTYPE_LOGICAL;
2135 convType = CONVTYPE_DATE_TIME;
2136 else
2137 break;
2138 }
2139 else if (!isConvertible(m_categories[i], convType))
2140 {
2142 convType = CONVTYPE_LOGICAL;
2143 else
2144 {
2145 convType = CONVTYPE_NONE;
2146 break;
2147 }
2148 }
2149 }
2150
2151 switch (type)
2152 {
2154 {
2155 if (convType == CONVTYPE_NONE)
2156 return nullptr;
2157
2158 break;
2159 }
2161 {
2162 if (convType != CONVTYPE_DATE_TIME)
2163 return nullptr;
2164
2165 break;
2166 }
2168 {
2169 if (convType != CONVTYPE_VALUE && convType != CONVTYPE_LOGICAL)
2170 return nullptr;
2171
2172 break;
2173 }
2175 {
2176 if (convType != CONVTYPE_VALUE && convType != CONVTYPE_LOGICAL)
2177 return nullptr;
2178
2179 break;
2180 }
2182 {
2183 col = new StringColumn(m_data.size());
2185 col->m_sHeadLine = m_sHeadLine;
2186 return col;
2187 }
2189 return this;
2190 default:
2191 return nullptr;
2192 }
2193
2194 if (convType == CONVTYPE_DATE_TIME)
2195 col = new DateTimeColumn(m_data.size());
2196 else if (convType == CONVTYPE_VALUE)
2197 col = new ValueColumn(m_data.size());
2198 else if (convType == CONVTYPE_LOGICAL)
2199 col = new LogicalColumn(m_data.size());
2200
2201 for (size_t i = 0; i < m_data.size(); i++)
2202 {
2203 if (m_data[i] == CATEGORICAL_NAN || toLowerCase(m_categories[m_data[i]]) == "nan" || m_categories[m_data[i]] == "---")
2204 col->setValue(i, NAN);
2205 else if (toLowerCase(m_categories[m_data[i]]) == "inf")
2206 col->setValue(i, INFINITY);
2207 else if (toLowerCase(m_categories[m_data[i]]) == "-inf")
2208 col->setValue(i, -INFINITY);
2209 else if (convType == CONVTYPE_VALUE)
2210 {
2211 std::string strval = m_categories[m_data[i]];
2212 replaceAll(strval, ",", ".");
2213 col->setValue(i, StrToCmplx(strval));
2214 }
2215 else if (convType == CONVTYPE_LOGICAL)
2216 {
2217 std::string strval = m_categories[m_data[i]];
2218 replaceAll(strval, ",", ".");
2219 col->setValue(i, StrToLogical(strval));
2220 }
2221 else if (convType == CONVTYPE_DATE_TIME)
2222 {
2224 }
2225 }
2226
2227 col->m_sHeadLine = m_sHeadLine;
2228 return col;
2229}
2230
2231
2240void CategoricalColumn::setCategories(const std::vector<std::string>& vCategories)
2241{
2242 // If the number of new categories is higher or equal to
2243 // the previous one: simply overwrite
2244 if (vCategories.size() >= m_categories.size())
2245 m_categories = vCategories;
2246 else
2247 {
2248 // Otherwise replace only the new ones. But consider the
2249 // case that the user might only want to reorder the categories
2250 for (size_t i = 0; i < vCategories.size(); i++)
2251 {
2252 // Try to find the new category in the current list
2253 auto iter = std::find(m_categories.begin(), m_categories.end(), vCategories[i]);
2254
2255 // If the category was found and is different to the current
2256 // one: swap them. Otherwise simply overwrite
2257 if (iter != m_categories.end() && iter-m_categories.begin() != (int)i)
2258 std::swap(m_categories[i], *iter);
2259 else
2260 m_categories[i] = vCategories[i];
2261 }
2262 }
2263}
2264
2265
2266
2267
2268
2281{
2282 if (!col || (col->m_type != type && !col->size()))
2283 {
2284 std::string sHead = TableColumn::getDefaultColumnHead(colNo);
2285
2286 if (col)
2287 sHead = col->m_sHeadLine;
2288
2289 switch (type)
2290 {
2292 col.reset(new StringColumn);
2293 break;
2295 col.reset(new ValueColumn);
2296 break;
2298 col.reset(new DateTimeColumn);
2299 break;
2301 col.reset(new LogicalColumn);
2302 break;
2304 col.reset(new CategoricalColumn);
2305 break;
2306 default:
2307 return;
2308 }
2309
2310 col->m_sHeadLine = sHead;
2311 }
2312}
2313
2314
2326{
2327 if (!col || (!col->size() && col->m_type != type))
2328 {
2329 convert_if_empty(col, colNo, type);
2330 return true;
2331 }
2332
2333 if (col->m_type == type
2334 || (type == TableColumn::TYPE_CATEGORICAL && col->m_type == TableColumn::TYPE_STRING)
2335 || (type == TableColumn::TYPE_STRING && col->m_type == TableColumn::TYPE_CATEGORICAL))
2336 return true;
2337
2338 TableColumn* convertedCol = col->convert(type);
2339
2340 if (!convertedCol)
2341 return false;
2342
2343 if (convertedCol != col.get())
2344 col.reset(convertedCol);
2345
2346 return true;
2347}
2348
2349
2362{
2363 if (!col || (!col->size() && col->m_type != type))
2364 {
2365 convert_if_empty(col, colNo, type);
2366 return;
2367 }
2368
2369 if (col->m_type == type)
2370 return;
2371
2372 std::string sHeadLine = col->m_sHeadLine;
2373
2374 if (!sHeadLine.length())
2375 sHeadLine = TableColumn::getDefaultColumnHead(colNo);
2376
2377 switch (type)
2378 {
2380 {
2381 col.reset(new StringColumn);
2382 col->m_sHeadLine = sHeadLine;
2383 break;
2384 }
2386 {
2387 col.reset(new ValueColumn);
2388 col->m_sHeadLine = sHeadLine;
2389 break;
2390 }
2392 {
2393 col.reset(new DateTimeColumn);
2394 col->m_sHeadLine = sHeadLine;
2395 break;
2396 }
2398 {
2399 col.reset(new LogicalColumn);
2400 col->m_sHeadLine = sHeadLine;
2401 break;
2402 }
2404 {
2405 col.reset(new CategoricalColumn);
2406 col->m_sHeadLine = sHeadLine;
2407 break;
2408 }
2409 default:
2410 return;
2411 }
2412}
2413
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
A table column containing categorical values.
virtual std::string getValueAsInternalString(size_t elem) const override
Returns the contents as an internal string (i.e. without quotation marks).
CategoricalColumn()
Default constructor. Sets only the column's type.
virtual bool asBool(int elem) const override
Interprets the value as a boolean.
virtual void assign(const TableColumn *column) override
Assign another TableColumn's contents to this table column.
virtual size_t getBytes() const override
Calculates the number of bytes occupied by this column.
virtual void removeElements(size_t pos, size_t elem)
Removes the selected number of elements from the column and moving all following items forward.
std::vector< std::string > m_categories
virtual mu::value_type getValue(size_t elem) const override
Returns always NaN, because this conversion is not possible.
virtual std::string getValueAsParserString(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual void insertElements(size_t pos, size_t elem)
Inserts as many as the selected elements at the desired position, if the column is already larger tha...
virtual void resize(size_t elem) override
Resizes the internal array.
virtual void setValue(size_t elem, const std::string &sValue) override
Set a single string value.
void setCategories(const std::vector< std::string > &vCategories)
Replaces the internal categories with new categories.
virtual std::string getValueAsString(size_t elem) const override
Returns the selected value or an empty string, if the value does not exist.
virtual void insert(const VectorIndex &idx, const TableColumn *column) override
Insert the contents of the passed column at the specified positions.
virtual void deleteElements(const VectorIndex &idx) override
Delete the specified elements.
virtual int compare(int i, int j, bool caseinsensitive) const override
Returns 0, if both elements are equal, -1 if element i is smaller than element j and 1 otherwise.
virtual size_t size() const override
Returns the number of elements in this column (will also count invalid ones).
virtual std::string getValueAsStringLiteral(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual bool isValid(int elem) const override
Returns true, if the selected element is a valid value.
std::vector< int > m_data
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE) override
Returns the contents of this column converted to the new column type. Might even return itself.
virtual void appendElements(size_t elem)
Appends the number of elements.
A table column containing numerical values formatted as dates and times.
virtual size_t size() const override
Return the number of elements in this column (will also count invalid ones).
virtual bool isValid(int elem) const override
Returns true, if the selected element is a valid value.
virtual std::string getValueAsStringLiteral(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual int compare(int i, int j, bool unused) const override
Returns 0, if both elements are equal, -1 if element i is smaller than element j and 1 otherwise.
virtual void setValue(size_t elem, const std::string &sValue) override
Set a single string value.
virtual bool asBool(int elem) const override
Interprets the value as a boolean.
virtual void insertElements(size_t pos, size_t elem) override
Inserts as many as the selected elements at the desired position, if the column is already larger tha...
virtual mu::value_type getValue(size_t elem) const override
Returns the selected value as a numerical type or an invalid value, if it does not exist.
virtual std::string getValueAsString(size_t elem) const override
Returns the selected value as a string or a default value, if it does not exist.
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE) override
Returns the contents of this column converted to the new column type. Might even return itself.
virtual std::string getValueAsInternalString(size_t elem) const override
Returns the contents as an internal string (i.e. without quotation marks).
DateTimeColumn()
Default constructor. Sets only the column's type.
virtual void removeElements(size_t pos, size_t elem) override
Removes the selected number of elements from the column and moving all following items forward.
virtual void resize(size_t elem) override
Resizes the internal array.
std::vector< double > m_data
virtual void insert(const VectorIndex &idx, const TableColumn *column) override
Insert the contents of the passed column at the specified positions.
virtual void appendElements(size_t elem) override
Appends the number of elements.
virtual std::string getValueAsParserString(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual void assign(const TableColumn *column) override
Assign another TableColumn's contents to this table column.
virtual void deleteElements(const VectorIndex &idx) override
Delete the specified elements.
A table column containing logical values.
virtual std::string getValueAsInternalString(size_t elem) const override
Returns the contents as an internal string (i.e. without quotation marks).
virtual mu::value_type getValue(size_t elem) const override
Returns the selected value as a numerical type or an invalid value, if it does not exist.
virtual void insert(const VectorIndex &idx, const TableColumn *column) override
Insert the contents of the passed column at the specified positions.
virtual std::string getValueAsStringLiteral(size_t elem) const override
Returns the contents as parser string (i.e. without quotation marks).
virtual void appendElements(size_t elem) override
Appends the number of elements.
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE) override
Returns the contents of this column converted to the new column type. Might even return itself.
virtual void setValue(size_t elem, const std::string &sValue) override
Set a single string value.
virtual std::string getValueAsParserString(size_t elem) const override
Returns the contents as parser string (i.e. without quotation marks).
virtual void assign(const TableColumn *column) override
Assign another TableColumn's contents to this table column.
virtual bool asBool(int elem) const override
Interprets the value as a boolean.
virtual size_t size() const override
Return the number of elements in this column (will also count invalid ones).
virtual void removeElements(size_t pos, size_t elem) override
Removes the selected number of elements from the column and moving all following items forward.
virtual void insertElements(size_t pos, size_t elem) override
Inserts as many as the selected elements at the desired position, if the column is already larger tha...
virtual int compare(int i, int j, bool unused) const override
Returns 0, if both elements are equal, -1 if element i is smaller than element j and 1 otherwise.
virtual std::string getValueAsString(size_t elem) const override
Returns the selected value as a string or a default value, if it does not exist.
virtual void deleteElements(const VectorIndex &idx) override
Delete the specified elements.
virtual void resize(size_t elem) override
Resizes the internal array.
LogicalColumn()
Default constructor. Sets only the column's type.
virtual bool isValid(int elem) const override
Returns true, if the selected element is a valid value.
std::vector< LogicalValue > m_data
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
A table column containing only strings as values.
virtual std::string getValueAsString(size_t elem) const override
Returns the selected value or an empty string, if the value does not exist.
virtual std::string getValueAsStringLiteral(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual bool asBool(int elem) const override
Interprets the value as a boolean.
virtual std::string getValueAsParserString(size_t elem) const override
Returns the contents as parser string (i.e. with quotation marks).
virtual void insertElements(size_t pos, size_t elem)
Inserts as many as the selected elements at the desired position, if the column is already larger tha...
virtual void deleteElements(const VectorIndex &idx) override
Delete the specified elements.
virtual size_t size() const override
Returns the number of elements in this column (will also count invalid ones).
virtual std::string getValueAsInternalString(size_t elem) const override
Returns the contents as an internal string (i.e. without quotation marks).
virtual int compare(int i, int j, bool caseinsensitive) const override
Returns 0, if both elements are equal, -1 if element i is smaller than element j and 1 otherwise.
virtual bool isValid(int elem) const override
Returns true, if the selected element is a valid value.
std::vector< std::string > m_data
StringColumn()
Default constructor. Sets only the column's type.
virtual size_t getBytes() const override
Calculates the number of bytes occupied by this column.
virtual void resize(size_t elem) override
Resizes the internal array.
virtual void appendElements(size_t elem)
Appends the number of elements.
virtual mu::value_type getValue(size_t elem) const override
Returns always NaN, because this conversion is not possible.
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE) override
Returns the contents of this column converted to the new column type. Might even return itself.
virtual void setValue(size_t elem, const std::string &sValue) override
Set a single string value.
virtual void insert(const VectorIndex &idx, const TableColumn *column) override
Insert the contents of the passed column at the specified positions.
virtual void assign(const TableColumn *column) override
Assign another TableColumn's contents to this table column.
virtual void removeElements(size_t pos, size_t elem)
Removes the selected number of elements from the column and moving all following items forward.
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ CANNOT_ASSIGN_COLUMN_OF_DIFFERENT_TYPE
Definition: error.hpp:88
@ STRING_ERROR
Definition: error.hpp:209
A table column containing only numerical values.
virtual bool asBool(int elem) const override
Interprets the value as a boolean.
virtual int compare(int i, int j, bool unused) const override
Returns 0, if both elements are equal, -1 if element i is smaller than element j and 1 otherwise.
virtual void deleteElements(const VectorIndex &idx) override
Delete the specified elements.
virtual void appendElements(size_t elem) override
Appends the number of elements.
virtual std::string getValueAsString(size_t elem) const override
Returns the selected value as a string or a default value, if it does not exist.
ValueColumn()
Default constructor. Sets only the type of the column.
virtual std::string getValueAsParserString(size_t elem) const override
Returns the contents as parser string (i.e. without quotation marks).
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE) override
Returns the contents of this column converted to the new column type. Might even return itself.
virtual std::string getValueAsStringLiteral(size_t elem) const override
Returns the contents as parser string (i.e. without quotation marks).
std::vector< mu::value_type > m_data
virtual void setValue(size_t elem, const std::string &sValue) override
Set a single string value.
virtual void insert(const VectorIndex &idx, const TableColumn *column) override
Insert the contents of the passed column at the specified positions.
virtual void insertElements(size_t pos, size_t elem) override
Inserts as many as the selected elements at the desired position, if the column is already larger tha...
virtual mu::value_type getValue(size_t elem) const override
Returns the selected value as a numerical type or an invalid value, if it does not exist.
virtual std::string getValueAsInternalString(size_t elem) const override
Returns the contents as an internal string (i.e. without quotation marks).
virtual bool isValid(int elem) const override
Returns true, if the selected element is a valid value.
virtual size_t size() const override
Return the number of elements in this column (will also count invalid ones).
virtual void resize(size_t elem) override
Resizes the internal array.
virtual void assign(const TableColumn *column) override
Assign another TableColumn's contents to this table column.
virtual void removeElements(size_t pos, size_t elem) override
Removes the selected number of elements from the column and moving all following items forward.
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
int last() const
This member function returns the last index value, which can be reached by the values stored internal...
Definition: structures.hpp:693
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
bool isExpanded() const
This member function determines, whether the indices are calculated or actual vectorial indices.
Definition: structures.hpp:377
int & front()
This member function returns a reference to the first index value stored internally.
Definition: structures.hpp:640
sys_time_point to_timePoint(double d)
Convert a double to a sys_time_point assuming the double is in units of seconds.
double to_double(sys_time_point tp)
Convert a sys_time_point to a double. The double is returned in units of seconds.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
std::vector< double > real(const std::vector< value_type > &vVec)
#define max(a, b)
Definition: resampler.cpp:30
std::string toInternalString(std::string sStr)
Converts a string literal to the internal representation in tables and clusters.
std::string toExternalString(std::string sStr)
Converts an internal string to the external representation in the terminal.
sys_time_point StrToTime(const std::string &sString)
Convert a string to a sys_time_point.
double StrToLogical(const std::string &sString)
Converts a string into a double considering logical values.
bool isConvertible(const std::string &sStr, ConvertibleType type)
This function checks, whether a string can be converted to the selected ConvertibleType.
std::complex< double > StrToCmplx(const std::string &sString)
Converts a string into a complex number.
std::string toCmdString(double dNumber)
Converts a numerical value into a "full" precision string.
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
ConvertibleType
Definition: stringtools.hpp:42
@ CONVTYPE_DATE_TIME
Definition: stringtools.hpp:45
@ CONVTYPE_LOGICAL
Definition: stringtools.hpp:46
@ CONVTYPE_NONE
Definition: stringtools.hpp:43
@ CONVTYPE_VALUE
Definition: stringtools.hpp:44
Abstract table column, which allows using it to compose the data table in each Memory instance.
Definition: tablecolumn.hpp:34
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
TableColumn * copy() const
Simplification wrapper around the indiced copy method to copy the whole column.
virtual TableColumn * convert(ColumnType type=TableColumn::TYPE_NONE)=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
ColumnType m_type
Definition: tablecolumn.hpp:49
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::string m_sHeadLine
Definition: tablecolumn.hpp:48
void setValue(const VectorIndex &idx, const std::vector< std::string > &vValue)
Sets a string vector at the specified indices.
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
std::unique_ptr< TableColumn > TblColPtr
Typedef for simplifying the usage of a smart pointer in combination with a TableColumn instance.
void convert_for_overwrite(TblColPtr &col, size_t colNo, TableColumn::ColumnType type)
This function deletes the contents of a column, if necessary, and creates a new column with the corre...
void convert_if_empty(TblColPtr &col, size_t colNo, TableColumn::ColumnType type)
Tries to convert a column if the column does not contain any data (with the exception of the header).
bool convert_if_needed(TblColPtr &col, size_t colNo, TableColumn::ColumnType type)
Tries to convert a column into the selected column, if possible.
bool isInt(const std::complex< double > &number)
Determines, whether the content of a complex value is actually a regular integer.
Definition: tools.cpp:1838