Commit 833b8baf authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

Minor adjustments in unexpected value handling

parent cf526221
......@@ -473,9 +473,10 @@ struct QTransmogrifier<QCborValue> {
if (j.isString ()) return v.bind(j.toString ());
if (j.isByteArray()) return v.bind(j.toByteArray());
if (j.isNull ()) return v.null();
return (j.isUndefined() || v->handleError(qBindUnexpectedValue)) ? v.any() : QValueEnd();
if (j.isUndefined()) return v.any ();
return QValueEnd();
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
}
static QValueEnd zap(QValue&& v, QCborValue& j) {
if (v->mode()==Write) {
......@@ -495,7 +496,7 @@ struct QTransmogrifier<QCborValue> {
QByteArray y; if ((r = v.bind(y))) { j = QCborValue( y ); v->setErrorHandler(suspended); return r; }
/**/ if ((r = v.null( ))) { j = QCborValue( nullptr ); v->setErrorHandler(suspended); return r; }
v->setErrorHandler(suspended);
if ((r = v.any())) { j = QCborValue(); }
if ((r = v.any())) { j = QCborValue(QCborValue::Undefined); }
return r;
}
else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
......
......@@ -529,13 +529,13 @@ template<>
struct QTransmogrifier<QJsonValue> {
static QValueEnd 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 ());
if (j.isBool ()) return v.bind(j.toBool ());
if (j.isDouble()) return v.bind(j.toDouble());
if (j.isString()) return v.bind(j.toString());
if (j.isNull ()) return v.null();
if (j.isUndefined() || v->handleError(qBindUnexpectedValue)) return v.any();
if (j.isObject ()) return v.bind(j.toObject());
if (j.isArray ()) return v.bind(j.toArray ());
if (j.isBool ()) return v.bind(j.toBool ());
if (j.isDouble ()) return v.bind(j.toDouble());
if (j.isString ()) return v.bind(j.toString());
if (j.isNull ()) return v.null();
if (j.isUndefined()) return v.any ();
return QValueEnd();
}
else { Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported v->mode()"); return v.any(); }
......
......@@ -368,7 +368,7 @@ public:
Q_ENABLE_MOVE_DEFAULT(QVal)
~QVal() {
if (isValid()) {
if (outer->handleError(qBindUnexpectedEnd) && !outer->tryAny()) {
if (outer->handleError(qBindUnexpectedValue) && !outer->tryAny()) {
Q_ASSERT_X(outer->handleError(qBindBlocked), Q_FUNC_INFO, "Unhandled blocked bind");
outer.invalidate();
}
......@@ -380,12 +380,15 @@ public:
bool isValid() const noexcept { return outer.isValid(); } //!< Drives QTransmogrifier<T>::bind() traversal
QCur* operator->() noexcept { return outer.operator->(); }
operator QValueEnd() { return end(); }
QValueEnd end() { return any(); /* calls T_::operator QValueEnd() if T_ != QValueEnd */ }
/**/ T_ any() { return outer->tryAny() ? std::move(outer) : T_(); } // TODO resume suspended errorHandler
QVal<T_> meta (QIdentifierLiteral& n, QAsciiData& m) { outer->_meta(n,m); return std::move(*this); }
QSeq<T_> sequence(quint32* s=nullptr) { return outer->trySequence (s) ? QSeq<T_>(std::move(outer)) : QSeq<T_>(); }
QRec<T_> record (quint32* s=nullptr) { return outer->tryRecord (s) ? QRec<T_>(std::move(outer)) : QRec<T_>(); }
/**/ T_ null ( ) { return outer->tryNull ( ) ? std::move(outer) : T_ (); }
/**/ T_ any ( ) { return outer->tryAny ( ) ? std::move(outer) : T_ (); }
/**/ T_ bind ( const char* u) { return outer->tryBind(QUtf8DataView(u)) ? std::move(outer) : T_ (); }
/**/ T_ bind ( QUtf8DataView u) { return outer->tryBind (u) ? std::move(outer) : T_ (); }
......@@ -435,10 +438,12 @@ public:
explicit operator bool() const noexcept { return isValid(); }
bool isValid() const noexcept { return outer.isValid(); } //!< Drives QTransmogrifier<T>::bind() traversal
QCur* operator->() noexcept { return outer.operator ->(); }
operator QValueEnd() { return out(); /* calls T_::operator QValueEnd() if T_ != QValueEnd */ }
QCur* operator->() noexcept { return outer.operator->(); }
operator QValueEnd() { return end(); }
QValueEnd end() { return out(); /* calls T_::operator QValueEnd() if T_ != QValueEnd */ }
T_ out() { return outer->tryOut() ? std::move(outer) : T_(); }
/**/ T_ out() { return outer-> tryOut() ? std::move(outer) : T_ (); }
QVal<QSeq<T_>> item() { return outer->tryItem() ? QVal<QSeq<T_>>(std::move(*this)) : QVal<QSeq<T_>>(); }
// Shortcuts
......@@ -494,10 +499,12 @@ public:
explicit operator bool() const noexcept { return isValid(); }
bool isValid() const noexcept { return outer.isValid(); } //!< Drives QTransmogrifier<T>::bind() traversal
QCur* operator->() noexcept { return outer.operator ->(); }
operator QValueEnd() { return out(); /* calls T_::operator QValueEnd() if T_ != QValueEnd */ }
QCur* operator->() noexcept { return outer.operator->(); }
operator QValueEnd() { return end(); }
QValueEnd end() { return out(); /* calls T_::operator QValueEnd() if T_ != QValueEnd */ }
T_ out() { return outer->tryOut() ? std::move(outer) : T_(); }
/**/ T_ out ( ) { return outer->tryOut ( ) ? std::move(outer) : T_ (); }
QVal<QRec<T_>> item(QIdentifier& n) { return outer->tryItem( n ) ? QVal<QRec<T_>>(std::move(*this)) : QVal<QRec<T_>>(); }
QVal<QRec<T_>> item(const char* n) { return outer->tryItem(QIdentifierLiteral(n)) ? QVal<QRec<T_>>(std::move(*this)) : QVal<QRec<T_>>(); }
......
......@@ -64,7 +64,7 @@ JsonValue>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments:
Json>JsonValue|{"age":-1,"children":[],"comments":"","height":1.7500000000000004,"names":["John","Doe"],"phones":[]} |
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739fff68636f6d6d656e747360686368696c6472656e9fffff
Person-Cbor |================================================================================
Cbor>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | at 41 commentsIgnoredItem, at 41 UnexpectedEnd, at 58 UnexpectedEnd
Cbor>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | at 41 commentsIgnoredItem, at 41 UnexpectedEnd, at 58 UnexpectedValue
P>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765206670686f6e65738068636f6d6d656e747360686368696c6472656e80ff
Cbor>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] |
QCborStream>P |(Person) names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[] | true
......@@ -75,5 +75,5 @@ CborValue>Cbor|a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000
Cbor>Json |{"names":["John","Doe"],"height":1.75,"age":undefined} |
Person-Settings|================================================================================
P>Settings |(Person) names:[ John Doe] height:1.75 age:18 phones:[] comments:unicode is likely U+01  + U+1F  + U+A4 ¤ U+B0 ° U+D8 Ø U+FF ÿ children:[]
Settings>P |(Person) names:[ John Doe] height:1.75 age:18 phones:[] comments:unicode is likely U+01  + U+1F  + U+A4 ¤ U+B0 ° U+D8 Ø U+FF ÿ children:[] | at /-1/ namesIgnoredItem, at /-1/ UnexpectedEnd, at /-1 UnexpectedEnd
Settings>P |(Person) names:[ John Doe] height:1.75 age:18 phones:[] comments:unicode is likely U+01  + U+1F  + U+A4 ¤ U+B0 ° U+D8 Ø U+FF ÿ children:[] | at /-1/ namesIgnoredItem, at /-1/ UnexpectedEnd, at /-1 UnexpectedValue
P>Settings |QBind
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