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

Use a QValueEnd type with jus the bool result to hide QValueStatus

undesirable methods like value() that allowed to concatenate QValues in,
say, a JSON stream
parent c50b87ac
......@@ -465,7 +465,7 @@ private:
template<>
struct QTransmogrifier<QCborValue> {
static QValueStatus zap(QValue&& v, QCborValue&& j) {
static QValueEnd 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 ());
......@@ -480,7 +480,7 @@ struct QTransmogrifier<QCborValue> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QCborValue& j) {
static QValueEnd zap(QValue&& v, QCborValue& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......@@ -507,7 +507,7 @@ struct QTransmogrifier<QCborValue> {
template<>
struct QTransmogrifier<QCborArray> {
static QValueStatus zap(QValue&& v, QCborArray&& j) {
static QValueEnd zap(QValue&& v, QCborArray&& j) {
if (v->mode()==Write) {
quint32 size=quint32(j.size());
auto s(v.sequence(&size));
......@@ -518,7 +518,7 @@ struct QTransmogrifier<QCborArray> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QCborArray& j) {
static QValueEnd zap(QValue&& v, QCborArray& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......@@ -538,7 +538,7 @@ struct QTransmogrifier<QCborArray> {
template<>
struct QTransmogrifier<QCborMap> {
static QValueStatus zap(QValue&& v, QCborMap&& j) {
static QValueEnd zap(QValue&& v, QCborMap&& j) {
if (v->mode()==Write) {
quint32 size=quint32(j.size());
auto r(v.record(&size));
......@@ -553,7 +553,7 @@ struct QTransmogrifier<QCborMap> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QCborMap& j) {
static QValueEnd zap(QValue&& v, QCborMap& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......
......@@ -65,7 +65,7 @@ public:
QValue value ( ) { return QValueStatus(this).value(); }
QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus zap(T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
template<typename T> QValueEnd zap(T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected:
friend class QValueStatus;
bool trySequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
......
......@@ -240,7 +240,7 @@ 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 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)); } };
struct Error { QIdentifierLiteral error; int line; int column; int index; QValueEnd 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;
// Shortcuts
......@@ -523,7 +523,7 @@ private:
template<>
struct QTransmogrifier<QJsonValue> {
static QValueStatus zap(QValue&& v, QJsonValue&& j) {
static QValueEnd 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 ());
......@@ -536,7 +536,7 @@ struct QTransmogrifier<QJsonValue> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QJsonValue& j) {
static QValueEnd zap(QValue&& v, QJsonValue& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......@@ -561,7 +561,7 @@ struct QTransmogrifier<QJsonValue> {
template<>
struct QTransmogrifier<QJsonArray> {
static QValueStatus zap(QValue&& v, QJsonArray&& j) {
static QValueEnd zap(QValue&& v, QJsonArray&& j) {
if (v->mode()==Write) {
quint32 size=quint32(j.size());
auto s(v.sequence(&size));
......@@ -572,7 +572,7 @@ struct QTransmogrifier<QJsonArray> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QJsonArray& j) {
static QValueEnd zap(QValue&& v, QJsonArray& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......@@ -592,7 +592,7 @@ struct QTransmogrifier<QJsonArray> {
template<>
struct QTransmogrifier<QJsonObject> {
static QValueStatus zap(QValue&& v, QJsonObject&& j) {
static QValueEnd zap(QValue&& v, QJsonObject&& j) {
if (v->mode()==Write) {
quint32 size=quint32(j.size());
auto s(v.record(&size));
......@@ -604,7 +604,7 @@ struct QTransmogrifier<QJsonObject> {
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueStatus zap(QValue&& v, QJsonObject& j) {
static QValueEnd zap(QValue&& v, QJsonObject& j) {
if (v->mode()==Write) {
return zap(std::move(v),std::move(j));
}
......
This diff is collapsed.
......@@ -99,7 +99,7 @@ struct Person
{
QString firstName, lastName; double height; int age; QVector<QString> phones; QString comments; QList<Person> children;
QValueStatus zap(QValue&& value) { // works with value->mode()==Read as well as Write
QValueEnd 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,8 +247,8 @@ 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<QColor> {
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) {
static QValueEnd zap(QValue&& v, QColor&& c) { QColor copy(c); return bind(std::move(v),copy); } // supports writing temporaries and const QColor&
static QValueEnd zap(QValue&& v, QColor& c) {
if (!c.isValid()) {
return v.null();
}
......
......@@ -84,7 +84,7 @@ struct Person
{
int id; QString firstName, lastName; double height; int age; QVector<Phone> phones; QString comments; QList<Person> children;
QValueStatus zap(QValue&& value) { // works with value->mode()==Read as well as Write
QValueEnd zap(QValue&& value) { // works with value->mode()==Read as well as Write
return value
.record("Person")
.sequence("names")
......@@ -137,7 +137,7 @@ struct PersonsView
{
QList<Person>& persons;
QValueStatus zap(QValue&& value) {
QValueEnd zap(QValue&& value) {
return value
.meta(qmChildren,"children")
.meta(qmColumns ,"names,height,age,phones,comments") // to optimize multi-dimensional data formats
......@@ -151,7 +151,7 @@ struct PersonsTable {
QList<Person>& persons;
PersonsTable(QList<Person>& ps) : persons(ps) {}
QValueStatus zap(QValue&& v) {
QValueEnd zap(QValue&& v) {
if (v->mode()==Read) {
ids.clear();
orphans.clear();
......@@ -254,11 +254,11 @@ private:
//! QTransmogrifier<QColor> with special support for QDataStream compatibility using meta()
template<>
struct QTransmogrifier<QColor> {
static QValueStatus zap(QValue&& v, QColor&& c) {
static QValueEnd zap(QValue&& v, QColor&& c) {
QColor copy(c);
return zap(std::move(v),copy);
}
static QValueStatus zap(QValue&& v, QColor& c) {
static QValueEnd zap(QValue&& v, QColor& c) {
if (!c.isValid()) {
return v.null();
}
......
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