4#include "include/database/database_version.h"
11namespace ehm_dal::container {
12template<
typename T_ItemCountType>
13concept Number = std::is_integral<T_ItemCountType>::value;
18template<
typename T_DataType, Number T_ItemCountType = qu
int8>
22 Container(
const quint32 size = 0,
const bool is_sortable =
true);
27 void addRows(
const qint32 count);
28 inline void push_back(T_DataType &item) { data_.push_back(std::move(item)); }
29 inline void push_back(T_DataType *item) { data_.push_back(std::move(*item)); }
32 void clear() { data_.clear(); }
33 void erase(
const qint32 first_index_to_delete,
const qint32 last_index_to_delete);
37 void read(QDataStream &in,
39 const T_ItemCountType count);
42 void write(QDataStream &out,
44 const T_ItemCountType count);
47 inline bool isSortable()
const {
return is_sortable_; }
48 inline qint32 rowCount()
const {
return static_cast<qint32
>(data_.size()); }
49 inline T_ItemCountType size()
const {
return static_cast<T_ItemCountType
>(data_.size()); }
52 T_DataType *item(
const T_ItemCountType pos);
53 const T_DataType *itemConst(
const T_ItemCountType pos)
const;
59 inline std::vector<T_DataType> *data() {
return &data_; }
63 std::vector<T_DataType> data_;
66 const bool is_sortable_;
74template<
typename T_DataType, Number T_ItemCountType>
77 , is_sortable_(is_sortable)
81template<
typename T_DataType, Number T_ItemCountType>
82Container<T_DataType, T_ItemCountType>::Container(
const Container &obj)
83 : data_(std::move(obj.data_))
84 , is_sortable_(obj.isSortable())
95template<
typename T_DataType, Number T_ItemCountType>
96void Container<T_DataType, T_ItemCountType>::addRows(
const qint32 count)
98 for (
auto i = 0; i < count; ++i) {
100 data_.push_back(std::move(new_item));
109template<
typename T_DataType, Number T_ItemCountType>
110void Container<T_DataType, T_ItemCountType>::erase(
const qint32 first_index_to_delete,
111 const qint32 last_index_to_delete)
113 data_.erase(data_.begin() + first_index_to_delete, data_.begin() + last_index_to_delete);
121template<
typename T_DataType, Number T_ItemCountType>
122void Container<T_DataType, T_ItemCountType>::read(QDataStream &in,
125 T_ItemCountType count{0};
126 in.readRawData(
reinterpret_cast<char *
>(&count),
sizeof(T_ItemCountType));
128 read(in, version, count);
132template<
typename T_DataType, Number T_ItemCountType>
133void Container<T_DataType, T_ItemCountType>::read(QDataStream &in,
135 const T_ItemCountType count)
137 for (T_ItemCountType i = 0; i < count; ++i) {
139 item.read(in, version);
140 data_.emplace_back(item);
144 std::sort(std::execution::par, this->data_.begin(), this->data_.end());
148template<
typename T_DataType, Number T_ItemCountType>
149void Container<T_DataType, T_ItemCountType>::readInto(QDataStream &in,
152 for (
auto &itr : data_)
153 itr.read(in, version);
156 std::sort(std::execution::par, this->data_.begin(), this->data_.end());
160template<
typename T_DataType, Number T_ItemCountType>
161void Container<T_DataType, T_ItemCountType>::write(QDataStream &out,
165 out.writeRawData(
reinterpret_cast<char *
>(&count),
sizeof(T_ItemCountType));
167 write(out, version, count);
171template<
typename T_DataType, Number T_ItemCountType>
172void Container<T_DataType, T_ItemCountType>::write(QDataStream &out,
174 const T_ItemCountType count)
177 std::sort(std::execution::par, this->data_.begin(), this->data_.end());
179 for (T_ItemCountType i = 0; i < count; ++i)
180 this->data_[i].write(out, version);
188template<
typename T_DataType, Number T_ItemCountType>
189T_DataType *Container<T_DataType, T_ItemCountType>::item(
const T_ItemCountType pos)
191 if (pos < size() && pos >= 0)
198template<
typename T_DataType, Number T_ItemCountType>
199const T_DataType *Container<T_DataType, T_ItemCountType>::itemConst(
const T_ItemCountType pos)
const
201 if (pos < rowCount() && pos >= 0)
212template<
typename T_DataType, Number T_ItemCountType>
213Container<T_DataType, T_ItemCountType> &Container<T_DataType, T_ItemCountType>::operator=(
The Container class is a representation of vector in the EHM database which is written to the databas...
Definition: container.h:20
The DatabaseVersion class represents the database version number.
Definition: database_version.h:12
Definition: container.h:13