Heart
1.4.984.b4712811
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
streambase.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018-2027 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
#include "
streambase.h
"
9
10
#include <QDataStream>
11
#include <QIODevice>
12
#include <QSharedPointer>
13
14
namespace
QH
{
15
16
17
StreamBase::StreamBase
() =
default
;
18
19
StreamBase::~StreamBase
() =
default
;
20
21
bool
StreamBase::fromBytes
(
const
QByteArray &data) {
22
if
(data.isEmpty())
23
return
false
;
24
25
QDataStream stream(data);
26
27
if
(
parsingVersion
()) {
28
stream.setVersion(
parsingVersion
());
29
}
30
31
fromStream
(stream);
32
33
Q_ASSERT_X(isValid(), __FUNCTION__,
34
QString(
"Parsing error detected, check your parsing chain %0"
).
35
arg(
typeid
(*this).name()).toLatin1());
36
return
true
;
37
}
38
39
QByteArray
StreamBase::toBytes
()
const
{
40
QByteArray res;
41
QDataStream stream(&res, QIODevice::WriteOnly);
42
43
if
(
parsingVersion
()) {
44
stream.setVersion(
parsingVersion
());
45
}
46
47
Q_ASSERT_X(isValid(), __FUNCTION__,
48
QString(
"Parsing error detected, check your parsing chain %0"
).
49
arg(
typeid
(*this).name()).toLatin1());
50
51
toStream
(stream);
52
return
res;
53
}
54
55
bool
StreamBase::fromBase64
(
const
QString &data) {
56
return
fromBase64
(data.toLatin1());
57
}
58
59
bool
StreamBase::fromBase64
(
const
QByteArray &data) {
60
return
fromBytes
(QByteArray::fromBase64(data, QByteArray::Base64UrlEncoding));
61
}
62
63
QByteArray
StreamBase::toBase64
()
const
{
64
return
toBytes
().toBase64(QByteArray::Base64UrlEncoding);
65
}
66
67
int
StreamBase::parsingVersion
()
const
{
68
return
0;
69
}
70
71
unsigned
int
StreamBase::typeId
()
const
{
72
return
typeid
(
this
).hash_code();
73
}
74
75
QDataStream &
operator<<
(QDataStream &stream,
const
StreamBase
&obj) {
76
77
Q_ASSERT_X(obj.isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
78
79
return
(&obj)->toStream(stream);
80
}
81
82
QDataStream &
operator>>
(QDataStream &stream,
StreamBase
&obj) {
83
(&obj)->
fromStream
(stream);
84
Q_ASSERT_X(obj.isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
85
return
stream;
86
}
87
88
}
QH::StreamBase::typeId
virtual unsigned int typeId() const
typeId This method return id of type.
Definition
streambase.cpp:71
QH::StreamBase::parsingVersion
virtual int parsingVersion() const
parsingVersion this method return parsing version of Qt. By Default is 0 (last available parsing)....
Definition
streambase.cpp:67
QH::StreamBase::toBytes
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
Definition
streambase.cpp:39
QH::StreamBase::operator>>
HEARTSHARED_EXPORT friend QDataStream & operator>>(QDataStream &stream, StreamBase &obj)
This is wrapper over fromStream. For see more information see toStream method.
Definition
streambase.cpp:82
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::fromBase64
bool fromBase64(const QString &data)
fromBase64 This method provide initialization of object from the base64 string.
Definition
streambase.cpp:55
QH::StreamBase::operator<<
HEARTSHARED_EXPORT friend QDataStream & operator<<(QDataStream &stream, const StreamBase &obj)
This is wrapper over toStream.
Definition
streambase.cpp:75
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:63
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
streambase.h
src
public
streambase.cpp
Generated by
1.18.0