8#include <bsoncxx/builder/basic/array.hpp>
15EntityResultTableData<T>::EntityResultTableData(
ot::UID ID, EntityBase *parent, EntityObserver *obs, ModelState *ms, ClassFactoryHandler* factory,
const std::string &owner) :
16 EntityBase(
ID, parent, obs, ms, factory, owner)
22EntityResultTableData<T>::~EntityResultTableData()
27bool EntityResultTableData<T>::getEntityBox(
double &xmin,
double &xmax,
double &ymin,
double &ymax,
double &zmin,
double &zmax)
33void EntityResultTableData<T>::StoreToDataBase(
void)
35 EntityBase::StoreToDataBase();
39void EntityResultTableData<T>::AddStorageData(bsoncxx::builder::basic::document &storage)
42 EntityBase::AddStorageData(storage);
44 auto headerArray = bsoncxx::builder::basic::array();
46 for (
auto &text : header)
48 headerArray.append(text);
51 auto dataArray = bsoncxx::builder::basic::array();
53 for (
unsigned int iRow = 0; iRow < getNumberOfRows(); iRow++)
55 for (
unsigned int iCol = 0; iCol < getNumberOfColumns(); iCol++)
57 dataArray.append(getValue(iRow, iCol));
64 bsoncxx::builder::basic::kvp(
"NumberColums", (
int) getNumberOfColumns()),
65 bsoncxx::builder::basic::kvp(
"NumberRows", (
int) getNumberOfRows()),
66 bsoncxx::builder::basic::kvp(
"Header", headerArray),
67 bsoncxx::builder::basic::kvp(
"Data", dataArray)
72void EntityResultTableData<T>::readSpecificDataFromDataBase(bsoncxx::document::view &doc_view, std::map<ot::UID, EntityBase *> &entityMap)
75 EntityBase::readSpecificDataFromDataBase(doc_view, entityMap);
82 unsigned int numberCols = doc_view[
"NumberColums"].get_int32();
83 unsigned int numberRows = doc_view[
"NumberRows"].get_int32();
85 setNumberOfColumns(numberCols);
86 setNumberOfRows(numberRows);
88 auto headerArray = doc_view[
"Header"].get_array().value;
89 auto dataArray = doc_view[
"Data"].get_array().value;
91 unsigned int iCol = 0;
92 for (
const auto& text : headerArray)
94 setHeaderText(iCol,
text.get_utf8().value.data());
98 unsigned int iRow = 0;
101 for (
const auto& data : dataArray)
107 if (iCol == numberCols)
118void EntityResultTableData<T>::removeChild(EntityBase *child)
120 EntityBase::removeChild(child);
124void EntityResultTableData<T>::setNumberOfColumns(uint64_t cols)
126 header.resize(cols,
"");
128 for (
unsigned int iRow = 0; iRow < getNumberOfRows(); iRow++)
130 data[iRow].resize(cols);
135void EntityResultTableData<T>::setNumberOfRows(uint64_t rows)
137 uint64_t oldRows = getNumberOfRows();
143 for (uint64_t iRow = oldRows; iRow < rows; iRow++)
145 data[iRow].resize(getNumberOfColumns());
151void EntityResultTableData<T>::setHeaderText(
unsigned int col,
const std::string &text)
153 assert(col < getNumberOfColumns());
158void EntityResultTableData<T>::setValue(
unsigned int row,
unsigned int col, T
value)
160 assert(row < getNumberOfRows());
161 assert(col < getNumberOfColumns());
163 data[row][col] =
value;
166void EntityResultTableData<T>::setRow(
unsigned int row, std::vector<T>&
value)
168 if (row >= getNumberOfRows())
170 throw std::runtime_error(
"Row index out of range.");
172 if (
value.size() > getNumberOfColumns())
174 throw std::runtime_error(
"Vector has too many entries for the set number of columns.");
178 for (i; i <
value.size(); i++)
180 data[row][i] =
value[i];
182 while (i < getNumberOfColumns())
190void EntityResultTableData<T>::setColumn(
unsigned int column, std::vector<T>&
value)
192 if (column >= getNumberOfColumns())
194 throw std::runtime_error(
"Column index out of range.");
196 if (
value.size() >= getNumberOfRows())
198 throw std::runtime_error(
"Vector has too many entries for the set number of rows.");
201 for (
int i = 0; i <
value.size(); i++)
203 data[i][column] =
value[i];
209uint64_t EntityResultTableData<T>::getNumberOfRows(
void)
211 return (data.size());
215uint64_t EntityResultTableData<T>::getNumberOfColumns(
void)
217 return (header.size());
221std::string EntityResultTableData<T>::getHeaderText(
unsigned int col)
223 assert(col < getNumberOfColumns());
228T EntityResultTableData<T>::getValue(
unsigned int row,
unsigned int col)
230 assert(row < getNumberOfRows());
231 assert(col < getNumberOfColumns());
233 return data[row][col];
bsoncxx::types::value value
Definition DocumentManager.h:16
Template for getting a type name. Some type names are not system independent, hence the need to creat...
Definition BsonArrayTypeGetterWrapper.h:9
static std::string getTypeName()
Definition TemplateTypeName.hpp:9
UICORE_API_EXPORT QString text(UID _checkBoxUID)
Definition uiAPI.cpp:387
int ID
The ID datatype used for items.
Definition globalDataTypes.h:68
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27