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:
QCborWriter(QByteArray* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
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<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
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<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 ( QByteArray&& s) { set(QCborValue( s )); return true; }
......@@ -233,7 +233,7 @@ public:
QCborVisitor(QCborValue* v) : cbor(v) { Q_ASSERT(v); }
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;
QAsciiData currentPath() {
......@@ -246,9 +246,9 @@ public:
}
// Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
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<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;
// Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> 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<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected:
bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); }
......@@ -475,7 +475,7 @@ private:
template<>
struct QTransmogrifier<QCborValue> {
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<QCborValue> {
}
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<QCborValue> {
template<>
struct QTransmogrifier<QCborArray> {
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<QCborArray> {
}
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<QSeq<QValueStatus>> i;
QVal<QSequence> i;
while ((i = s.item())) {
QCborValue json;
if ((s = i.bind(json)))
......@@ -546,7 +546,7 @@ struct QTransmogrifier<QCborArray> {
template<>
struct QTransmogrifier<QCborMap> {
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<QCborMap> {
}
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<QRec<QValueStatus>> i;
QIdentifier k; QVal<QRecord> i;
while ((i = s.item(k))) {
QCborValue json;
if ((s = i.bind(json)))
......
......@@ -47,7 +47,7 @@
#include "QValue.h"
// //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<T,QDataStream*> 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<QValueStatus> 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<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:
friend class QValueStatus;
bool trySequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
......
......@@ -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<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
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<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;
QAsciiData currentPath() {
......@@ -117,9 +117,9 @@ public:
}
// Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
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<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
protected:
template<class T> friend class QModelWriter;
......@@ -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 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;
// Shortcuts
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ QSeq<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
protected:
enum CachedNumber : quint8 { None=0, Integer, FloatingPoint };
......@@ -513,7 +513,7 @@ private:
};
// //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<QJson*,_> support
// QJson* support
#include <QtCore/qjsonvalue.h>
#include <QtCore/qjsonarray.h>
......@@ -521,7 +521,7 @@ private:
template<>
struct QTransmogrifier<QJsonValue> {
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<QJsonValue> {
}
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<QJsonValue> {
template<>
struct QTransmogrifier<QJsonArray> {
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<QJsonArray> {
}
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<QSeq<QValueStatus>> i;
QVal<QSequence> i;
while ((i = s.item())) {
QJsonValue json;
if ((s = i.bind(json)))
......@@ -588,7 +588,7 @@ struct QTransmogrifier<QJsonArray> {
template<>
struct QTransmogrifier<QJsonObject> {
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<QJsonObject> {
}
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<QRec<QValueStatus>> i;
QIdentifier k; QVal<QRecord> i;
while ((i = s.item(k))) {
QJsonValue json;
if ((s = i.bind(json)))
......
......@@ -51,7 +51,7 @@
#include "QJson_impl.h"
// //////////////////////////////////////////////////////////////////////////
// QTransmogrifier<T,Q*Model> 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<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;
QValue value() { return QValueStatus(this).value(); }
......
......@@ -56,7 +56,7 @@ public:
// Shortcuts
/**/ 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)); }
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<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;
QAsciiData currentPath() {
......
This diff is collapsed.
......@@ -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<QValueStatus> 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)); }
/**/ QValue value ( ) { return QValueStatus(this).value(); }
/**/ 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)); }
protected:
// TODO Support _meta to be able to cache and restitute all metadata as well as data+datatype
......
......@@ -67,8 +67,8 @@ public:
QValueMode mode() const noexcept { return QValueMode::Write; }
// Shortcuts
QValue value ( ) { return QValueStatus(this).value(); }
QSeq<QValueStatus> 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<typename T> QValueStatus bind(T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected:
......
......@@ -99,7 +99,7 @@ struct Person
{
QString firstName, lastName; double height; int age; QVector<QString> phones; QString comments; QList<Person> 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<QColor> {
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<QValueStatus> 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<QValueStatus>&& s) {
QModelWriter<>(&custom).sequence().with([&](QSequence&& s) {
for (auto&& person : persons) {
s = s.record()
.item("first name")
......
......@@ -84,7 +84,7 @@ struct Person
{
int id; QString firstName, lastName; double height; int age; QVector<Phone> phones; QString comments; QList<Person> 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<Person>& 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<Person>& persons;
PersonsTable(QList<Person>& 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<int,Person*> ids;
QMap<int,QList<Person>> orphans;
QSeq<QValueStatus> bind(Person& p, QSeq<QValueStatus>&& s) {
QSequence bind(Person& p, QSequence&& s) {
if (s->mode()==Read) {
int parentId=0;
double height_ft=0.;
......@@ -235,7 +235,7 @@ private:
}
}
QSeq<QValueStatus> flatten(QList<Person>& ps, QSeq<QValueStatus>&& s) {
QSequence flatten(QList<Person>& ps, QSequence&& s) {
for (auto&& p : ps) {
s = bind(p, std::move(s));
}
......@@ -251,11 +251,11 @@ private:
//! QTransmogrifier<QColor> with special support for QDataStream compatibility using meta()
template<>
struct QTransmogrifier<QColor> {
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<QColor> {
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<QValueStatus> 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<typename T> QSeq<QValueStatus> operator<<(T&& t) { return QValueStatus(this).value().sequence().item().bind(std::forward<T>(t)); }
template<typename T> QValueStatus bind (T&& t) { return QValueStatus(this).value() .bind(std::forward<T>(t)); }
template<typename T> QSequence operator<<(T&& t) { return QValueStatus(this).value().sequence().item().bind(std::forward<T>(t)); }
template<typename T> QValueStatus bind (T&& t) { return QValueStatus(this).value() .bind(std::forward<T>(t)); }
protected:
bool trySequence(quint32* =nullptr) { if (0<level++) utf8->append("["); return true; }
bool tryRecord (quint32* =nullptr) { if (0<level++) utf8->append("["); return true; }
......@@ -1094,7 +1094,7 @@ int main(int argc, char *argv[])
return (fclose(samples)==0) &/*anyway*/ (fclose(results)==0);
}
QSeq<QValueStatus> flatten(QList<Person>& ps, QSeq<QValueStatus>&& s) {
QSequence flatten(QList<Person>& 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<QValueStatus>&& 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()
......
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