diff --git a/tests/QBind/QCbor_impl.h b/tests/QBind/QCbor_impl.h index 06d468e05960f1245efa54b11c766137aa50ad5d..e6ed22e326a5e3c93105179cf81af8c5867df133 100644 --- a/tests/QBind/QCbor_impl.h +++ b/tests/QBind/QCbor_impl.h @@ -108,9 +108,9 @@ public: QCborWriter(QByteArray* io) : io(io) { Q_ASSERT(io); } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool _isOk() const noexcept { return io; } @@ -185,9 +185,9 @@ public: QCborBuilder(QCborValue* v) : cbor(v) { Q_ASSERT(v); } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool trySequence(quint32* =nullptr) { levels.push(Step( )); return true; } bool tryRecord (quint32* =nullptr) { levels.push(Step(qBindExpectedItem)); return true; } @@ -199,7 +199,7 @@ protected: bool tryBind ( float&& d) { set(QCborValue(double(d))); return true; } bool tryBind ( double&& d) { set(QCborValue( d )); return true; } bool tryBind ( quint64&& n) { if (std::numeric_limits::max() T bind(QVal&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; + struct Error { QIdentifierLiteral error; QAsciiData path; QValueStatus zap(QValue&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; QVector errors; QAsciiData currentPath() { @@ -246,9 +246,9 @@ public: } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } _reportError(qBindExpectedSequence); return false; } bool tryRecord (quint32* =nullptr) { if (current().isMap ()) { steps.push(Step()); return true; } _reportError(qBindExpectedRecord ); return false; } @@ -290,12 +290,12 @@ class QCborReader : public QAbstractValueReader, public QCborStreamReader public: QCborReader(QIODevice* io) : QCborStreamReader(io), cacheVisitor(&cachedValue) { Q_ASSERT(io); } - struct Error { QIdentifierLiteral error; qint64 index; QCborError cborError; template T bind(QVal&& value) { QByteArray utf8(error.utf8()); utf8.append(' ').append(QByteArray::number(index)); return value.bind(utf8.constData()); } }; + struct Error { QIdentifierLiteral error; qint64 index; QCborError cborError; QValueStatus zap(QValue&& value) { QByteArray utf8(error.utf8()); utf8.append(' ').append(QByteArray::number(index)); return value.bind(utf8.constData()); } }; QVector errors; // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); } @@ -475,7 +475,7 @@ private: template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QCborValue&& j) { + static QValueStatus zap(QValue&& v, QCborValue&& j) { if (v->mode()==Write) { if (j.isMap ()) return v.bind(j.toMap ()); if (j.isArray ()) return v.bind(j.toArray ()); @@ -488,9 +488,9 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QCborValue& j) { + static QValueStatus zap(QValue&& v, QCborValue& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { QValueStatus r; @@ -515,7 +515,7 @@ struct QTransmogrifier { template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QCborArray&& j) { + static QValueStatus zap(QValue&& v, QCborArray&& j) { if (v->mode()==Write) { quint32 size=quint32(j.size()); auto s(v.sequence(&size)); @@ -526,13 +526,13 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QCborArray& j) { + static QValueStatus zap(QValue&& v, QCborArray& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { auto s(v.sequence()); - QVal> i; + QVal i; while ((i = s.item())) { QCborValue json; if ((s = i.bind(json))) @@ -546,7 +546,7 @@ struct QTransmogrifier { template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QCborMap&& j) { + static QValueStatus zap(QValue&& v, QCborMap&& j) { if (v->mode()==Write) { quint32 size=quint32(j.size()); auto r(v.record(&size)); @@ -561,13 +561,13 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QCborMap& j) { + static QValueStatus zap(QValue&& v, QCborMap& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { auto s(v.record()); - QIdentifier k; QVal> i; + QIdentifier k; QVal i; while ((i = s.item(k))) { QCborValue json; if ((s = i.bind(json))) diff --git a/tests/QBind/QData_impl.h b/tests/QBind/QData_impl.h index 5d4210cfe3896cba435ef6f45c08bf0908bad9a9..401e53c91666131a3eb2bc91bf8e71429cf75a48 100644 --- a/tests/QBind/QData_impl.h +++ b/tests/QBind/QData_impl.h @@ -47,7 +47,7 @@ #include "QValue.h" // ////////////////////////////////////////////////////////////////////////// -// QTransmogrifier support +// QDataStream* support // TODO Use QByteArray directly @@ -62,10 +62,10 @@ public: QValueMode mode() const noexcept { return QValueMode::Write; } // Shortcuts - QValue value ( ) { return QValueStatus(this).value(); } - QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + QValue value ( ) { return QValueStatus(this).value(); } + QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } - template QValueStatus bind(T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + template QValueStatus zap(T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: friend class QValueStatus; bool trySequence(quint32* s=nullptr) { if (s) *io << *s; return true; } diff --git a/tests/QBind/QJson_impl.h b/tests/QBind/QJson_impl.h index a50eb5cdc4d5f9b41cff05768b9302c9fdeddde0..e2502f92d3b1113bb629109f9ee069e04367d455 100644 --- a/tests/QBind/QJson_impl.h +++ b/tests/QBind/QJson_impl.h @@ -60,9 +60,9 @@ public: void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: friend class QJsonReader; //!< Calls methods below for out-of-order cachedItems bool trySequence(quint32* s=nullptr) { Q_UNUSED(s); steps.push(Step( )); return true; } @@ -104,7 +104,7 @@ public: QJsonVisitor(const QJsonValue* v) : json(v) { Q_ASSERT(v); } void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); errors.resize(0); } - struct Error { QIdentifierLiteral error; QAsciiData path; template T bind(QVal&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; + struct Error { QIdentifierLiteral error; QAsciiData path; QValueStatus zap(QValue&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; QVector errors; QAsciiData currentPath() { @@ -117,9 +117,9 @@ public: } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } _reportError(qBindExpectedSequence); return false; } @@ -163,9 +163,9 @@ public: ~QJsonWriter() { while (!levels.isEmpty()) write(levels.takeLast().end); } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: template friend class QModelWriter; @@ -245,13 +245,13 @@ public: } struct Step { int index; const char* end; QMap cachedItems; Step(int i=-1, const char* e=nullptr) : index(i), end(e) {} }; - struct Error { QIdentifierLiteral error; int line; int column; int index; template T bind(QVal&& value) { QByteArray u(error.utf8()); u.append(' ').append(QByteArray::number(line)).append(':').append(QByteArray::number(column)); return value.bind(QUtf8Data(u)); } }; + struct Error { QIdentifierLiteral error; int line; int column; int index; QValueStatus zap(QValue&& value) { QByteArray u(error.utf8()); u.append(' ').append(QByteArray::number(line)).append(':').append(QByteArray::number(column)); return value.bind(QUtf8Data(u)); } }; QVector errors; // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: enum CachedNumber : quint8 { None=0, Integer, FloatingPoint }; @@ -513,7 +513,7 @@ private: }; // ////////////////////////////////////////////////////////////////////////// -// QTransmogrifier support +// QJson* support #include #include @@ -521,7 +521,7 @@ private: template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QJsonValue&& j) { + static QValueStatus zap(QValue&& v, QJsonValue&& j) { if (v->mode()==Write) { if (j.isObject()) return v.bind(j.toObject()); if (j.isArray ()) return v.bind(j.toArray ()); @@ -532,9 +532,9 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QJsonValue& j) { + static QValueStatus zap(QValue&& v, QJsonValue& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { QValueStatus r; @@ -557,7 +557,7 @@ struct QTransmogrifier { template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QJsonArray&& j) { + static QValueStatus zap(QValue&& v, QJsonArray&& j) { if (v->mode()==Write) { quint32 size=quint32(j.size()); auto s(v.sequence(&size)); @@ -568,13 +568,13 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QJsonArray& j) { + static QValueStatus zap(QValue&& v, QJsonArray& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { auto s(v.sequence()); - QVal> i; + QVal i; while ((i = s.item())) { QJsonValue json; if ((s = i.bind(json))) @@ -588,7 +588,7 @@ struct QTransmogrifier { template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QJsonObject&& j) { + static QValueStatus zap(QValue&& v, QJsonObject&& j) { if (v->mode()==Write) { quint32 size=quint32(j.size()); auto s(v.record(&size)); @@ -600,13 +600,13 @@ struct QTransmogrifier { } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QJsonObject& j) { + static QValueStatus zap(QValue&& v, QJsonObject& j) { if (v->mode()==Write) { - return bind(std::move(v),std::move(j)); + return zap(std::move(v),std::move(j)); } else if (v->mode()==Read) { auto s(v.record()); - QIdentifier k; QVal> i; + QIdentifier k; QVal i; while ((i = s.item(k))) { QJsonValue json; if ((s = i.bind(json))) diff --git a/tests/QBind/QModel_impl.h b/tests/QBind/QModel_impl.h index 56277803ff57b828db915d7ce3752ca2b9dd5332..a369558927cd6132eb87a142299b19ccf596f5aa 100644 --- a/tests/QBind/QModel_impl.h +++ b/tests/QBind/QModel_impl.h @@ -51,7 +51,7 @@ #include "QJson_impl.h" // ////////////////////////////////////////////////////////////////////////// -// QTransmogrifier support +// Q*Model support class QModelBind : public QAbstractValue { @@ -59,7 +59,7 @@ class QModelBind : public QAbstractValue public: QModelBind(QAbstractItemModel* m, bool rowFirst=true) : m(m), rowFirst(rowFirst) { Q_ASSERT(m); } - struct Error { QIdentifierLiteral error; QModelIndex index; template T bind(QVal&& value) { QByteArray u(error.utf8()); for (; index.isValid(); index=index.parent()) u.append('/').append(QByteArray::number(index.row())).append(',').append(QByteArray::number(index.column())); return value.bind(QUtf8Data(u)); } }; + struct Error { QIdentifierLiteral error; QModelIndex index; QValueStatus zap(QValue&& value) { QByteArray u(error.utf8()); for (; index.isValid(); index=index.parent()) u.append('/').append(QByteArray::number(index.row())).append(',').append(QByteArray::number(index.column())); return value.bind(QUtf8Data(u)); } }; QVector errors; QValue value() { return QValueStatus(this).value(); } diff --git a/tests/QBind/QSettings_impl.h b/tests/QBind/QSettings_impl.h index 879a53b5af03a672a42f9634981de1d1d3ea62b4..933819053c78e26e83e2e6e955bbbff65ba4817b 100644 --- a/tests/QBind/QSettings_impl.h +++ b/tests/QBind/QSettings_impl.h @@ -56,7 +56,7 @@ public: // Shortcuts /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: bool tryBind ( quint8&& t) { settings->setValue(key(), int(t) ); return true; } @@ -96,7 +96,7 @@ public: Q_ENABLE_MOVE(QSettingsReader, std::swap(isChoice, o.isChoice); ) QSettingsReader(QSettings* s) : settings(s) { Q_ASSERT(s); levels.push(Level(qBindExpectedItem)); } - struct Error { QIdentifierLiteral error; QAsciiData path; template T bind(QVal&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; + struct Error { QIdentifierLiteral error; QAsciiData path; QValueStatus zap(QValue&& value) { return value.bind(QUtf8Data(error.utf8()+' '+path.utf8())); } }; QVector errors; QAsciiData currentPath() { diff --git a/tests/QBind/QValue.h b/tests/QBind/QValue.h index 482e31cba65ac079dd0ae318386db6ba1d5fe513..08560ea66b8a4ce47ad7df5035dbfb7e990a8a12 100644 --- a/tests/QBind/QValue.h +++ b/tests/QBind/QValue.h @@ -109,7 +109,7 @@ extern QIdentifierLiteral qmColor; // ////////////////////////////////////////////////////////////////////////// // QTransmogrifier -enum QValueMode { Invalid=0, Read=1, Write=2 }; //!< Specifies QTransmogrifier::bind traversal and processing (the design would support other QValueMode like Append or Diff) +enum QValueMode { Invalid=0, Read=1, Write=2 }; //!< Specifies QTransmogrifier::zap traversal and processing (the design would support other QValueMode like Append or Diff) struct BindGeneric {}; struct BindNative {}; @@ -318,8 +318,8 @@ using QRecord = QRec; #include #ifndef NO_COMPILER_RTTI_OR_EXCEPTIONS -template using QValFunction = QValueStatus (*)(T &,QValue &&) ; -template using QSeqFunction = QSequence (*)(Ts&,QSequence&&) ; +template using QValFunction = QValueStatus(*)(T &,QValue &&) ; +template using QSeqFunction = QSequence (*)(Ts&,QSequence&&) ; #endif /**/ using QValLambda = std::function; /**/ using QSeqLambda = std::function; @@ -338,16 +338,16 @@ public: QSeq sequence(quint32* s=nullptr) { return outer->trySequence (s) ? QSeq(std::move(outer)) : QSeq(); } QRec record (quint32* s=nullptr) { return outer->tryRecord (s) ? QRec(std::move(outer)) : QRec(); } - /**/ T_ null ( ) { return outer->tryNull ( ) ? std::move(outer) : T_ (); } - /**/ T_ any ( ) { return outer->tryAny ( ) ? std::move(outer) : T_ (); } + /**/ T_ null ( ) { return outer->tryNull ( ) ? std::move(outer) : T_ (); } + /**/ T_ any ( ) { return outer->tryAny ( ) ? std::move(outer) : T_ (); } - /**/ T_ bind ( const char* u) { return outer->tryBind(QUtf8DataView(u)) ? std::move(outer) : T_ (); } - /**/ T_ bind ( QUtf8DataView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); } - /**/ T_ bind ( QAsciiDataView a) { return outer->tryBind (a) ? std::move(outer) : T_ (); } - /**/ T_ bind ( QLatin1String l) { return outer->tryBind (l) ? std::move(outer) : T_ (); } - /**/ T_ bind ( QStringView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); } + /**/ T_ bind ( const char* u) { return outer->tryBind(QUtf8DataView(u)) ? std::move(outer) : T_ (); } + /**/ T_ bind ( QUtf8DataView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); } + /**/ T_ bind ( QAsciiDataView a) { return outer->tryBind (a) ? std::move(outer) : T_ (); } + /**/ T_ bind ( QLatin1String l) { return outer->tryBind (l) ? std::move(outer) : T_ (); } + /**/ T_ bind ( QStringView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); } - template T_ bind ( T&& t) { return outer->tryBind(std::forward(t )) ? std::move(outer) : T_(); } + template T_ bind ( T&& t) { return outer->tryBind(std::forward (t )) ? std::move(outer) : T_(); } template T_ bind (T& t, T&& defaultT) { return outer->tryBind(QDefaultValue{t,defaultT}) ? std::move(outer) : T_(); } // Custom bind support @@ -412,8 +412,8 @@ public: template QSeq operator<<(T&& t) { return item().bind(std::forward(t)); } // stream compatible private: template friend struct QTransmogrifier; - QValue unsafeItem() noexcept { return outer->tryItem() ? QValue(outer->_unsafeCopy()) : QValue(); } - QSeq unsafeThis() noexcept { return QSeq(outer->_unsafeCopy()) ; } + QValue unsafeItem() noexcept { return outer->tryItem() ? QValue(outer->_unsafeCopy()) : QValue(); } + QSequence unsafeThis() noexcept { return QSequence(outer->_unsafeCopy()) ; } T_ outer = T_(); }; @@ -472,13 +472,13 @@ private: //! template struct QTransmogrifier { - static QValueStatus bind(QValue&& value, T& t) { return t .bind(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,T&) - static QValueStatus bind(QValue&& value,const T& t) { return const_cast(t).bind(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,const T&) - static QValueStatus bind(QValue&& value, T&& t) { return t .bind(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,T&&) + static QValueStatus zap(QValue&& value, T& t) { return t .zap(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,T&) + static QValueStatus zap(QValue&& value,const T& t) { return const_cast(t).zap(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,const T&) + static QValueStatus zap(QValue&& value, T&& t) { return t .zap(std::move(value)); } // In case of error, define a T::bind(QValue) method or external QTransmogrifier::bind(QValue,T&&) }; template -bool QValueStatus::tryBind(BindGeneric, T&& t) { return QTransmogrifier>::bind(QValue(_unsafeCopy()),std::forward(t)); } +bool QValueStatus::tryBind(BindGeneric, T&& t) { return QTransmogrifier>::zap(QValue(_unsafeCopy()),std::forward(t)); } class QScopedChoice //!< for accurate error reporting { @@ -804,7 +804,7 @@ public: template QBindable(T& t) : f(/*captured T ref */[&t] (QValue&& v) { return v.bind(t); } ) {} template QBindable(T&& t) : f(/*captured T copy*/[ t] (QValue&& v) { return v.bind(t); } ) {} - QValueStatus bind(QValue&& v) { return f(std::move(v)); } + QValueStatus zap(QValue&& v) { return f(std::move(v)); } }; // ////////////////////////////////////////////////////////////////////////// @@ -921,11 +921,11 @@ QValueStatus qbind(QValue&& v, T* t) { } //! Default bind(QValue&&) based on static QMetaObject reflection -#define QBIND_GADGET_WITH_METAOBJECT(Class) QValueStatus bind(QValue&& v) { return qbind(std::move(v), this); } +#define QBIND_GADGET_WITH_METAOBJECT(Class) QValueStatus zap(QValue&& v) { return qbind(std::move(v), this); } template struct QTransmogrifier> { - static QValueStatus bind(QValue&& v, QDefaultValue&& t) { + static QValueStatus zap(QValue&& v, QDefaultValue&& t) { if (v->mode()==Read) { v->setChoice(true); auto r=v.null(); @@ -937,17 +937,17 @@ struct QTransmogrifier> { } return v.bind(t.value); } - static QValueStatus bind(QValue&& v, QDefaultValue& t) { + static QValueStatus zap(QValue&& v, QDefaultValue& t) { return bind(std::move(v),std::move(t)); } }; template struct QTransmogrifier::value && std::is_integral::value && !std::is_same::value>::type> { - static QValueStatus bind(QValue&& v, T&& t) { + static QValueStatus zap(QValue&& v, T&& t) { return v.bind(quint64(t)); } - static QValueStatus bind(QValue&& v, T& t) { + static QValueStatus zap(QValue&& v, T& t) { if (v->mode()==Write) { return bind(std::move(v),T(t)); } @@ -959,10 +959,10 @@ struct QTransmogrifier::value && }; template struct QTransmogrifier::value && std::is_integral::value && !std::is_same::value>::type> { - static QValueStatus bind(QValue&& v, T&& t) { + static QValueStatus zap(QValue&& v, T&& t) { return v.bind(qint64(t)); } - static QValueStatus bind(QValue&& v, T& t) { + static QValueStatus zap(QValue&& v, T& t) { if (v->mode()==Write) { return bind(std::move(v),T(t)); } @@ -977,7 +977,7 @@ struct QTransmogrifier::value && st template struct QTransmogrifier { - static QValueStatus bind(QValue&& v, T(& ts)[Size]) { + static QValueStatus zap(QValue&& v, T(& ts)[Size]) { if (v->mode()==Write) { quint32 size=Size; auto s(v.sequence(&size)); @@ -988,7 +988,7 @@ struct QTransmogrifier { } else if (v->mode()==Read) { auto s(v.sequence()); - QVal> i; unsigned j=0; + QVal i; unsigned j=0; while ((i = s.item())) { if (j== Size) { i->reportError(qBindIgnoredItem); @@ -1008,7 +1008,7 @@ struct QTransmogrifier { template struct QTransmogrifier> { - static QValueStatus bind(QValue&& v, QVector&& ts) { + static QValueStatus zap(QValue&& v, QVector&& ts) { if (v->mode()==Write) { quint32 size=ts.size(); auto s(v.sequence(&size)); @@ -1019,7 +1019,7 @@ struct QTransmogrifier> { } else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QVector& ts) { + static QValueStatus zap(QValue&& v, QVector& ts) { if (v->mode()==Write) { quint32 size=ts.size(); auto s(v.sequence(&size)); @@ -1030,7 +1030,7 @@ struct QTransmogrifier> { } else if (v->mode()==Read) { auto s(v.sequence()); - QVal> i; int it = 0; + QVal i; int it = 0; while ((i = s.item())) { if (it==ts.size()) { T t; @@ -1054,7 +1054,7 @@ struct QTransmogrifier> { template struct QTransmogrifier> { - static QValueStatus bind(QValue&& v, QList&& ts) { + static QValueStatus zap(QValue&& v, QList&& ts) { if (v->mode()==Write) { quint32 size=quint32(ts.size()); auto s(v.sequence(&size)); @@ -1065,7 +1065,7 @@ struct QTransmogrifier> { } else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QList& ts) { + static QValueStatus zap(QValue&& v, QList& ts) { if (v->mode()==Write) { quint32 size=quint32(ts.size()); auto s(v.sequence(&size)); @@ -1076,7 +1076,7 @@ struct QTransmogrifier> { } else if (v->mode()==Read) { auto s(v.sequence()); - QVal> i; int it = 0; + QVal i; int it = 0; while ((i = s.item())) { if (it==ts.size()) { T t; @@ -1101,7 +1101,7 @@ struct QTransmogrifier> { template struct QTransmogrifier> { - static QValueStatus bind(QValue&& v, QMap&& ts) { + static QValueStatus zap(QValue&& v, QMap&& ts) { if (v->mode()==Write) { quint32 size=quint32(ts.size()); auto s(v.record(&size)); @@ -1112,7 +1112,7 @@ struct QTransmogrifier> { } else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } - static QValueStatus bind(QValue&& v, QMap& ts) { + static QValueStatus zap(QValue&& v, QMap& ts) { if (v->mode()==Write) { quint32 size=quint32(ts.size()); auto s(v.record(&size)); @@ -1123,7 +1123,7 @@ struct QTransmogrifier> { } else if (v->mode()==Read) { auto r(v.record()); - QIdentifier name; QVal> i; + QIdentifier name; QVal i; while ((i = r.item(name))) { T value(ts[name.latin1()]); if ((r = i.bind(value))) @@ -1140,32 +1140,32 @@ struct QTransmogrifier> { template<> //!< \remark Enumerating types where BindSupport<_> = BindNative with C++11 seems hard, so we just handle the set of default QAbstractValue BindNative types struct QTransmogrifier { - static QValueStatus bind(QValue&& src, QValue&& dst) { + static QValueStatus zap(QValue&& src, QValue&& dst) { if (src->mode()==Read && dst->mode()==Write) { QValueStatus srcRes; { QScopedChoice choice(src); - QSeq srcSeq; QSeq dstSeq; + QSequence srcSeq; QSequence dstSeq; if ( (srcSeq = src.sequence())) { /**/ dstSeq = dst.sequence(); QValue srcVal; QValue dstVal; - while((srcVal = srcSeq.unsafeItem())) { // using item()'s QVal would cause an infinite compiler loop to generate corresponding QTransmogrifier>,_> functions + while((srcVal = srcSeq.unsafeItem())) { // using item()'s QVal>,_> functions dstVal = dstSeq.unsafeItem(); - srcSeq = QSeq(srcVal.bind(std::move(dstVal))); + srcSeq = QSequence(srcVal.bind(std::move(dstVal))); } /**/ dstSeq.out(); return srcSeq.out(); } - QRec srcRec; QRec dstRec; + QRecord srcRec; QRecord dstRec; if ( (srcRec = src.record())) { /**/ dstRec = dst.record(); QIdentifier srcKey; QValue srcVal; QValue dstVal; while((srcVal = srcRec.unsafeItem(srcKey))) { dstVal = dstRec.unsafeItem(srcKey); - srcRec = QRec(srcVal.bind(std::move(dstVal))); + srcRec = QRecord(srcVal.bind(std::move(dstVal))); } /**/ dstRec.out(); @@ -1196,10 +1196,10 @@ struct QTransmogrifier { srcRes.reportError("ExpectedSequenceRecordNullTextBytesBooleanIntegerDecimal"); return srcRes; } - else if (src->mode()==Write && dst->mode()==Read) { return bind(std::move(dst),std::move(src)); } // To return reader's QValueStatus instead of writer's QValueStatus since it should contain more information (mismatches, etc.) + else if (src->mode()==Write && dst->mode()==Read) { return zap(std::move(dst),std::move(src)); } // To return reader's QValueStatus instead of writer's QValueStatus since it should contain more information (mismatches, etc.) else { Q_ASSERT_X(!src || !dst, Q_FUNC_INFO, "Unsupported src->mode() and dst->mode()"); return src.null(); } } - static QValueStatus bind(QValue&& v1, QValue& v2) { - return bind(std::move(v1),std::move(v2)); + static QValueStatus zap(QValue&& v1, QValue& v2) { + return zap(std::move(v1),std::move(v2)); } }; diff --git a/tests/QBind/QVariant_impl.h b/tests/QBind/QVariant_impl.h index 142a263fe271c858c4a7cb7355bce1bf96d1bada..855c0fae3b1bd50886e75bbf59fcb4337c4a319a 100644 --- a/tests/QBind/QVariant_impl.h +++ b/tests/QBind/QVariant_impl.h @@ -56,9 +56,9 @@ public: void reset(QVariant* v) { variant=v; Q_ASSERT(v); levels.resize(0); } // Shortcuts - /**/ QValue value ( ) { return QValueStatus(this).value(); } - /**/ QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } - template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } + /**/ QValue value ( ) { return QValueStatus(this).value(); } + /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + template QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: // TODO Support _meta to be able to cache and restitute all metadata as well as data+datatype diff --git a/tests/QBind/QXml_impl.h b/tests/QBind/QXml_impl.h index 9316f66fa845de2b9c21448cc0fdc2dbeac756e7..f4c19786a083f069def8a1eae29cbcd62cf9d4d3 100644 --- a/tests/QBind/QXml_impl.h +++ b/tests/QBind/QXml_impl.h @@ -67,8 +67,8 @@ public: QValueMode mode() const noexcept { return QValueMode::Write; } // Shortcuts - QValue value ( ) { return QValueStatus(this).value(); } - QSeq sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } + QValue value ( ) { return QValueStatus(this).value(); } + QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } template QValueStatus bind(T&& t) { return QValueStatus(this).value().bind(std::forward(t)); } protected: diff --git a/tests/QBind/README.md b/tests/QBind/README.md index 0069c8d22d12539d300a8d26218e945103c2aeaa..aab10cec3c302bb673bdbe13a6738bb002ef584d 100644 --- a/tests/QBind/README.md +++ b/tests/QBind/README.md @@ -99,7 +99,7 @@ struct Person { QString firstName, lastName; double height; int age; QVector phones; QString comments; QList children; - QValueStatus bind(QValue&& value) { // works with value->mode()==Read as well as Write + QValueStatus zap(QValue&& value) { // works with value->mode()==Read as well as Write return value .record("Person") // aggregates a usually small number of named items in any order (Person is an optional meta-name for the record that may be ignored) .sequence("names") // aggregates any number of items in a fixed order, just to illustrate a basic mapping between struct Person and a more general data schema @@ -247,12 +247,12 @@ Each specialization must implement at least the bind() method for lvalue referen references to support temporaries, and for const lvalue reference to efficiently support copyable types. ```cpp template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QColor&& c) { QColor copy(c); return bind(std::move(v),copy); } // supports writing temporaries and const QColor& - static QValueStatus bind(QValue&& v, QColor& c) { + static QValueStatus zap(QValue&& v, QColor&& c) { QColor copy(c); return bind(std::move(v),copy); } // supports writing temporaries and const QColor& + static QValueStatus zap(QValue&& v, QColor& c) { if (!c.isValid()) { return v.null(); } - QRec r = v.record(); + QRecord r = v.record(); switch(c.spec()) { case QColor::Spec::Rgb : r = r.sequence("RGB" ).bind(c.red ()).bind(c.green ()).bind(c.blue ()); break; case QColor::Spec::Hsl : r = r.sequence("HSL" ).bind(c.hslHue()).bind(c.hslSaturation()).bind(c.lightness()); break; @@ -332,7 +332,7 @@ By convention: One can also customize binds using ad-hoc std::function like [flatten](tests/QTransmogrifier/main.cpp#L996) or lambda below (mimicking Python list comprehensions): ```cpp QStandardItemModel custom; -QModelWriter<>(&custom).sequence().with([&](QSeq&& s) { +QModelWriter<>(&custom).sequence().with([&](QSequence&& s) { for (auto&& person : persons) { s = s.record() .item("first name") diff --git a/tests/QBind/main.cpp b/tests/QBind/main.cpp index 4f5ad8ead3280fe5a05b2f220c50514933e9652f..08cabfa9c3736b1f4a89e6d04587486b2fa2003b 100644 --- a/tests/QBind/main.cpp +++ b/tests/QBind/main.cpp @@ -84,7 +84,7 @@ struct Person { int id; QString firstName, lastName; double height; int age; QVector phones; QString comments; QList children; - QValueStatus bind(QValue&& value) { // works with value->mode()==Read as well as Write + QValueStatus zap(QValue&& value) { // works with value->mode()==Read as well as Write auto r = value.record("Person"); auto s = r.sequence("names"); s = s.bind(firstName); @@ -136,7 +136,7 @@ struct PersonsView { QList& persons; - QValueStatus bind(QValue&& value) { + QValueStatus zap(QValue&& value) { return value .meta(qmChildren,"children") .meta(qmColumns ,"names,height,age,phones,comments") // to optimize multi-dimensional data formats @@ -150,7 +150,7 @@ struct PersonsTable { QList& persons; PersonsTable(QList& ps) : persons(ps) {} - QValueStatus bind(QValue&& v) { + QValueStatus zap(QValue&& v) { if (v->mode()==Read) { ids.clear(); orphans.clear(); @@ -181,7 +181,7 @@ private: QMap ids; QMap> orphans; - QSeq bind(Person& p, QSeq&& s) { + QSequence bind(Person& p, QSequence&& s) { if (s->mode()==Read) { int parentId=0; double height_ft=0.; @@ -235,7 +235,7 @@ private: } } - QSeq flatten(QList& ps, QSeq&& s) { + QSequence flatten(QList& ps, QSequence&& s) { for (auto&& p : ps) { s = bind(p, std::move(s)); } @@ -251,11 +251,11 @@ private: //! QTransmogrifier with special support for QDataStream compatibility using meta() template<> struct QTransmogrifier { - static QValueStatus bind(QValue&& v, QColor&& c) { + static QValueStatus zap(QValue&& v, QColor&& c) { QColor copy(c); - return bind(std::move(v),copy); + return zap(std::move(v),copy); } - static QValueStatus bind(QValue&& v, QColor& c) { + static QValueStatus zap(QValue&& v, QColor& c) { if (!c.isValid()) { return v.null(); } @@ -271,7 +271,7 @@ struct QTransmogrifier { return v.sequence().bind(quint8(c.spec())).bind(quint16(c64.alpha())).bind(quint16(c64.red())).bind(quint16(c64.green())).bind(quint16(c64.blue())).bind(quint16(0)); // TODO pad } } while (!n.isNull()); - QRec r = v.record(); + QRecord r = v.record(); switch(c.spec()) { case QColor::Spec::Rgb : r = r.sequence("RGB" ).bind(quint8(c.red ())).bind(quint8(c.green ())).bind(quint8(c.blue ())) .out(); break; case QColor::Spec::Hsl : r = r.sequence("HSL" ).bind(qint16(c.hslHue())).bind(quint8(c.hslSaturation())).bind(quint8(c.lightness())) .out(); break; @@ -299,8 +299,8 @@ public: TextWriter(QByteArray* utf8) : utf8(utf8) { Q_ASSERT(utf8); } // Shortcuts - template QSeq operator<<(T&& t) { return QValueStatus(this).value().sequence().item().bind(std::forward(t)); } - template QValueStatus bind (T&& t) { return QValueStatus(this).value() .bind(std::forward(t)); } + template QSequence operator<<(T&& t) { return QValueStatus(this).value().sequence().item().bind(std::forward(t)); } + template QValueStatus bind (T&& t) { return QValueStatus(this).value() .bind(std::forward(t)); } protected: bool trySequence(quint32* =nullptr) { if (0append("["); return true; } bool tryRecord (quint32* =nullptr) { if (0append("["); return true; } @@ -1094,7 +1094,7 @@ int main(int argc, char *argv[]) return (fclose(samples)==0) &/*anyway*/ (fclose(results)==0); } -QSeq flatten(QList& ps, QSeq&& s) { +QSequence flatten(QList& ps, QSequence&& s) { for (auto&& p : ps) { // Iterating on ps only works for Write but flatten cannot be Read/Write anyway s = s .record() @@ -1191,7 +1191,7 @@ void doGuiExample() { // Using sequence comprehensions similar to Python (that does not work by default for Read/Write) { new QStandardItemModel(&dlg), new QTableView(&dlg), "sequence().with([&](...){for...", [&](QValue&& v) { - return v.sequence().with([&](QSeq&& s) { + return v.sequence().with([&](QSequence&& s) { for (auto&& person : persons) { // Read would require looping while !s.item() s = s // To keep working with the active QValueStatus .record()