Commit d23e244c authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

minor changes

parent 593cac6c
...@@ -133,11 +133,11 @@ private: ...@@ -133,11 +133,11 @@ private:
// TODO BindNative other QVariant-supported types? // TODO BindNative other QVariant-supported types?
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// QBind<_,QVariant&> example support for the fixed set of QVariantBuilder's BindNative types + other convenient types // QBind<_,QVariant&> example support for the fixed set of IBind's BindNative types + other convenient types
template<class TResult> template<>
struct QBind<TResult, QVariant> { struct QBind<Cursor, QVariant> {
static TResult bind(Val<TResult>&& v, QVariant&& src) { static Cursor bind(Val<Cursor>&& v, QVariant&& src) {
if (v->mode()==Write) { if (v->mode()==Write) {
if (src.type()==QVariant::List ) return v.bind(src.value<QVariantList>()); // TODO QSequentialIterable ? if (src.type()==QVariant::List ) return v.bind(src.value<QVariantList>()); // TODO QSequentialIterable ?
if (src.type()==QVariant::Map ) return v.bind(src.value<QVariantMap >()); // TODO QAssociativeIterable ? if (src.type()==QVariant::Map ) return v.bind(src.value<QVariantMap >()); // TODO QAssociativeIterable ?
...@@ -161,7 +161,7 @@ struct QBind<TResult, QVariant> { ...@@ -161,7 +161,7 @@ struct QBind<TResult, QVariant> {
} }
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); }
} }
static TResult bind(Val<TResult>&& v, QVariant& dst) { static Cursor bind(Val<Cursor>&& v, QVariant& dst) {
if (v->mode()==Write) { if (v->mode()==Write) {
return bind(std::move(v),std::move(dst)); return bind(std::move(v),std::move(dst));
} }
...@@ -169,11 +169,11 @@ struct QBind<TResult, QVariant> { ...@@ -169,11 +169,11 @@ struct QBind<TResult, QVariant> {
} }
}; };
//template<class TResult> //template<>
//struct QBind<TResult, QVariant&, IsReader<TResult>> { static TResult bind(Val<TResult>&& v, QVariant& dst) { //struct QBind<Cursor, QVariant&, IsReader<Cursor>> { static Cursor bind(Val<Cursor>&& v, QVariant& dst) {
// TResult r; // Cursor r;
// { // {
// QScopedChoice<Val<TResult>> choice(src); // QScopedChoice<Val<Cursor>> choice(src);
// QVariantList a; if ((r = src.bind(a))) { dst = a ; return r; } // NB We cannot try QStringList before QVariantList as it will always work with our logical model... // QVariantList a; if ((r = src.bind(a))) { dst = a ; return r; } // NB We cannot try QStringList before QVariantList as it will always work with our logical model...
// QVariantMap o; if ((r = src.bind(o))) { dst = o ; return r; } // QVariantMap o; if ((r = src.bind(o))) { dst = o ; return r; }
// bool b; if ((r = src.bind(b))) { dst = QVariant(b); return r; } // bool b; if ((r = src.bind(b))) { dst = QVariant(b); return r; }
......
...@@ -95,6 +95,15 @@ QDataStream &operator<<(QDataStream &out, const Person &p) ...@@ -95,6 +95,15 @@ QDataStream &operator<<(QDataStream &out, const Person &p)
<< p.phones << p.phones
<< p.comments; << p.comments;
} }
QDataStream &operator>>(QDataStream &in, Person &p)
{
return in
>> p.firstName >> p.lastName // sequence is implicit
>> p.height
>> p.age
>> p.phones
>> p.comments;
}
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// IBind basic implementation example // IBind basic implementation example
...@@ -128,11 +137,11 @@ private: ...@@ -128,11 +137,11 @@ private:
#include <QtCore/qbuffer.h> #include <QtCore/qbuffer.h>
class Text : public TextWriter class Text
{ {
QBuffer result; QBuffer result;
public: public:
template<typename T> Text(T&& t) : TextWriter(&result) { result.open(QIODevice::WriteOnly); bind(std::forward<T>(t)); } template<typename T> Text(T&& t) { result.open(QIODevice::WriteOnly); TextWriter(&result).bind(std::forward<T>(t)); }
operator QUtf8String() const { return result.buffer(); } operator QUtf8String() const { return result.buffer(); }
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment