NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
table.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2018 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#ifndef TABLE_HPP
20#define TABLE_HPP
21
22#include "tablecolumn.hpp"
23#include <ctime>
24
25namespace NumeRe
26{
32 {
33 std::string comment;
34 std::string source;
35 __time64_t lastSavedTime;
36 bool isSaved;
37
38 void save()
39 {
40 lastSavedTime = _time64(0);
41 isSaved = true;
42 }
43
44 void modify()
45 {
46 if (!isSaved)
47 return;
48
49 lastSavedTime = _time64(0);
50 isSaved = false;
51 }
52
54 {
55 TableMetaData melted(*this);
56
57 if (meta.comment.length())
58 {
59 if (melted.comment.length())
60 melted.comment += "\n\n========\n\n" + meta.comment;
61 else
62 melted.comment = meta.comment;
63 }
64
65 if (meta.source.length())
66 {
67 if (melted.source.length())
68 melted.source += "; " + meta.source;
69 else
70 melted.source = meta.source;
71 }
72
73 return melted;
74 }
75 };
76
77
78
79
80
86 class Table
87 {
88 private:
90 std::string sTableName;
92
93 void setMinSize(size_t i, size_t j);
94 bool isNumerical(const std::string& sValue) const;
95
96 public:
97 Table();
98 Table(int nLines, int nCols);
99 Table(const Table& _table);
100 Table(Table&& _table);
101 ~Table();
102
103 Table& operator=(Table _table);
104
105 void Clear();
106
107 void setSize(size_t i, size_t j);
108
109 void setName(const std::string& _sName);
110 void setComment(const std::string& _comment);
111 void setMetaData(const TableMetaData& meta);
112 void setHead(size_t i, const std::string& _sHead);
113 void setHeadPart(size_t i, size_t part, const std::string& _sHead);
114 void setValue(size_t i, size_t j, const mu::value_type& _dValue);
115 void setValueAsString(size_t i, size_t j, const std::string& _sValue);
116 void setColumn(size_t j, TableColumn* column);
117 bool setColumnType(size_t j, TableColumn::ColumnType _type);
118
119 std::string getName() const;
120 std::string getComment() const;
122 int getHeadCount() const;
123 std::string getHead(size_t i) const;
124 std::string getCleanHead(size_t i) const;
125 std::string getCleanHeadPart(size_t i, size_t part = 0) const;
126 mu::value_type getValue(size_t i, size_t j) const;
127 std::string getValueAsString(size_t i, size_t j) const;
128 TableColumn* getColumn(size_t j) const;
131
132 size_t getLines() const;
133 size_t getCols() const;
134
135 bool isEmpty() const;
136
137 bool insertLines(size_t nPos = 0, size_t nNum = 1);
138 bool appendLines(size_t nNum = 1);
139 bool deleteLines(size_t nPos = 0, size_t nNum = 1);
140 bool insertCols(size_t nPos = 0, size_t nNum = 1);
141 bool appendCols(size_t nNum = 1);
142 bool deleteCols(size_t nPos = 0, size_t nNum = 1);
143
144 };
145
146}
147#endif // TABLE_HPP
148
This data container is a copy- efficient table to interchange data between Kernel and GUI.
Definition: table.hpp:87
bool insertLines(size_t nPos=0, size_t nNum=1)
This member function inserts lines at the desired position.
Definition: table.cpp:683
TableColumn::ColumnType getColumnType(size_t j) const
Returns the type of the selected column.
Definition: table.cpp:621
void setName(const std::string &_sName)
Setter function for the table name.
Definition: table.cpp:186
void Clear()
This member function cleares the contents of this table.
Definition: table.cpp:149
bool appendLines(size_t nNum=1)
This member function appends lines.
Definition: table.cpp:704
TableMetaData m_meta
Definition: table.hpp:91
bool isEmpty() const
Return, whether the table is empty.
Definition: table.cpp:668
std::string getValueAsString(size_t i, size_t j) const
Getter function for the value of the selected cell. The value is converted into a string.
Definition: table.cpp:580
bool deleteCols(size_t nPos=0, size_t nNum=1)
This member function delets columns at the desired position.
Definition: table.cpp:780
void setComment(const std::string &_comment)
Setter function for the table comment.
Definition: table.cpp:213
void setValue(size_t i, size_t j, const mu::value_type &_dValue)
This member function sets the data to the table. It will resize the table automatically,...
Definition: table.cpp:291
~Table()
Destructor.
Definition: table.cpp:85
void setSize(size_t i, size_t j)
This member function simply redirects the control to setMinSize().
Definition: table.cpp:165
void setColumn(size_t j, TableColumn *column)
Assigns a whole column to the internal array.
Definition: table.cpp:357
std::string getCleanHeadPart(size_t i, size_t part=0) const
Getter function for the selected part of the selected column's headline. Underscores and masked headl...
Definition: table.cpp:507
bool insertCols(size_t nPos=0, size_t nNum=1)
This member function inserts columns at the desired position.
Definition: table.cpp:748
Table()
Default constructor.
Definition: table.cpp:32
std::string getHead(size_t i) const
Getter function for the selected column's headline.
Definition: table.cpp:469
std::string getName() const
Getter function for the table name.
Definition: table.cpp:390
int getHeadCount() const
Getter function for the needed number of headlines (depending on the number of linebreaks found in th...
Definition: table.cpp:429
void setHead(size_t i, const std::string &_sHead)
Setter function for the selected column headline. Will create missing headlines automatically.
Definition: table.cpp:229
Table & operator=(Table _table)
Move assignment operator.
Definition: table.cpp:98
TableColumnArray & getTableData()
Definition: table.hpp:130
size_t getCols() const
Get the number of columns.
Definition: table.cpp:656
TableMetaData getMetaData() const
Getter function for the table meta data.
Definition: table.cpp:403
void setValueAsString(size_t i, size_t j, const std::string &_sValue)
This member function sets the data, which is passed as a string, to the table. If the data is not a n...
Definition: table.cpp:312
std::string getComment() const
Getter function for the table comment.
Definition: table.cpp:415
std::string sTableName
Definition: table.hpp:90
bool isNumerical(const std::string &sValue) const
This member function is a simple helper function to determine, whether a passed value may be parsed i...
Definition: table.cpp:136
void setMetaData(const TableMetaData &meta)
Setter function for the table meta data.
Definition: table.cpp:200
size_t getLines() const
Get the number of lines.
Definition: table.cpp:636
mu::value_type getValue(size_t i, size_t j) const
Getter function for the value of the selected cell.
Definition: table.cpp:561
bool setColumnType(size_t j, TableColumn::ColumnType _type)
Tries to change the column type of the selected column.
Definition: table.cpp:375
bool deleteLines(size_t nPos=0, size_t nNum=1)
This member function deletes lines at the desired position.
Definition: table.cpp:725
void setMinSize(size_t i, size_t j)
This member function prepares a table with the minimal size of the selected lines and columns.
Definition: table.cpp:119
bool appendCols(size_t nNum=1)
This member function appends columns.
Definition: table.cpp:763
void setHeadPart(size_t i, size_t part, const std::string &_sHead)
Setter function for the selected column headline and the selected part of the headline (split using l...
Definition: table.cpp:254
TableColumn * getColumn(size_t j) const
Returns a copy of the internal column array or a nullptr, if the column does not exist or is empty.
Definition: table.cpp:604
TableColumnArray vTableData
Definition: table.hpp:89
std::string getCleanHead(size_t i) const
Getter function for the selected column's headline. Underscores and masked headlines are replaced on-...
Definition: table.cpp:487
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
Encapsulating structure to gather all table meta data information.
Definition: table.hpp:32
TableMetaData melt(const TableMetaData &meta)
Definition: table.hpp:53
__time64_t lastSavedTime
Definition: table.hpp:35
std::string source
Definition: table.hpp:34
std::string comment
Definition: table.hpp:33
Abstract table column, which allows using it to compose the data table in each Memory instance.
Definition: tablecolumn.hpp:34
std::vector< TblColPtr > TableColumnArray
This typedef represents the actual table, which is implemented using a std::vector.