...
 
Commits (6)
......@@ -200,7 +200,7 @@ protected:
bool tryBind ( bool&& b) { set(QCborValue( b )); return true; }
bool tryBind ( float&& d) { set(QCborValue(double(d))); return true; }
bool tryBind ( double&& d) { set(QCborValue( d )); return true; }
bool tryBind ( quint64&& n) { if (quint64(std::numeric_limits<qint64>::max())<n) { isErrorFiltered(qBindExpectedSmallerNumber); return false; }
bool tryBind ( quint64&& n) { if (quint64(std::numeric_limits<qint64>::max())<n) { if (isErrorFiltered(qBindExpectedSmallerNumber)) { set(QCborValue(std::numeric_limits<qint64>::max())); return true; } return false; }
set(QCborValue(qint64(n))); return true; }
bool tryBind ( qint64&& n) { set(QCborValue( n )); return true; }
bool tryBind ( QByteArray&& s) { set(QCborValue( s )); return true; }
......@@ -255,11 +255,11 @@ protected:
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; } isErrorFiltered(qBindExpectedInteger); return false; }
bool tryBind ( qint64& t) { if (current().isInteger ()) { t = current().toInteger (); return true; } 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; }
bool tryBind ( double& v) { if (current().isDouble ()) { v = current().toDouble (); return true; } isErrorFiltered(qBindExpectedDecimal); return false; }
bool tryBind ( QByteArray& v) { QString s; if (current().isByteArray()) { v = current().toByteArray(); return true; } isErrorFiltered(qBindExpectedBytes ); return false; }
bool tryBind ( double& v) { if (current().isDouble ()) { v = current().toDouble (); return true; } return false; }
bool tryBind ( QByteArray& v) { QString s; if (current().isByteArray()) { v = current().toByteArray(); return true; } return false; }
bool tryItem(QIdentifierLiteral u) { steps.last().key=u; return !(steps.last().item = current(1).toMap().value(steps.last().key.latin1())).isUndefined(); }
bool tryItem(QIdentifier& k) { steps.last().key=k; return !(steps.last().item = current(1).toMap().value(steps.last().key.latin1())).isUndefined(); }
......@@ -320,7 +320,7 @@ protected:
r = readByteArray();
}
return r.status == QCborStreamReader::EndOfString || isErrorFiltered(qBindUnexpectedData);
} else { isErrorFiltered(qBindExpectedBytes); return false; } }
} else { return false; } }
bool tryBind ( bool& b) { if (caching) { return caching->tryBind(b) && cacheOut(); }
skipTag(); if (isBool()) {
b=toBool();
......@@ -330,8 +330,8 @@ protected:
return getNumber(n); }
bool tryBind ( float& n) { double d;
if (!tryBind(d)) { return false; }
if (d<double(std::numeric_limits<float>::min()) ||
double(std::numeric_limits<float>::max()) <d) { isErrorFiltered(qBindExpectedSmallerNumber); return false; }
if (d<double(std::numeric_limits<float>::min()) ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); n=std::numeric_limits<float>::min(); return true; } // using isErrorFiltered result to return false (allowing user to bind with a larger type) would require a cachedNumber like in JSON
if ( double(std::numeric_limits<float>::max())<d) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); n=std::numeric_limits<float>::max(); return true; }
n=float(d); return true; }
bool tryBind ( quint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
......@@ -341,8 +341,9 @@ protected:
bool tryBind ( qint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
quint64 i; bool neg;
if (!getInteger(i,neg)) { return false; }
if ( neg ) { if (-quint64(std::numeric_limits<qint64>::max())-1<i) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } t=-qint64(i); return true; }
else { if ( quint64(std::numeric_limits<qint64>::max()) <i) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } t= qint64(i); return true; }
if ( neg && quint64(std::numeric_limits<qint64>::max())+1<i) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); t=std::numeric_limits<qint64>::min(); return true; } // using isErrorFiltered result to return false (allowing user to bind with a larger type) would require a cachedNumber like in JSON
if (!neg && quint64(std::numeric_limits<qint64>::max()) <i) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); t=std::numeric_limits<qint64>::max(); return true; }
t = neg ? -qint64(i) : qint64(i); return true;
}
bool tryItem( QIdentifierLiteral u) { if (caching) { return caching->tryItem(u); }
......@@ -413,12 +414,12 @@ private:
if (isFloat16()) { d = double(toFloat16()); return next(); }
if (isFloat ()) { d = double(toFloat ()); return next(); }
if (isDouble ()) { d = toDouble () ; return next(); }
isErrorFiltered(qBindExpectedDecimal); return false;
return false;
}
bool getInteger(quint64&i, bool& isNegative) { skipTag();
if (isNegativeInteger()) { i = quint64(toNegativeInteger()); isNegative = true ; return next(); }
if (isUnsignedInteger()) { i = toUnsignedInteger() ; isNegative = false; return next(); }
isErrorFiltered(qBindExpectedInteger); return false;
return false;
}
bool cacheOut() { if (!cacheLevel) {
......
......@@ -128,7 +128,7 @@ protected:
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; } isErrorFiltered(qBindExpectedDecimal ); return false; }
bool tryBind ( double& v) { if (current().isDouble()) { v = current().toDouble(); return true; } return false; }
bool tryItem(QIdentifierLiteral u) { steps.last().key=u; return !(steps.last().item = current(1).toObject().value(steps.last().key.latin1())).isUndefined(); }
bool tryItem(QIdentifier& k) { steps.last().key=k; return !(steps.last().item = current(1).toObject().value(steps.last().key.latin1())).isUndefined(); }
......@@ -288,26 +288,24 @@ protected:
return true;
} 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())||
double( std::numeric_limits<float >::max())<d) { isErrorFiltered(qBindExpectedSmallerNumber); return false; }
if (getNumber()==None) return false;
if (d<double(std::numeric_limits<float>::min()) ) { if (isErrorFiltered(qBindExpectedSmallerNumber)) { n=std::numeric_limits<float>::min(); cachedNumber=None; return true; } return false; }
if ( double(std::numeric_limits<float>::max())<d) { if (isErrorFiltered(qBindExpectedSmallerNumber)) { n=std::numeric_limits<float>::max(); cachedNumber=None; return true; } return false; }
n = float(d); cachedNumber=None; return true; }
bool tryBind ( double& n) { if (caching) { return caching->tryBind(n) && cacheOut(); }
if (getNumber()==None) return false; // already reported qBindExpectedDecimal
if (getNumber()==None) return false;
n = d ; cachedNumber=None; return true; }
bool tryBind ( quint64& t) { if (caching) { return caching->tryBind(t) && cacheOut(); }
auto r=getNumber();
if (r==None) return false; // already reported qBindExpectedDecimal
if (r==FloatingPoint) { isErrorFiltered(qBindExpectedInteger); return false; }
if (getNumber()==None) return false;
if (cachedNumber==FloatingPoint) { if (isErrorFiltered(qBindExpectedInteger)) { t=i; cachedNumber=None; return true; } 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) { 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; }
isErrorFiltered(qBindExpectedSmallerNumber); return false; }
if (getNumber()==None) return false;
if (cachedNumber==FloatingPoint) { if (isErrorFiltered(qBindExpectedInteger)) { t=i; cachedNumber=None; return true; } return false; }
if (!neg && quint64(std::numeric_limits<qint64>::max()) <i) { if (isErrorFiltered(qBindExpectedSmallerNumber)) { t=std::numeric_limits<qint64>::max(); cachedNumber=None; return true; } return false; }
if ( neg && quint64(std::numeric_limits<qint64>::max())+1<i) { if (isErrorFiltered(qBindExpectedSmallerNumber)) { t=std::numeric_limits<qint64>::min(); cachedNumber=None; return true; } return false; }
t = neg ? -qint64(i) : qint64(i); cachedNumber=None; return true; }
bool tryBind ( QVariant& dst) { if (caching) { return caching->tryBind(dst) && cacheOut(); }
{
QSuspendedValueErrorHandler(this);
......@@ -329,7 +327,7 @@ protected:
}
if (tryNull()) { dst = QVariant::fromValue(nullptr); return true; }
}
return isErrorFiltered(qBindUnexpectedValue) && tryAny();
return false;
}
bool tryOut ( ) { if (caching) { bool out = caching->tryOut(); if (out) { cacheLevel--; cacheOut(); } return out; }
......@@ -395,7 +393,6 @@ private:
neg = get('-', "[{\"ntf-0123456789.");
qint8 digit;
if ((digit = getDigit()) < 0) {
isErrorFiltered(qBindExpectedDecimal);
return None; // do not accept no digit otherwise we may accept an empty mantissa or string!
}
cachedNumber=Integer;
......@@ -537,7 +534,7 @@ struct QTransmogrifier<QJsonValue> {
if (j.isDouble ()) return v.bind(j.toDouble());
if (j.isString ()) return v.bind(j.toString());
if (j.isNull ()) return v.null();
return v;
return v.unexpected();
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
......@@ -556,7 +553,7 @@ struct QTransmogrifier<QJsonValue> {
quint64 u; if ((r = v.bind(u))) { j = QJsonValue(double(u)); return r; }
double d; if ((r = v.bind(d))) { j = QJsonValue( d ); return r; }
/**/ if ((r = v.null( ))) { j = QJsonValue( ); return r; }
return v;
return v.unexpected();
}
else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
......
......@@ -305,7 +305,7 @@ protected:
row++; col=0;
return true;
}
isErrorFiltered(qBindUnexpectedItem);
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
return false;
}
return true;
......@@ -320,7 +320,7 @@ protected:
row=0; col++;
return true;
}
isErrorFiltered(qBindUnexpectedItem);
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
return false;
}
return true;
......@@ -416,7 +416,7 @@ protected:
d--;
return hidden() || itemBind()->tryOut();
}
else { Q_ASSERT(C==d || R==d);
else { // FIXME Q_ASSERT(C==d || R==d);
d--;
if (R==d && parent.isValid()) { // case of a tree, even if hidden()
row=parent.row(); parent=parent.parent(); d=C;
......@@ -500,7 +500,7 @@ protected:
if (col < m->columnCount()) {
return true;
}
isErrorFiltered(qBindUnexpectedItem);
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
return false;
}
return true;
......@@ -518,7 +518,7 @@ protected:
row=0; col++;
return true;
}
isErrorFiltered(qBindUnexpectedItem);
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
return false;
}
return true;
......
This diff is collapsed.
......@@ -134,7 +134,7 @@ protected:
// TODO Support _meta to be able to cache and restitute all metadata as well as data+datatype
template<typename T>
bool tryBind(T& t) { if (current()->type()==qMetaTypeId<T>()) { t = current()->value<T>(); return true; } isErrorFiltered(QIdentifierLiteral("ExpectedDeclaredMetatypeT")); return false; }
bool tryBind(T& t) { if (current()->type()==qMetaTypeId<T>()) { t = current()->value<T>(); return true; } return isErrorFiltered(QIdentifierLiteral("ExpectedDeclaredMetatypeT")); }
bool tryBind( QUtf8Data& t) { if (current()->userType() // TODO ->type() if QUtf8Data lands into Qt
==qMetaTypeId< QUtf8Data>()) { t = current()->value< QUtf8Data>(); return true; } return false; }
......
......@@ -56,13 +56,13 @@ Bindable |
Bindable>Cbor |bf647479706502666e756d6265726b2b34342031323334353637ff
Bindable>Json |{"type":2,"number":"+44 1234567"}
Person-Json |================================================================================
Json>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | 0 1:UnexpectedData, 0 15:UnexpectedData, 0 23:UnexpectedData, 0 40:UnexpectedData, 0 58:UnexpectedData, 0x0000000001:ExpectedDecimal, 0 102:UnexpectedData, comments [ 0 102]:UnexpectedItem, 0 102:UnexpectedEnd, 0 103:UnexpectedValue, 0 104:Stopped
P>Json |{"names":["John","Doe"],"height":1.7500000000000002,"age":-1,"phones":[],"comments":"","children":[]}
Json>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | 0 1:UnexpectedData, 0 15:UnexpectedData, 0 23:UnexpectedData, 0 40:UnexpectedData, 0 58:UnexpectedData, 0 102:UnexpectedData, comments [ 0 102]:UnexpectedItem, 0 102:UnexpectedEnd, 0 103:UnexpectedValue, 0 104:Stopped
P>Json |{"names":["John","Doe"],"height":1.75,"age":-1,"phones":[],"comments":"","children":[]}
Json>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] |
P>JsonValue |{"age":-1,"children":[],"comments":"","height":1.7500000000000004,"names":["John","Doe"],"phones":[]}
P>JsonValue |{"age":-1,"children":[],"comments":"","height":1.75,"names":["John","Doe"],"phones":[]}
JsonValue>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] |
Json>JsonValue|{"age":-1,"children":[],"comments":"","height":1.7500000000000004,"names":["John","Doe"],"phones":[]} |
JsonValue>Json|{"age":-1,"children":[],"comments":"","height":1.7500000000000004,"names":["John","Doe"],"phones":[]}
Json>JsonValue|{"age":-1,"children":[],"comments":"","height":1.75,"names":["John","Doe"],"phones":[]} |
JsonValue>Json|{"age":-1,"children":[],"comments":"","height":1.75,"names":["John","Doe"],"phones":[]}
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739fff68636f6d6d656e747360686368696c6472656e9fffff
Person-Cbor |================================================================================
Cbor>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | comments 41:UnexpectedItem, 41:UnexpectedEnd, 58:UnexpectedValue, 58:Stopped
......