Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MODMED
modmedLog
Commits
593cac6c
Commit
593cac6c
authored
Mar 10, 2019
by
EXT Arnaud Clère
Browse files
WIP test specific QBind<Cur<QDataWriter>,_>
parent
ce292776
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/QBind/QBind_impl.h
View file @
593cac6c
...
...
@@ -813,16 +813,16 @@ struct QBind<TResult, QMap<QString,T>> {
#include <QtGui/qcolor.h>
template
<
class
TResult
>
//= Cursor
struct
QBind
<
TResult
,
QColor
>
{
static
TResult
bind
(
Val
<
TResult
>&&
v
,
QColor
&&
src
)
{
template
<
>
struct
QBind
<
Cursor
,
QColor
>
{
static
Cursor
bind
(
Val
<
Cursor
>&&
v
,
QColor
&&
src
)
{
return
v
.
record
()
.
bind
(
"A"
,
src
.
alpha
())
.
bind
(
"R"
,
src
.
red
())
.
bind
(
"G"
,
src
.
green
())
.
bind
(
"B"
,
src
.
blue
());
}
static
TResult
bind
(
Val
<
TResult
>&&
v
,
QColor
&
src
)
{
static
Cursor
bind
(
Val
<
Cursor
>&&
v
,
QColor
&
src
)
{
return
bind
(
std
::
move
(
v
),
QColor
(
src
));
}
};
...
...
tests/QBind/QData_impl.h
View file @
593cac6c
...
...
@@ -49,6 +49,8 @@
// //////////////////////////////////////////////////////////////////////////
// QBind<QDataStream*,T> support using operator<< for all registered types and containers, or GenericBind with DataTag
static
const
char
*
qmDataStreamVersion
=
"qmDataStreamVersion"
;
//! \warning As with QDataStream, QDataWriter and QDataReader must:
//! - bind the same C++ root data type (when unknown, QVariant can be used on both side)
//! - use the same set of registered QMetaTypeIds with operator<< defined
...
...
@@ -57,7 +59,7 @@ class QDataWriter : public IWriter // allows runtime flexibility without BindNat
{
Q_DISABLE_COPY
(
QDataWriter
)
public:
QDataWriter
(
QDataStream
*
io
)
:
io
(
io
)
{
Q_ASSERT
(
io
);
}
QDataWriter
(
QDataStream
*
io
)
:
io
(
io
)
{
Q_ASSERT
(
io
);
version
=
QString
::
number
(
io
->
version
());
}
BindMode
mode
()
const
noexcept
{
return
BindMode
::
Write
;
}
...
...
@@ -83,8 +85,11 @@ protected:
bool
_item
(
)
{
return
true
;
}
bool
_item
(
QUtf8String
&
)
{
return
true
;
}
// record keys are implicit, maps should be serialized as a sequence of records with key and value items
bool
_item
(
QName
)
{
return
true
;
}
// for QBaseWriter
void
_meta
(
QMetaData
&
m
)
{
m
[
qmDataStreamVersion
]
=
version
;
}
private:
QDataStream
*
io
;
QString
version
;
};
template
<
typename
T
>
struct
BindSupport
<
QDataWriter
,
T
>
:
BindSupport
<
IBind
,
T
>
{};
// TODO BindNative other types that should bind specifically for compatibility with QDataStream
...
...
@@ -94,4 +99,30 @@ template<> struct BindSupport<QDataWriter, QColor> : BindNative {};
// Providing a general QDataReader may be deceiving because the QDataStream structure is implicit:
// A reader is assumed to specify exactly what to read based on the stream origin and version
// QVariant could be used though for parts which type are not known in advance
// QVariant could be used though for parts which type are not known in advance such as the exact type of a message coming from a socket
// And QDataStream version can be
// ///////////////////////////////////////////////////////////////////////////
// QBind<Cur<QDataWriter>,T> types that should bind specifically for compatibility with QDataStream
template
<
>
struct
QBind
<
Cur
<
QDataWriter
>
,
QColor
>
{
static
Cur
<
QDataWriter
>
bind
(
Val
<
Cur
<
QDataWriter
>>&&
v
,
QColor
&&
src
)
{
QMetaData
m
;
v
=
v
.
meta
(
m
);
if
(
m
[
qmDataStreamVersion
].
toInt
()
<
7
)
{
v
->
reportError
(
"Unsupported QDataStream.version()"
);
return
v
.
null
();
}
return
v
.
sequence
()
.
bind
(
quint8
(
src
.
spec
()))
.
bind
(
quint16
(
src
.
alpha
()))
.
bind
(
quint16
(
src
.
red
()))
.
bind
(
quint16
(
src
.
green
()))
.
bind
(
quint16
(
src
.
blue
()));
}
static
Cur
<
QDataWriter
>
bind
(
Val
<
Cur
<
QDataWriter
>>&&
v
,
QColor
&
src
)
{
return
bind
(
std
::
move
(
v
),
QColor
(
src
));
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment