...
 
Commits (3)
......@@ -249,12 +249,12 @@ public:
/**/ QSequence sequence(quint32* s=nullptr) { return QCur(this).value().sequence(s); }
template<typename T> QCur bind ( T&& t) { return QCur(this).value().bind(std::forward<T>(t)); }
protected:
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } handleError(qBindExpectedSequence); return false; }
bool tryRecord (quint32* =nullptr) { if (current().isMap ()) { steps.push(Step()); return true; } handleError(qBindExpectedRecord ); return false; }
bool tryNull ( ) { if (current().isNull ()) { return true; } handleError(qBindExpectedNull ); return false; }
bool tryBind ( QUtf8Data& u) { QString s; if (tryBind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool tryBind ( QString& v) { if (current().isString ()) { v = current().toString (); return true; } handleError(qBindExpectedText ); return false; }
bool tryBind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } handleError(qBindExpectedBoolean ); return false; }
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } return false; }
bool tryRecord (quint32* =nullptr) { if (current().isMap ()) { steps.push(Step()); return true; } return false; }
bool tryNull ( ) { if (current().isNull ()) { return true; } return false; }
bool tryBind ( QUtf8Data& u) { QString s; if (tryBind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool tryBind ( QString& v) { if (current().isString ()) { v = current().toString (); return true; } return false; }
bool tryBind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } return false; }
bool tryBind ( qint64& t) { if (current().isInteger ()) { t = current().toInteger (); return true; } handleError(qBindExpectedInteger ); return false; }
bool tryBind ( quint64& t) { qint64 i; if (tryBind(i) ) { t = quint64(i) ; return true; } return false; }
bool tryBind ( float& v) { double d; if (tryBind(d) ) { v = float(d) ; return true; } return false; }
......@@ -294,13 +294,13 @@ public:
template<typename T> QValueEnd bind ( T&& t) { return QCur(this).value().bind(std::forward<T>(t)); }
protected:
bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); }
skipTag(); if (isArray () && enterContainer()) { levels.push(Level()); return true; } handleError(qBindExpectedSequence); return false; }
skipTag(); if (isArray () && enterContainer()) { levels.push(Level()); return true; } return false; }
bool tryRecord (quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->tryRecord(s); }
skipTag(); if (isMap () && enterContainer()) { levels.push(Level()); return true; } handleError(qBindExpectedRecord ); return false; }
skipTag(); if (isMap () && enterContainer()) { levels.push(Level()); return true; } return false; }
bool tryAny ( ) { if (caching) { return caching->tryAny() && cacheOut(); }
skipTag(); return next(); }
bool tryNull ( ) { if (caching) { return caching->tryNull() && cacheOut(); }
skipTag(); if (isNull() && next()) { return true; } handleError(qBindExpectedNull); return false; }
skipTag(); return isNull() && next(); }
bool tryBind ( QUtf8Data& u) { QString s; if (tryBind(s)) { u = s.toUtf8(); return true; } return false; }
bool tryBind ( QString& s) { if (caching) { return caching->tryBind(s) && cacheOut(); }
skipTag(); if (isString()) {
......@@ -317,7 +317,7 @@ protected:
return handleError(qBindIgnoredBytes);
}
return true;
} else { handleError(qBindExpectedText); return false; } }
} else { return false; } }
bool tryBind ( QByteArray& s) { if (caching) { return caching->tryBind(s) && cacheOut(); }
skipTag(); if (isByteArray()) {
s.resize(0);
......@@ -338,7 +338,7 @@ protected:
skipTag(); if (isBool()) {
b=toBool();
return next();
} else { handleError(qBindExpectedBoolean); return false; } }
} else { return false; } }
bool tryBind ( double& n) { if (caching) { return caching->tryBind(n) && cacheOut(); }
return getNumber(n); }
bool tryBind ( float& n) { double d;
......@@ -349,7 +349,7 @@ protected:
bool tryBind ( quint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
skipTag();
if (!isUnsignedInteger()) { handleError(qBindExpectedPositiveInteger); return false; }
if (!isUnsignedInteger()) { return false; }
t=toUnsignedInteger(); return true; }
bool tryBind ( qint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
quint64 i; bool neg;
......
......@@ -119,15 +119,15 @@ public:
/**/ QSequence sequence(quint32* s=nullptr) { return QCur(this).value().sequence(s); }
template<typename T> QValueEnd bind ( T&& t) { return QCur(this).value().bind(std::forward<T>(t)); }
protected:
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } handleError(qBindExpectedSequence); return false; }
bool tryRecord (quint32* =nullptr) { if (current().isObject()) { steps.push(Step()); return true; } handleError(qBindExpectedRecord ); return false; }
bool tryNull ( ) { if (current().isNull() ) { return true; } handleError(qBindExpectedNull ); return false; }
bool tryBind ( QUtf8Data& u) { QString s; if (tryBind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool tryBind ( QString& v) { if (current().isString()) { v = current().toString(); return true; } handleError(qBindExpectedText ); return false; }
bool tryBind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } handleError(qBindExpectedBoolean ); return false; }
bool tryBind ( qint64& t) { double d; if (tryBind(d) ) { t = qint64(d) ; return true; } return false; }
bool tryBind ( quint64& t) { double d; if (tryBind(d) ) { t = quint64(d) ; return true; } return false; }
bool tryBind ( float& v) { double d; if (tryBind(d) ) { v = float(d) ; return true; } return false; }
bool trySequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } return false; }
bool tryRecord (quint32* =nullptr) { if (current().isObject()) { steps.push(Step()); return true; } return false; }
bool tryNull ( ) { if (current().isNull() ) { return true; } return false; }
bool tryBind ( QUtf8Data& u) { QString s; if (tryBind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool tryBind ( QString& v) { if (current().isString()) { v = current().toString(); return true; } return false; }
bool tryBind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } return false; }
bool tryBind ( qint64& t) { double d; if (tryBind(d) ) { t = qint64(d) ; return true; } return false; }
bool tryBind ( quint64& t) { double d; if (tryBind(d) ) { t = quint64(d) ; return true; } return false; }
bool tryBind ( float& v) { double d; if (tryBind(d) ) { v = float(d) ; return true; } return false; }
bool tryBind ( double& v) { if (current().isDouble()) { v = current().toDouble(); return true; } handleError(qBindExpectedDecimal ); return false; }
bool tryItem(QIdentifierLiteral u) { steps.last().key=u; return !(steps.last().item = current(1).toObject().value(steps.last().key.latin1())).isUndefined(); }
......@@ -254,9 +254,9 @@ protected:
enum CachedNumber : quint8 { None=0, Integer, FloatingPoint };
bool trySequence(quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->trySequence(s); }
if (get('[', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"]")); return true; } handleError(qBindExpectedSequence); return false; }
if (get('[', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"]")); return true; } return false; }
bool tryRecord (quint32* s=nullptr) { if (caching) { cacheLevel++; return caching->tryRecord(s); }
if (get('{', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"}")); return true; } handleError(qBindExpectedRecord ); return false; }
if (get('{', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"}")); return true; } return false; }
bool tryAny ( ) { if (caching) { return caching->tryAny() && cacheOut(); }
return next(",}]"); }
bool tryNull ( ) { if (caching) { return caching->tryNull() && cacheOut(); }
......@@ -265,14 +265,14 @@ protected:
get('l') &&
get('l')) {
return true;
} else { handleError(qBindExpectedNull); return false; } }
} else { return false; } }
bool tryBind ( QUtf8Data& s) { if (caching) { return caching->tryBind(s) && cacheOut(); }
QByteArray u;
if ( get('"', "[{\"ntf-0123456789.")) { u.resize(0); char c;
while ((c=getCharInString()) != '\0' ) { u.append(c); }
s=QUtf8Data(u);
return get('"');
} else { handleError(qBindExpectedText); return false; } }
} else { return false; } }
bool tryBind ( QString& s) { QUtf8Data u; if (tryBind(u)) { s = QString(u.utf8()); return true; } return false; }
bool tryBind ( bool& b) { if (caching) { return caching->tryBind(b) && cacheOut(); }
if (get('t', "[{\"ntf-0123456789.") &&
......@@ -287,7 +287,7 @@ protected:
get('s') &&
get('e')) { b=false;
return true;
} else { handleError(qBindExpectedBoolean); return false; } }
} else { return false; } }
bool tryBind ( float& n) { if (caching) { return caching->tryBind(n) && cacheOut(); }
if (getNumber()==None) return false; // already reported qBindExpectedDecimal
if (d<double( std::numeric_limits<float >::min())||
......@@ -300,12 +300,12 @@ protected:
auto r=getNumber();
if (r==None) return false; // already reported qBindExpectedDecimal
if (r==FloatingPoint) { handleError(qBindExpectedInteger); return false; }
if (neg) { handleError(qBindExpectedPositiveInteger); return false; }
if (neg) { return false; }
t = i ; cachedNumber=None; return true; }
bool tryBind ( qint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
auto r=getNumber();
if (r==None) return false; // already reported qBindExpectedDecimal
if (r==FloatingPoint) { handleError(qBindExpectedInteger); return false; }
if (r==FloatingPoint) { return false; }
if (!neg && i<quint64( std::numeric_limits<qint64>::max()) ) { t = qint64(i); cachedNumber=None; return true; }
if ( neg && i<quint64(-std::numeric_limits<qint64>::max())-1) { t = -qint64(i); cachedNumber=None; return true; }
handleError(qBindExpectedSmallerNumber); return false; }
......
......@@ -194,7 +194,7 @@ protected:
: 0;
}
inline bool write(QVariant v) { m->setData(current(), v); return true; }
inline QVariant read() { return m-> data(current()); } // TODO Handle Undefined ?
inline QVariant read() { return m-> data(current()); }
QAbstractItemModel* m;
bool rowFirst;
......
......@@ -121,26 +121,26 @@ protected:
template<typename T>
bool tryBind(T& t) { return set(t, "Expected declared metatype T"); }
bool tryBind(QUtf8Data& t) { return set(t, qBindExpectedText ); }
bool tryBind( QString& t) { return set(t, qBindExpectedText ); }
bool tryBind( bool& t) { return set(t, qBindExpectedBoolean); }
bool tryBind( QByteArray& t) { return set(t, qBindExpectedBytes ); }
bool tryBind( QUtf8Data& t) { return set(t); }
bool tryBind( QString& t) { return set(t); }
bool tryBind( bool& t) { return set(t); }
bool tryBind( QByteArray& t) { return set(t); }
// Convert numerical types to strictly larger ones // TODO convert all compatible values
bool tryBind( qint8& t) { return set(t, qBindExpectedInteger ); }
bool tryBind( qint16& t) { return set(t, qBindExpectedInteger ); }
bool tryBind( qint32& t) { return set(t, qBindExpectedInteger ); }
bool tryBind( qint64& t) { return set(t, qBindExpectedInteger ); }
bool tryBind( quint8& t) { return set(t, qBindExpectedPositiveInteger); }
bool tryBind( quint16& t) { return set(t, qBindExpectedPositiveInteger); }
bool tryBind( quint32& t) { return set(t, qBindExpectedPositiveInteger); }
bool tryBind( quint64& t) { return set(t, qBindExpectedPositiveInteger); }
bool tryBind( float& t) { return set(t, qBindExpectedDecimal ); }
bool tryBind( double& t) { return set(t, qBindExpectedDecimal ); }
bool trySequence(quint32* =nullptr) { if (levels.last().isGroup) { levels.push(Level( )); return true; } handleError(qBindExpectedSequence); return false; }
bool tryRecord (quint32* =nullptr) { if (levels.last().isGroup) { levels.push(Level(qBindExpectedItem)); return true; } handleError(qBindExpectedRecord ); return false; }
bool tryNull() { if ( settings->value(key()).isNull ()) { return true; } handleError(qBindExpectedNull); return false; }
bool tryBind( qint8& t) { return set(t); }
bool tryBind( qint16& t) { return set(t); }
bool tryBind( qint32& t) { return set(t); }
bool tryBind( qint64& t) { return set(t); }
bool tryBind( quint8& t) { return set(t); }
bool tryBind( quint16& t) { return set(t); }
bool tryBind( quint32& t) { return set(t); }
bool tryBind( quint64& t) { return set(t); }
bool tryBind( float& t) { return set(t); }
bool tryBind( double& t) { return set(t); }
bool trySequence(quint32* =nullptr) { if (levels.last().isGroup) { levels.push(Level( )); return true; } return false; }
bool tryRecord (quint32* =nullptr) { if (levels.last().isGroup) { levels.push(Level(qBindExpectedItem)); return true; } return false; }
bool tryNull() { return settings->value(key()).isNull(); }
bool tryItem(QIdentifier& k) { levels.last().key=k ; return true; }
bool tryItem( ) { levels.last().idx++ ; return true; }
......@@ -148,10 +148,10 @@ protected:
bool tryAny() { return true; }
bool isValid() const noexcept { return settings; }
bool handleError(QIdentifierLiteral e, QString context = QString()) const { return errorHandler ? errorHandler(e, QString("at %1 %2").arg(currentPath(), context)) : false; }
bool handleError(QIdentifierLiteral e, QString context = QString()) const { return errorHandler && errorHandler(e, QString("at %1 %2").arg(currentPath(), context)); }
private:
template<typename T>
bool set(T& t, QIdentifierLiteral error) { QVariant v = settings->value(key()); if (v.convert(qMetaTypeId<T>())) { t = v.value<T>(); return true; } handleError(error); return false; }
bool set(T& t) { QVariant v = settings->value(key()); if (v.convert(qMetaTypeId<T>())) { t = v.value<T>(); return true; } return false; }
QString key() {
Q_ASSERT(!levels.isEmpty());
return !levels.last().key.isNull()
......
This diff is collapsed.
......@@ -137,39 +137,39 @@ protected:
bool tryBind(T& t) { if (current()->type()==qMetaTypeId<T>()) { t = current()->value<T>(); return true; } handleError(QIdentifierLiteral("ExpectedDeclaredMetatypeT")); return false; }
bool tryBind( QUtf8Data& t) { if (current()->userType() // TODO ->type() if QUtf8Data lands into Qt
==qMetaTypeId< QUtf8Data>()) { t = current()->value< QUtf8Data>(); return true; } handleError(qBindExpectedText ); return false; }
bool tryBind( QString& t) { if (current()->type()==qMetaTypeId< QString>()) { t = current()->value< QString>(); return true; } handleError(qBindExpectedText ); return false; }
bool tryBind( bool& t) { if (current()->type()==qMetaTypeId< bool>()) { t = current()->value< bool>(); return true; } handleError(qBindExpectedBoolean ); return false; }
bool tryBind(QByteArray& t) { if (current()->type()==qMetaTypeId<QByteArray>()) { t = current()->value<QByteArray>(); return true; } handleError(qBindExpectedBytes ); return false; }
==qMetaTypeId< QUtf8Data>()) { t = current()->value< QUtf8Data>(); return true; } return false; }
bool tryBind( QString& t) { if (current()->type()==qMetaTypeId< QString>()) { t = current()->value< QString>(); return true; } return false; }
bool tryBind( bool& t) { if (current()->type()==qMetaTypeId< bool>()) { t = current()->value< bool>(); return true; } return false; }
bool tryBind(QByteArray& t) { if (current()->type()==qMetaTypeId<QByteArray>()) { t = current()->value<QByteArray>(); return true; } return false; }
// Convert numerical types to strictly larger ones // TODO convert all compatible values
bool tryBind( qint8& t) { if (current()->type()==qMetaTypeId< qint8>()) { t = current()->value< qint8>(); return true; } handleError(qBindExpectedInteger ); return false; }
bool tryBind( qint8& t) { if (current()->type()==qMetaTypeId< qint8>()) { t = current()->value< qint8>(); return true; } return false; }
bool tryBind( qint16& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()) { t = current()->value< qint16>(); return true; } handleError(qBindExpectedInteger ); return false; }
current()->type()==qMetaTypeId< qint16>()) { t = current()->value< qint16>(); return true; } return false; }
bool tryBind( qint32& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()||
current()->type()==qMetaTypeId< qint32>()) { t = current()->value< qint32>(); return true; } handleError(qBindExpectedInteger ); return false; }
current()->type()==qMetaTypeId< qint32>()) { t = current()->value< qint32>(); return true; } return false; }
bool tryBind( qint64& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()||
current()->type()==qMetaTypeId< qint32>()||
current()->type()==qMetaTypeId< qint64>()) { t = current()->value< qint64>(); return true; } handleError(qBindExpectedInteger ); return false; }
bool tryBind( quint8& t) { if (current()->type()==qMetaTypeId< quint8>()) { t = current()->value< quint8>(); return true; } handleError(qBindExpectedPositiveInteger); return false; }
current()->type()==qMetaTypeId< qint64>()) { t = current()->value< qint64>(); return true; } return false; }
bool tryBind( quint8& t) { if (current()->type()==qMetaTypeId< quint8>()) { t = current()->value< quint8>(); return true; } return false; }
bool tryBind( quint16& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()) { t = current()->value< quint16>(); return true; } handleError(qBindExpectedPositiveInteger); return false; }
current()->type()==qMetaTypeId< quint16>()) { t = current()->value< quint16>(); return true; } return false; }
bool tryBind( quint32& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()||
current()->type()==qMetaTypeId< quint32>()) { t = current()->value< quint32>(); return true; } handleError(qBindExpectedPositiveInteger); return false; }
current()->type()==qMetaTypeId< quint32>()) { t = current()->value< quint32>(); return true; } return false; }
bool tryBind( quint64& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()||
current()->type()==qMetaTypeId< quint32>()||
current()->type()==qMetaTypeId< quint64>()) { t = current()->value< quint64>(); return true; } handleError(qBindExpectedPositiveInteger); return false; }
bool tryBind( float& t) { if (current()->type()==qMetaTypeId< float>()) { t = current()->value< float>(); return true; } handleError(qBindExpectedDecimal ); return false; }
current()->type()==qMetaTypeId< quint64>()) { t = current()->value< quint64>(); return true; } return false; }
bool tryBind( float& t) { if (current()->type()==qMetaTypeId< float>()) { t = current()->value< float>(); return true; } return false; }
bool tryBind( double& t) { if (current()->type()==qMetaTypeId< float>()||
current()->type()==qMetaTypeId< double>()) { t = current()->value< double>(); return true; } handleError(qBindExpectedDecimal ); return false; }
current()->type()==qMetaTypeId< double>()) { t = current()->value< double>(); return true; } return false; }
bool trySequence(quint32* =nullptr) { if (current()->type()==QVariant::List ) { levels.push(Level()); return true; } handleError(qBindExpectedSequence); return false; }
bool tryRecord (quint32* =nullptr) { if (current()->type()==QVariant::Map ) { levels.push(Level()); return true; } handleError(qBindExpectedRecord ); return false; }
bool trySequence(quint32* =nullptr) { if (current()->type()==QVariant::List ) { levels.push(Level()); return true; } return false; }
bool tryRecord (quint32* =nullptr) { if (current()->type()==QVariant::Map ) { levels.push(Level()); return true; } return false; }
bool tryNull() { if ( current()->isNull ()) { return true; } handleError(qBindExpectedNull ); return false; }
bool tryNull() { return current()->isNull(); }
bool tryItem(QIdentifier& k) { levels.last().key=k; return (levels.last().item = current(1)->toMap ().value(QString(levels.last().key.latin1()), QVariant())).isValid(); }
bool tryItem( ) { levels.last().idx++; return (levels.last().item = current(1)->toList().value( levels.last().idx , QVariant())).isValid(); }
......