Heart
1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
streambase.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018-2025 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 STREAMBASE_H
9
#define STREAMBASE_H
10
11
#include <QByteArray>
12
#include <QDataStream>
13
#include <QVariantMap>
14
#include "heart_global.h"
15
#include "validableobject.h"
16
#include <type_traits>
17
18
class
QDataStream;
19
namespace
QH
{
20
21
class
Package
;
22
28
class
HEARTSHARED_EXPORT
StreamBase
:
public
QuasarAppUtils::iVO
29
{
30
public
:
31
StreamBase
();
32
virtual
~StreamBase
();
33
38
bool
fromBytes
(
const
QByteArray &dataz);
39
44
QByteArray
toBytes
()
const
;
45
52
bool
fromBase64
(
const
QString &data);
53
59
bool
fromBase64
(
const
QByteArray &data);
60
65
QByteArray
toBase64
()
const
;
66
73
HEARTSHARED_EXPORT
friend
QDataStream& operator<< (QDataStream& stream,
const
StreamBase
& obj);
74
81
HEARTSHARED_EXPORT
friend
QDataStream& operator>> (QDataStream& stream,
StreamBase
& obj);
82
90
template
<
class
T>
91
T&
copy
(
const
StreamBase
& right) {
92
static_assert
(std::is_base_of_v<StreamBase, T>,
93
"The argument of the copy method must be base type of the StreamBase class"
);
94
95
fromBytes
(right.
toBytes
());
96
return
static_cast<
T&
>
(*this);
97
}
98
99
template
<
class
T>
106
bool
compare
(
const
T& right) {
107
static_assert
(std::is_base_of_v<StreamBase, T>,
108
"The argument of the compare method must be base type of the StreamBase class"
);
109
110
if
(
static_cast<
unsigned
int
>
(
typeid
(T).hash_code()) !=
typeId
()) {
111
return
false
;
112
}
113
114
return
toBytes
() == right.toBytes();
115
}
116
117
118
protected
:
119
125
virtual
int
parsingVersion()
const
;
126
143
virtual
QDataStream&
fromStream
(QDataStream& stream) = 0;
144
160
virtual
QDataStream&
toStream
(QDataStream& stream)
const
= 0;
161
166
virtual
unsigned
int
typeId
()
const
;
167
168
};
169
}
170
#endif
// STREAMBASE_H
QH::Package
The Package struct. This is base structure for transporting data by network between QH nodes....
Definition
package.h:23
QH::StreamBase::typeId
virtual unsigned int typeId() const
typeId This method return id of type.
Definition
streambase.cpp:68
QH::StreamBase::toBytes
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
Definition
streambase.cpp:38
QH::StreamBase::fromStream
virtual QDataStream & fromStream(QDataStream &stream)=0
fromStream This method should be read all bytes from the stream object and full the current object.
QH::StreamBase::toStream
virtual QDataStream & toStream(QDataStream &stream) const =0
fromStream This method should be write all members of the current object to the stream object.
QH::StreamBase::compare
bool compare(const T &right)
compare This method compare array signatures of this and right objects.
Definition
streambase.h:106
QH::StreamBase::fromBase64
bool fromBase64(const QString &data)
fromBase64 This method provide initialization of object from the base64 string.
Definition
streambase.cpp:52
QH::StreamBase::StreamBase
StreamBase()
QH::StreamBase::~StreamBase
virtual ~StreamBase()
QH::StreamBase::toBase64
QByteArray toBase64() const
toBase64 This method convert a current object to the base64 string.
Definition
streambase.cpp:60
QH::StreamBase::copy
T & copy(const StreamBase &right)
copy This is base copy method for all StreamBase structures. Default implementation it is copy from b...
Definition
streambase.h:91
QH::StreamBase::fromBytes
bool fromBytes(const QByteArray &dataz)
fromBytes This method provide initialization of object from byte array.
Definition
streambase.cpp:21
QH
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition
heart.cpp:13
src
public
streambase.h
Generated by
1.18.0