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

QModelReader working for simple cases allowing to change data from some

views to QList persons and other views
parent ed4b15cc
......@@ -161,63 +161,63 @@ struct IBind {
virtual bool _item(QIdentifierLiteral n) = 0;
virtual bool _out ( ) = 0; //!< End of sequence or record
virtual bool _bind( QUtf8DataView u) = 0;
virtual bool _bind( const char* u) = 0;
virtual bool _bind(QAsciiDataView a) = 0;
virtual bool _bind( QLatin1String l) = 0;
virtual bool _bind( QStringView s) = 0;
virtual bool _bind( QUtf8Data& r) = 0;
virtual bool _bind( QString& r) = 0;
virtual bool _bind( bool& r) = 0;
virtual bool _bind( qint8& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint8& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint16& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint16& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint32& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint32& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint64& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint64& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( float& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( double& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( QByteArray& r) = 0;
virtual bool _bind( QVariant& r) = 0;
virtual bool _bind( QUtf8DataView u) = 0;
virtual bool _bind( const char* u) = 0;
virtual bool _bind( QAsciiDataView a) = 0;
virtual bool _bind( QLatin1String l) = 0;
virtual bool _bind( QStringView s) = 0;
virtual bool _bind( QUtf8Data& r) = 0;
virtual bool _bind( QString& r) = 0;
virtual bool _bind( bool& r) = 0;
virtual bool _bind( qint8& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint8& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint16& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint16& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint32& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint32& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( qint64& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( quint64& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( float& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( double& r) = 0; //!< \warning Must return false instead of losing sign or digit
virtual bool _bind( QByteArray& r) = 0;
virtual bool _bind( QVariant& r) = 0;
// TODO QChar, QDateTime, QDate, QTime, QUuid (text or numerical)
// Overloads for const& and && T
virtual bool _bind(const QUtf8Data& r) = 0;
virtual bool _bind(const QString& r) = 0;
virtual bool _bind(const bool& r) = 0;
virtual bool _bind(const qint8& r) = 0;
virtual bool _bind(const quint8& r) = 0;
virtual bool _bind(const qint16& r) = 0;
virtual bool _bind(const quint16& r) = 0;
virtual bool _bind(const qint32& r) = 0;
virtual bool _bind(const quint32& r) = 0;
virtual bool _bind(const qint64& r) = 0;
virtual bool _bind(const quint64& r) = 0;
virtual bool _bind(const float& r) = 0;
virtual bool _bind(const double& r) = 0;
virtual bool _bind(const QByteArray& r) = 0;
virtual bool _bind(const QVariant& r) = 0;
virtual bool _bind( QUtf8Data&& r) = 0;
virtual bool _bind( QString&& r) = 0;
virtual bool _bind( bool&& r) = 0;
virtual bool _bind( qint8&& r) = 0;
virtual bool _bind( quint8&& r) = 0;
virtual bool _bind( qint16&& r) = 0;
virtual bool _bind( quint16&& r) = 0;
virtual bool _bind( qint32&& r) = 0;
virtual bool _bind( quint32&& r) = 0;
virtual bool _bind( qint64&& r) = 0;
virtual bool _bind( quint64&& r) = 0;
virtual bool _bind( float&& r) = 0;
virtual bool _bind( double&& r) = 0;
virtual bool _bind( QByteArray&& r) = 0;
virtual bool _bind( QVariant&& r) = 0;
virtual bool _bind(const QUtf8Data& r) = 0;
virtual bool _bind(const QString& r) = 0;
virtual bool _bind(const bool& r) = 0;
virtual bool _bind(const qint8& r) = 0;
virtual bool _bind(const quint8& r) = 0;
virtual bool _bind(const qint16& r) = 0;
virtual bool _bind(const quint16& r) = 0;
virtual bool _bind(const qint32& r) = 0;
virtual bool _bind(const quint32& r) = 0;
virtual bool _bind(const qint64& r) = 0;
virtual bool _bind(const quint64& r) = 0;
virtual bool _bind(const float& r) = 0;
virtual bool _bind(const double& r) = 0;
virtual bool _bind(const QByteArray& r) = 0;
virtual bool _bind(const QVariant& r) = 0;
virtual bool _bind( QUtf8Data&& r) = 0;
virtual bool _bind( QString&& r) = 0;
virtual bool _bind( bool&& r) = 0;
virtual bool _bind( qint8&& r) = 0;
virtual bool _bind( quint8&& r) = 0;
virtual bool _bind( qint16&& r) = 0;
virtual bool _bind( quint16&& r) = 0;
virtual bool _bind( qint32&& r) = 0;
virtual bool _bind( quint32&& r) = 0;
virtual bool _bind( qint64&& r) = 0;
virtual bool _bind( quint64&& r) = 0;
virtual bool _bind( float&& r) = 0;
virtual bool _bind( double&& r) = 0;
virtual bool _bind( QByteArray&& r) = 0;
virtual bool _bind( QVariant&& r) = 0;
virtual bool _any() { return _null(); }
......@@ -1022,11 +1022,19 @@ struct QBind<QVector<T>> {
}
else if (v->mode()==Read) {
auto s(v.sequence());
Val<Seq<Cursor>> i;
Val<Seq<Cursor>> i; int it = 0;
while ((i = s.item())) {
T t;
if((s = i.bind(t))) // gives back control to s, enabling the next s.item() call
ts.append(t);
if (it==ts.size()) {
T t;
if ((s = i.bind(t))) // gives back control to s, enabling the next s.item() call
ts.insert(it++, t);
// TODO else s = i.any();
}
else {
T t(ts[it]);
if ((s = i.bind(t)))
ts[it++] = t;
}
}
return s;
}
......@@ -1051,15 +1059,27 @@ struct QBind<QList<T>> {
}
static Cursor bind(Val<Cursor>&& v, QList<T>& ts) {
if (v->mode()==Write) {
return bind(std::move(v),QList<T>(ts));
quint32 size=quint32(ts.size());
auto s(v.sequence(&size));
for (auto&& t : ts) {
s = s.bind(t);
}
return s;
}
else if (v->mode()==Read) {
auto s(v.sequence());
Val<Seq<Cursor>> i;
Val<Seq<Cursor>> i; int it = 0;
while ((i = s.item())) {
T v;
if ((s = i.bind(v)))
ts.append(v);
if (it==ts.size()) {
T t;
if ((s = i.bind(t)))
ts.insert(it++, t);
}
else {
T t(ts[it]);
if ((s = i.bind(t)))
ts[it++] = t;
}
}
return s;
}
......@@ -1078,7 +1098,7 @@ struct QBind<QMap<QString,T>> {
quint32 size=quint32(ts.size());
auto s(v.record(&size));
for (QString key : ts.keys()) {
s = s.bind(key.toUtf8().constData(),ts[key]);
s = s.bind(key.toLatin1().constData(),ts[key]);
}
return s;
}
......@@ -1086,15 +1106,20 @@ struct QBind<QMap<QString,T>> {
}
static Cursor bind(Val<Cursor>&& v, QMap<QString,T>& ts) {
if (v->mode()==Write) {
return bind(std::move(v),QMap<QString,T>(ts));
quint32 size=quint32(ts.size());
auto s(v.record(&size));
for (QString key : ts.keys()) {
s = s.bind(key.toLatin1().constData(),ts[key]);
}
return s;
}
else if (v->mode()==Read) {
auto r(v.record());
QIdentifier name; Val<Rec<Cursor>> i;
while ((i = r.item(name))) {
T value;
T value(ts[name.latin1()]);
if ((r = i.bind(value)))
ts.insert(name.utf8(),value);
ts.insert(name.latin1(),value);
}
return r;
}
......
......@@ -231,6 +231,18 @@ class QJsonReader : public IReader
Q_DISABLE_COPY(QJsonReader)
public:
QJsonReader(QIODevice* io) : io(io), cacheWriter(&cachedValue), cacheReader(&cachedValue) { Q_ASSERT(io); }
void reset(QIODevice* other) {
errors.clear(); levels.clear();
line=0; column=0; index=-1;
isChoice=false;
cachedNumber = None; d=.0; i=0; neg=bool();
cacheLevel = 0; cachedValue = QJsonValue();
cacheWriter.reset(&cachedValue);
caching = nullptr; //!< Only used when cacheLevel>=1 && key!=expectedKey
cacheReader.reset(&cachedValue);
io=other;
Q_ASSERT(io);
}
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(Val<T>&& value) { QByteArray u(error.utf8()); u.append(' ').append(QByteArray::number(line)).append(':').append(QByteArray::number(column)); return value.bind(QUtf8Data(u)); } };
......@@ -465,7 +477,8 @@ private:
return false;
}
char getChar () { char c; if (io->getChar(&c) ) { if (c=='\n') { line++; column=0; } else { column++; } index++; return c; } return '\0'; }
char nextChar() { char c; if (io->peek (&c,1)==1) { return c; } return '\0'; }
char nextChar() { char c; if (io->peek (&c,1)==1) {
return c; } return '\0'; }
char next(const char* validChars, char expected='\0') {
if (validChars) {
while (!(nextChar() == expected || strchr(validChars, nextChar()) || nextChar() == '\0')) {
......
This diff is collapsed.
This diff is collapsed.
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