Commit a2c2f6b7 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

Renamed as in Qt proposal

parent bd379ac7
...@@ -108,9 +108,9 @@ public: ...@@ -108,9 +108,9 @@ public:
QCborWriter(QByteArray* io) : io(io) { Q_ASSERT(io); } QCborWriter(QByteArray* io) : io(io) { Q_ASSERT(io); }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool _isOk() const noexcept { return io; } bool _isOk() const noexcept { return io; }
...@@ -185,9 +185,9 @@ public: ...@@ -185,9 +185,9 @@ public:
QCborBuilder(QCborValue* v) : cbor(v) { Q_ASSERT(v); } QCborBuilder(QCborValue* v) : cbor(v) { Q_ASSERT(v); }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool trySequence(quint32* =nullptr) { levels.push(Step( )); return true; } bool trySequence(quint32* =nullptr) { levels.push(Step( )); return true; }
bool tryRecord (quint32* =nullptr) { levels.push(Step(qBindExpectedItem)); return true; } bool tryRecord (quint32* =nullptr) { levels.push(Step(qBindExpectedItem)); return true; }
...@@ -199,7 +199,7 @@ protected: ...@@ -199,7 +199,7 @@ protected:
bool tryBind ( float&& d) { set(QCborValue(double(d))); return true; } bool tryBind ( float&& d) { set(QCborValue(double(d))); return true; }
bool tryBind ( double&& d) { set(QCborValue( d )); return true; } bool tryBind ( double&& d) { set(QCborValue( d )); return true; }
bool tryBind ( quint64&& n) { if (std::numeric_limits<qint64>::max()<n) { _reportError(qBindExpectedSmallerNumber); return false; } bool tryBind ( quint64&& n) { if (std::numeric_limits<qint64>::max()<n) { _reportError(qBindExpectedSmallerNumber); return false; }
set(QCborValue(qint64(n))); return true; } set(QCborValue(qint64(n))); return true; }
bool tryBind ( qint64&& n) { set(QCborValue( n )); return true; } bool tryBind ( qint64&& n) { set(QCborValue( n )); return true; }
bool tryBind ( QByteArray&& s) { set(QCborValue( s )); return true; } bool tryBind ( QByteArray&& s) { set(QCborValue( s )); return true; }
...@@ -233,7 +233,7 @@ public: ...@@ -233,7 +233,7 @@ public:
QCborVisitor(QCborValue* v) : cbor(v) { Q_ASSERT(v); } QCborVisitor(QCborValue* v) : cbor(v) { Q_ASSERT(v); }
void reset(QCborValue* v) { cbor=v; Q_ASSERT(v); steps.resize(0); errors.resize(0); } void reset(QCborValue* v) { cbor=v; Q_ASSERT(v); steps.resize(0); errors.resize(0); }
struct Error { QIdentifierLiteral error; QAsciiData path; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
QAsciiData currentPath() { QAsciiData currentPath() {
...@@ -246,9 +246,9 @@ public: ...@@ -246,9 +246,9 @@ public:
} }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } _reportError(qBindExpectedSequence); return false; } 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; } 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 ...@@ -290,12 +290,12 @@ class QCborReader : public QAbstractValueReader, public QCborStreamReader
public: public:
QCborReader(QIODevice* io) : QCborStreamReader(io), cacheVisitor(&cachedValue) { Q_ASSERT(io); } QCborReader(QIODevice* io) : QCborStreamReader(io), cacheVisitor(&cachedValue) { Q_ASSERT(io); }
struct Error { QIdentifierLiteral error; qint64 index; QCborError cborError; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); } bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); }
...@@ -475,7 +475,7 @@ private: ...@@ -475,7 +475,7 @@ private:
template<> template<>
struct QTransmogrifier<QCborValue> { struct QTransmogrifier<QCborValue> {
static QValueStatus bind(QValue&& v, QCborValue&& j) { static QValueStatus zap(QValue&& v, QCborValue&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
if (j.isMap ()) return v.bind(j.toMap ()); if (j.isMap ()) return v.bind(j.toMap ());
if (j.isArray ()) return v.bind(j.toArray ()); if (j.isArray ()) return v.bind(j.toArray ());
...@@ -488,9 +488,9 @@ struct QTransmogrifier<QCborValue> { ...@@ -488,9 +488,9 @@ struct QTransmogrifier<QCborValue> {
} }
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 QValueStatus bind(QValue&& v, QCborValue& j) { static QValueStatus zap(QValue&& v, QCborValue& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
QValueStatus r; QValueStatus r;
...@@ -515,7 +515,7 @@ struct QTransmogrifier<QCborValue> { ...@@ -515,7 +515,7 @@ struct QTransmogrifier<QCborValue> {
template<> template<>
struct QTransmogrifier<QCborArray> { struct QTransmogrifier<QCborArray> {
static QValueStatus bind(QValue&& v, QCborArray&& j) { static QValueStatus zap(QValue&& v, QCborArray&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
quint32 size=quint32(j.size()); quint32 size=quint32(j.size());
auto s(v.sequence(&size)); auto s(v.sequence(&size));
...@@ -526,13 +526,13 @@ struct QTransmogrifier<QCborArray> { ...@@ -526,13 +526,13 @@ struct QTransmogrifier<QCborArray> {
} }
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 QValueStatus bind(QValue&& v, QCborArray& j) { static QValueStatus zap(QValue&& v, QCborArray& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
auto s(v.sequence()); auto s(v.sequence());
QVal<QSeq<QValueStatus>> i; QVal<QSequence> i;
while ((i = s.item())) { while ((i = s.item())) {
QCborValue json; QCborValue json;
if ((s = i.bind(json))) if ((s = i.bind(json)))
...@@ -546,7 +546,7 @@ struct QTransmogrifier<QCborArray> { ...@@ -546,7 +546,7 @@ struct QTransmogrifier<QCborArray> {
template<> template<>
struct QTransmogrifier<QCborMap> { struct QTransmogrifier<QCborMap> {
static QValueStatus bind(QValue&& v, QCborMap&& j) { static QValueStatus zap(QValue&& v, QCborMap&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
quint32 size=quint32(j.size()); quint32 size=quint32(j.size());
auto r(v.record(&size)); auto r(v.record(&size));
...@@ -561,13 +561,13 @@ struct QTransmogrifier<QCborMap> { ...@@ -561,13 +561,13 @@ struct QTransmogrifier<QCborMap> {
} }
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 QValueStatus bind(QValue&& v, QCborMap& j) { static QValueStatus zap(QValue&& v, QCborMap& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
auto s(v.record()); auto s(v.record());
QIdentifier k; QVal<QRec<QValueStatus>> i; QIdentifier k; QVal<QRecord> i;
while ((i = s.item(k))) { while ((i = s.item(k))) {
QCborValue json; QCborValue json;
if ((s = i.bind(json))) if ((s = i.bind(json)))
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
#include "QValue.h" #include "QValue.h"
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<T,QDataStream*> support // QDataStream* support
// TODO Use QByteArray directly // TODO Use QByteArray directly
...@@ -62,10 +62,10 @@ public: ...@@ -62,10 +62,10 @@ public:
QValueMode mode() const noexcept { return QValueMode::Write; } QValueMode mode() const noexcept { return QValueMode::Write; }
// Shortcuts // Shortcuts
QValue value ( ) { return QValueStatus(this).value(); } QValue value ( ) { return QValueStatus(this).value(); }
QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind(T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus zap(T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
friend class QValueStatus; friend class QValueStatus;
bool trySequence(quint32* s=nullptr) { if (s) *io << *s; return true; } bool trySequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
......
...@@ -60,9 +60,9 @@ public: ...@@ -60,9 +60,9 @@ public:
void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); } void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
friend class QJsonReader; //!< Calls methods below for out-of-order cachedItems friend class QJsonReader; //!< Calls methods below for out-of-order cachedItems
bool trySequence(quint32* s=nullptr) { Q_UNUSED(s); steps.push(Step( )); return true; } bool trySequence(quint32* s=nullptr) { Q_UNUSED(s); steps.push(Step( )); return true; }
...@@ -104,7 +104,7 @@ public: ...@@ -104,7 +104,7 @@ public:
QJsonVisitor(const QJsonValue* v) : json(v) { Q_ASSERT(v); } QJsonVisitor(const QJsonValue* v) : json(v) { Q_ASSERT(v); }
void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); errors.resize(0); } void reset(QJsonValue* v) { json=v; Q_ASSERT(v); steps.resize(0); errors.resize(0); }
struct Error { QIdentifierLiteral error; QAsciiData path; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
QAsciiData currentPath() { QAsciiData currentPath() {
...@@ -117,9 +117,9 @@ public: ...@@ -117,9 +117,9 @@ public:
} }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step());
return true; } _reportError(qBindExpectedSequence); return false; } return true; } _reportError(qBindExpectedSequence); return false; }
...@@ -163,9 +163,9 @@ public: ...@@ -163,9 +163,9 @@ public:
~QJsonWriter() { while (!levels.isEmpty()) write(levels.takeLast().end); } ~QJsonWriter() { while (!levels.isEmpty()) write(levels.takeLast().end); }
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence ( s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
template<class T> friend class QModelWriter; template<class T> friend class QModelWriter;
...@@ -245,13 +245,13 @@ public: ...@@ -245,13 +245,13 @@ public:
} }
struct Step { int index; const char* end; QMap<QIdentifier,QJsonValue/*TODO QVariant for meta() support*/> cachedItems; Step(int i=-1, const char* e=nullptr) : index(i), end(e) {} }; struct Step { int index; const char* end; QMap<QIdentifier,QJsonValue/*TODO QVariant for meta() support*/> cachedItems; Step(int i=-1, const char* e=nullptr) : index(i), end(e) {} };
struct Error { QIdentifierLiteral error; int line; int column; int index; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
enum CachedNumber : quint8 { None=0, Integer, FloatingPoint }; enum CachedNumber : quint8 { None=0, Integer, FloatingPoint };
...@@ -513,7 +513,7 @@ private: ...@@ -513,7 +513,7 @@ private:
}; };
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<QJson*,_> support // QJson* support
#include <QtCore/qjsonvalue.h> #include <QtCore/qjsonvalue.h>
#include <QtCore/qjsonarray.h> #include <QtCore/qjsonarray.h>
...@@ -521,7 +521,7 @@ private: ...@@ -521,7 +521,7 @@ private:
template<> template<>
struct QTransmogrifier<QJsonValue> { struct QTransmogrifier<QJsonValue> {
static QValueStatus bind(QValue&& v, QJsonValue&& j) { static QValueStatus zap(QValue&& v, QJsonValue&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
if (j.isObject()) return v.bind(j.toObject()); if (j.isObject()) return v.bind(j.toObject());
if (j.isArray ()) return v.bind(j.toArray ()); if (j.isArray ()) return v.bind(j.toArray ());
...@@ -532,9 +532,9 @@ struct QTransmogrifier<QJsonValue> { ...@@ -532,9 +532,9 @@ struct QTransmogrifier<QJsonValue> {
} }
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 QValueStatus bind(QValue&& v, QJsonValue& j) { static QValueStatus zap(QValue&& v, QJsonValue& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
QValueStatus r; QValueStatus r;
...@@ -557,7 +557,7 @@ struct QTransmogrifier<QJsonValue> { ...@@ -557,7 +557,7 @@ struct QTransmogrifier<QJsonValue> {
template<> template<>
struct QTransmogrifier<QJsonArray> { struct QTransmogrifier<QJsonArray> {
static QValueStatus bind(QValue&& v, QJsonArray&& j) { static QValueStatus zap(QValue&& v, QJsonArray&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
quint32 size=quint32(j.size()); quint32 size=quint32(j.size());
auto s(v.sequence(&size)); auto s(v.sequence(&size));
...@@ -568,13 +568,13 @@ struct QTransmogrifier<QJsonArray> { ...@@ -568,13 +568,13 @@ struct QTransmogrifier<QJsonArray> {
} }
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 QValueStatus bind(QValue&& v, QJsonArray& j) { static QValueStatus zap(QValue&& v, QJsonArray& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
auto s(v.sequence()); auto s(v.sequence());
QVal<QSeq<QValueStatus>> i; QVal<QSequence> i;
while ((i = s.item())) { while ((i = s.item())) {
QJsonValue json; QJsonValue json;
if ((s = i.bind(json))) if ((s = i.bind(json)))
...@@ -588,7 +588,7 @@ struct QTransmogrifier<QJsonArray> { ...@@ -588,7 +588,7 @@ struct QTransmogrifier<QJsonArray> {
template<> template<>
struct QTransmogrifier<QJsonObject> { struct QTransmogrifier<QJsonObject> {
static QValueStatus bind(QValue&& v, QJsonObject&& j) { static QValueStatus zap(QValue&& v, QJsonObject&& j) {
if (v->mode()==Write) { if (v->mode()==Write) {
quint32 size=quint32(j.size()); quint32 size=quint32(j.size());
auto s(v.record(&size)); auto s(v.record(&size));
...@@ -600,13 +600,13 @@ struct QTransmogrifier<QJsonObject> { ...@@ -600,13 +600,13 @@ struct QTransmogrifier<QJsonObject> {
} }
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 QValueStatus bind(QValue&& v, QJsonObject& j) { static QValueStatus zap(QValue&& v, QJsonObject& j) {
if (v->mode()==Write) { 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) { else if (v->mode()==Read) {
auto s(v.record()); auto s(v.record());
QIdentifier k; QVal<QRec<QValueStatus>> i; QIdentifier k; QVal<QRecord> i;
while ((i = s.item(k))) { while ((i = s.item(k))) {
QJsonValue json; QJsonValue json;
if ((s = i.bind(json))) if ((s = i.bind(json)))
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
#include "QJson_impl.h" #include "QJson_impl.h"
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<T,Q*Model> support // Q*Model support
class QModelBind : public QAbstractValue class QModelBind : public QAbstractValue
{ {
...@@ -59,7 +59,7 @@ class QModelBind : public QAbstractValue ...@@ -59,7 +59,7 @@ class QModelBind : public QAbstractValue
public: public:
QModelBind(QAbstractItemModel* m, bool rowFirst=true) : m(m), rowFirst(rowFirst) { Q_ASSERT(m); } QModelBind(QAbstractItemModel* m, bool rowFirst=true) : m(m), rowFirst(rowFirst) { Q_ASSERT(m); }
struct Error { QIdentifierLiteral error; QModelIndex index; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
QValue value() { return QValueStatus(this).value(); } QValue value() { return QValueStatus(this).value(); }
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
// Shortcuts // Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); } /**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool tryBind ( quint8&& t) { settings->setValue(key(), int(t) ); return true; } bool tryBind ( quint8&& t) { settings->setValue(key(), int(t) ); return true; }
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
Q_ENABLE_MOVE(QSettingsReader, std::swap(isChoice, o.isChoice); ) Q_ENABLE_MOVE(QSettingsReader, std::swap(isChoice, o.isChoice); )
QSettingsReader(QSettings* s) : settings(s) { Q_ASSERT(s); levels.push(Level(qBindExpectedItem)); } QSettingsReader(QSettings* s) : settings(s) { Q_ASSERT(s); levels.push(Level(qBindExpectedItem)); }
struct Error { QIdentifierLiteral error; QAsciiData path; template<class T> T bind(QVal<T>&& 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<Error> errors; QVector<Error> errors;
QAsciiData currentPath() { QAsciiData currentPath() {
......
...@@ -109,7 +109,7 @@ extern QIdentifierLiteral qmColor; ...@@ -109,7 +109,7 @@ extern QIdentifierLiteral qmColor;
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<T> // QTransmogrifier<T>
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 BindGeneric {};
struct BindNative {}; struct BindNative {};
...@@ -318,8 +318,8 @@ using QRecord = QRec<QValueStatus>; ...@@ -318,8 +318,8 @@ using QRecord = QRec<QValueStatus>;
#include <functional> #include <functional>
#ifndef NO_COMPILER_RTTI_OR_EXCEPTIONS #ifndef NO_COMPILER_RTTI_OR_EXCEPTIONS
template<typename T> using QValFunction = QValueStatus (*)(T &,QValue &&) ; template<typename T> using QValFunction = QValueStatus(*)(T &,QValue &&) ;
template<class Ts> using QSeqFunction = QSequence (*)(Ts&,QSequence&&) ; template<class Ts> using QSeqFunction = QSequence (*)(Ts&,QSequence&&) ;
#endif #endif
/**/ using QValLambda = std::function<QValueStatus(QValue &&)>; /**/ using QValLambda = std::function<QValueStatus(QValue &&)>;
/**/ using QSeqLambda = std::function<QSequence (QSequence&&)>; /**/ using QSeqLambda = std::function<QSequence (QSequence&&)>;
...@@ -338,16 +338,16 @@ public: ...@@ -338,16 +338,16 @@ public:
QSeq<T_> sequence(quint32* s=nullptr) { return outer->trySequence (s) ? QSeq<T_>(std::move(outer)) : QSeq<T_>(); } QSeq<T_> sequence(quint32* s=nullptr) { return outer->trySequence (s) ? QSeq<T_>(std::move(outer)) : QSeq<T_>(); }
QRec<T_> record (quint32* s=nullptr) { return outer->tryRecord (s) ? QRec<T_>(std::move(outer)) : QRec<T_>(); } QRec<T_> record (quint32* s=nullptr) { return outer->tryRecord (s) ? QRec<T_>(std::move(outer)) : QRec<T_>(); }
/**/ T_ null ( ) { return outer->tryNull ( ) ? std::move(outer) : T_ (); } /**/ T_ null ( ) { return outer->tryNull ( ) ? std::move(outer) : T_ (); }
/**/ T_ any ( ) { return outer->tryAny ( ) ? 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 ( 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 ( QUtf8DataView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); }
/**/ T_ bind ( QAsciiDataView a) { return outer->tryBind (a) ? 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 ( QLatin1String l) { return outer->tryBind (l) ? std::move(outer) : T_ (); }
/**/ T_ bind ( QStringView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); } /**/ T_ bind ( QStringView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); }
template<typename T> T_ bind ( T&& t) { return outer->tryBind(std::forward<T>(t )) ? std::move(outer) : T_(); } template<typename T> T_ bind ( T&& t) { return outer->tryBind(std::forward <T>(t )) ? std::move(outer) : T_(); }
template<typename T> T_ bind (T& t, T&& defaultT) { return outer->tryBind(QDefaultValue<T>{t,defaultT}) ? std::move(outer) : T_(); } template<typename T> T_ bind (T& t, T&& defaultT) { return outer->tryBind(QDefaultValue<T>{t,defaultT}) ? std::move(outer) : T_(); }
// Custom bind support // Custom bind support
...@@ -412,8 +412,8 @@ public: ...@@ -412,8 +412,8 @@ public:
template<typename T> QSeq<T_> operator<<(T&& t) { return item().bind(std::forward<T>(t)); } // stream compatible template<typename T> QSeq<T_> operator<<(T&& t) { return item().bind(std::forward<T>(t)); } // stream compatible
private: private:
template<typename T, typename TEnabledIf> friend struct QTransmogrifier; template<typename T, typename TEnabledIf> friend struct QTransmogrifier;
QValue unsafeItem() noexcept { return outer->tryItem() ? QValue(outer->_unsafeCopy()) : QValue(); } QValue unsafeItem() noexcept { return outer->tryItem() ? QValue(outer->_unsafeCopy()) : QValue(); }
QSeq<QValueStatus> unsafeThis() noexcept { return QSeq<