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

WIP More precise error handling

parent ff51bf75
......@@ -199,9 +199,9 @@ 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) { Q_UNUSED(isErrorFiltered(qBindExpectedSmallerNumber)); return false; }
set(QCborValue(qint64(n))); return true; }
bool tryBind ( double&& d) { set(QCborValue( d )); return true; }
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; }
......@@ -329,10 +329,10 @@ protected:
bool tryBind ( double& n) { if (caching) { return caching->tryBind(n) && cacheOut(); }
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; }
n=float(d); return true; }
if (!tryBind(d)) { return false; }
if (d<double(std::numeric_limits<float>::min()) ) { Q_ASSERT(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_ASSERT(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(); }
skipTag();
......@@ -340,10 +340,11 @@ protected:
t=toUnsignedInteger(); return true; }
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 (!getInteger(i,neg)) { return false; }
if ( neg && quint64(std::numeric_limits<qint64>::max())+1<i) { Q_ASSERT(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_ASSERT(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); }
QIdentifier s;
......
......@@ -289,25 +289,23 @@ protected:
} else { return false; } }
bool tryBind ( float& n) { if (caching) { return caching->tryBind(n) && cacheOut(); }
if (getNumber()==None) 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()) ) { 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;
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;
if (r==FloatingPoint) { Q_UNUSED(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;
if (r==FloatingPoint) { Q_UNUSED(isErrorFiltered(qBindExpectedInteger)); 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; }
Q_UNUSED(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>::min())<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);
......
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