Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
dbobjectsrequestwithStream.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef DBOBJECTSREQUESTWITHSTREAM_H
9#define DBOBJECTSREQUESTWITHSTREAM_H
10
11#include "dbobjectsrequest.h"
12
13#include <QDataStream>
14
15
16namespace QH {
17namespace PKG {
18
25template <class T>
27{
28public:
29
35
44 const QString& conditions = "" ):
45 DBObjectsRequest<T> (table, conditions) { };
46
47protected:
48
49 QDataStream &fromStream(QDataStream &stream) override {
51
52 int size = 0;
53 stream >> size;
54
55 for (int i = 0; i < size; ++i) {
56 auto ptr = QSharedPointer<T>::create();
57
58 stream >> *ptr;
59
60 _data.push_back(ptr);
61 }
62
63 return stream;
64 };
65
66 QDataStream &toStream(QDataStream &stream) const override {
68
69 stream << static_cast<int>(_data.size());
70
71 for (auto object: _data) {
72 stream << *object;
73 }
74
75 return stream;
76 };
77
78};
79
80}
81}
82#endif // DBOBJECTSREQUESTWITHSTREAM_H
QString table() const override
table This method should be return name of the database table that should be contains objects with th...
QDataStream & toStream(QDataStream &stream) const override
fromStream This method should be write all members of the current object to the stream object.
Definition dbobject.cpp:259
QDataStream & fromStream(QDataStream &stream) override
fromStream This method should be read all bytes from the stream object and full the current object.
Definition dbobject.cpp:251
The DBObjectsRequestWithStream class is template class some as DBObjectsRequest but with implementati...
QDataStream & toStream(QDataStream &stream) const override
fromStream This method should be write all members of the current object to the stream object.
DBObjectsRequestWithStream(const Package &pkkg)
DBObjectsRequest This is default constructor for parsing packages.
QDataStream & fromStream(QDataStream &stream) override
fromStream This method should be read all bytes from the stream object and full the current object.
DBObjectsRequestWithStream(const QString &table, const QString &conditions="")
DBObjectsRequest This contsrucor create a object with request the array of T objects.
The DBObjectsRequest class is template class for get array of TEMPLATE Objects from database.
QList< QSharedPointer< T > > _data
The Package struct. This is base structure for transporting data by network between QH nodes....
Definition package.h:23
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13