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
7e92d744
Commit
7e92d744
authored
Mar 13, 2019
by
EXT Arnaud Clère
Browse files
Added bind(T& t, T&& defaultT) to fluent interface
parent
2d4ed500
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/QBind/QBind_impl.h
View file @
7e92d744
...
...
@@ -168,9 +168,7 @@ public:
/**/
T_
null
(
)
{
return
outer
->
_null
(
)
?
std
::
move
(
outer
)
:
T_
();
}
/**/
T_
any
(
)
{
return
outer
->
_any
(
)
?
std
::
move
(
outer
)
:
T_
();
}
template
<
typename
T
>
T_
bind
(
T
&&
t
)
{
return
outer
->
_bind
(
std
::
forward
<
T
>
(
t
))
?
std
::
move
(
outer
)
:
T_
();
}
template
<
typename
T
>
T_
bind
(
T
&
t
,
T
&&
defaultT
)
{
return
outer
->
_bind
(
QBindDefault
<
T
>
{
t
,
defaultT
})
?
std
::
move
(
outer
)
:
T_
();
}
// TODO ? Add bind with default T specialised for Reader/Writer
template
<
typename
T
>
T_
bind
(
T
&
t
,
T
&&
defaultT
)
{
return
outer
->
_bind
(
QBindDefault
<
T
>
{
t
,
defaultT
})
?
std
::
move
(
outer
)
:
T_
();
}
// Literal metadata support
/**/
Val
<
T_
>
meta
(
QMetaData
&&
m
)
{
auto
v
=
m
;
return
meta
(
v
);
}
...
...
@@ -206,6 +204,7 @@ public:
/**/
Seq
<
T_
>
null
(
)
{
return
item
().
null
(
);
}
/**/
Seq
<
T_
>
any
(
)
{
return
item
().
any
(
);
}
template
<
typename
T
>
Seq
<
T_
>
bind
(
T
&&
t
)
{
return
item
().
bind
(
std
::
forward
<
T
>
(
t
));
}
template
<
typename
T
>
Rec
<
T_
>
bind
(
T
&
t
,
T
&&
defaultT
)
{
return
item
().
bind
(
t
,
std
::
forward
<
T
>
(
defaultT
));
}
private:
template
<
typename
T
,
class
TResult
,
typename
TEnabledIf
>
friend
struct
QBind
;
Val
<
TResult
>
unsafeItem
()
noexcept
{
return
outer
->
_item
()
?
Val
<
TResult
>
(
outer
.
_unsafeCopy
())
:
Val
<
TResult
>
();
}
...
...
@@ -239,6 +238,7 @@ public:
/**/
Rec
<
Rec
<
T_
>>
record
(
QName
n
,
quint32
*
s
=
nullptr
)
{
return
item
(
n
).
record
(
s
);
}
/**/
Rec
<
T_
>
null
(
QName
n
)
{
return
item
(
n
).
null
(
);
}
template
<
typename
T
>
Rec
<
T_
>
bind
(
QName
n
,
T
&&
t
)
{
return
item
(
n
).
bind
(
std
::
forward
<
T
>
(
t
));
}
template
<
typename
T
>
Rec
<
T_
>
bind
(
QName
n
,
T
&
t
,
T
&&
defaultT
)
{
return
item
(
n
).
bind
(
t
,
std
::
forward
<
T
>
(
defaultT
));
}
private:
template
<
typename
T
,
class
TResult
,
typename
TEnabledIf
>
friend
struct
QBind
;
Val
<
TResult
>
unsafeItem
(
QUtf8String
&
n
)
noexcept
{
return
outer
->
_item
(
n
)
?
Val
<
TResult
>
(
outer
.
_unsafeCopy
())
:
Val
<
TResult
>
();
}
...
...
tests/QBind/main.cpp
View file @
7e92d744
...
...
@@ -75,7 +75,7 @@ struct Person
.
bind
(
lastName
)
.
out
()
.
bind
(
"height"
,
height
)
.
bind
(
"age"
,
age
)
// TODO item("age").bind(age
,-1)
to
read null() as -1
.
bind
(
"age"
,
age
,
-
1
)
//
read
s
null() as -1
.
bind
(
"phones"
,
phones
)
// recursive calls to QBind will take care of that part
.
bind
(
"comments"
,
comments
)
;
// automagically closes all opened structures
...
...
@@ -490,7 +490,7 @@ int main(int argc, char *argv[])
{
QBuffer
json
;
json
.
open
(
QIODevice
::
ReadOnly
);
json
.
buffer
()
=
"_{
\"
names
\"
: [ _
\"
John
\"
_,
\"
Doe
\"
] ,
\"
height
\"
:_1.75 , null,
\"
phones
\"
:[
\"
+44 1234567
\"
,
\"
+44 2345678
\"
],
\"\"
:
\"
superfluous item
\"
_} "
;
json
.
buffer
()
=
"_{
\"
names
\"
: [ _
\"
John
\"
_,
\"
Doe
\"
] ,
\"
height
\"
:_1.75 ,
\"
age
\"
:
null,
\"
phones
\"
:[
\"
+44 1234567
\"
,
\"
+44 2345678
\"
],
\"\"
:
\"
superfluous item
\"
_} "
;
QJsonValue
v
;
#if QT_VERSION>=QT_VERSION_CHECK(5,12,0)
QCborValue
c
;
...
...
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