Commit 28efdf9b authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

minor changes

parent 4dd16b34
......@@ -255,7 +255,7 @@ protected:
template<class T_> friend class QRec;
void _meta (QIdentifierLiteral& n,
QAsciiData& m) { if (Q_LIKELY(impl) ) impl->_meta(n,m); } //!< idempotent (can be called by more than one code)
QAsciiData& m) { if (Q_LIKELY(impl) ) impl->_meta(n,m); } //!< idempotent (can be called by more than one code)
bool tryAny ( ) { return Q_LIKELY(impl) && impl->tryAny(); }
bool trySequence(quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->trySequence(s) || (impl->isErrorFiltered(qBindExpectedSequence ) && impl->tryAny())); }
bool tryRecord (quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->tryRecord (s) || (impl->isErrorFiltered(qBindExpectedRecord ) && impl->tryAny())); }
......@@ -551,25 +551,26 @@ public:
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_>>(); }
QVal<QRec<T_>> item(QIdentifier& n) { return outer->tryItem(n) || (outer->isErrorFiltered(qBindUnexpectedItem, n.latin1()) && false) ? QVal<QRec<T_>>(std::move(*this)) : QVal<QRec<T_>>(); }
QVal<QRec<T_>> item(QIdentifierLiteral n) { return outer->tryItem(n) || (outer->isErrorFiltered(qBindUnexpectedItem, n.latin1()) && false) ? QVal<QRec<T_>>(std::move(*this)) : QVal<QRec<T_>>(); }
QVal<QRec<T_>> item(const char* n) { return item(QIdentifierLiteral(n)); }
// Shortcuts
QSeq<QRec<T_>> sequence(const char* n, quint32* s=nullptr) { auto i = item(n); if (i) { return i.sequence (s) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QSeq<QRec<T_>>(); }
QRec<QRec<T_>> record (const char* n, quint32* s=nullptr) { auto i = item(n); if (i) { return i.record (s) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<QRec<T_>>(); }
/**/ QRec<T_> null (const char* n ) { auto i = item(n); if (i) { return i.null ( ) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, const char* u) { auto i = item(n); if (i) { return i.bind(QUtf8DataView(u)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, QUtf8DataView u) { auto i = item(n); if (i) { return i.bind (u) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, QAsciiDataView a) { auto i = item(n); if (i) { return i.bind (a) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, QLatin1String l) { auto i = item(n); if (i) { return i.bind (l) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, QStringView u) { auto i = item(n); if (i) { return i.bind (u) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
template<typename T> QRec<T_> bind(const char* n, T&& t ) { auto i = item(n); if (i) { return i.bind( std::forward<T>( t)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> bind(const char* n, T& t, T&& defaultT) { auto i = item(n); if (i) { return i.bind(t, std::forward<T>(defaultT)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
QSeq<QRec<T_>> sequence(const char* n, quint32* s=nullptr) { return item(n).sequence (s) ; }
QRec<QRec<T_>> record (const char* n, quint32* s=nullptr) { return item(n).record (s) ; }
/**/ QRec<T_> null (const char* n ) { return item(n).null ( ) ; }
/**/ QRec<T_> bind (const char* n, const char* u) { return item(n).bind(QUtf8DataView(u)); }
/**/ QRec<T_> bind (const char* n, QUtf8DataView u) { return item(n).bind (u) ; }
/**/ QRec<T_> bind (const char* n, QAsciiDataView a) { return item(n).bind (a) ; }
/**/ QRec<T_> bind (const char* n, QLatin1String l) { return item(n).bind (l) ; }
/**/ QRec<T_> bind (const char* n, QStringView u) { return item(n).bind (u) ; }
template<typename T> QRec<T_> bind(const char* n, T&& t ) { return item(n).bind( std::forward<T>( t)); }
template<typename T> QRec<T_> bind(const char* n, T& t, T&& defaultT) { return item(n).bind(t, std::forward<T>(defaultT)); }
// Custom bind support
/**/ QRec<T_> with(const char* n, QValLambda customBind) { auto i = item(n); if (i) { return i.with( customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> with(const char* n, T& t, QValFunction<T> customBind) { auto i = item(n); if (i) { return i.bind(t, customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
/**/ QRec<T_> with(const char* n, QValLambda customBind) { return item(n).with( customBind); }
template<typename T> QRec<T_> with(const char* n, T& t, QValFunction<T> customBind) { return item(n).bind(t, customBind); }
private:
template<class T> friend class QVal;
explicit QRec(T_&& out) noexcept { outer = std::move(out); }
......@@ -1267,8 +1268,8 @@ struct QTransmogrifier<QValue> {
if (src->mode()==Read && dst->mode()==Write) {
src.setIsVariant();
QSequence srcSeq; QSequence dstSeq;
if ( (srcSeq = src.sequence())) {
/**/ dstSeq = dst.sequence();
if ( (srcSeq = src.sequence())) {
/**/ dstSeq = dst.sequence();
QValue srcVal; QValue dstVal;
while((srcVal = srcSeq.unsafeItem())) { // using item()'s QVal<QSequence would cause an infinite compiler loop to generate corresponding QTransmogrifier<QVal<QSeq<QSeq<...>>,_> functions
......@@ -1276,12 +1277,12 @@ struct QTransmogrifier<QValue> {
srcVal.bind(std::move(dstVal));
}
/**/ dstSeq.out();
return srcSeq.out();
Q_UNUSED(dstSeq.out())
return srcSeq.out();
}
QRecord srcRec; QRecord dstRec;
if ( (srcRec = src.record())) {
/**/ dstRec = dst.record();
if ( (srcRec = src.record())) {
/**/dstRec = dst.record();
QIdentifier srcKey; QValue srcVal; QValue dstVal;
while((srcVal = srcRec.unsafeItem(srcKey))) {
......@@ -1289,8 +1290,8 @@ struct QTransmogrifier<QValue> {
srcVal.bind(std::move(dstVal));
}
/**/ dstRec.out();
return srcRec.out();
Q_UNUSED(dstRec.out())
return srcRec.out();
}
QValueEnd srcEnd;
QUtf8Data u; if ((srcEnd = src.bind( u))) { dst.bind( u); return srcEnd; } //! \remark QUtf8Data has common valus with QString but is more precise and efficient
......@@ -1312,8 +1313,8 @@ struct QTransmogrifier<QValue> {
double d; if ((srcEnd = src.bind( d))) { dst.bind( d); return srcEnd; } //! \remark Double-precision floating point numeric types can only be handled if QAbstractValue refuses to lose leading digits or precision
// TODO Other BindNative types we do not want to treat as text: QDateTime, QUuid
/**/ if ((srcEnd = src.null( ))) { dst.null( ); return srcEnd; }
if (src->isErrorFiltered(qBindUnexpectedValue) && (srcEnd = src.any())) { dst.any(); return srcEnd; }
return src.unexpected();
Q_UNUSED(dst.unexpected())
return src.unexpected();
}
else if (src->mode()==Write && dst->mode()==Read) { return zap(std::move(dst),std::move(src)); } // To return reader's QCur instead of writer's QCur since it should contain more information (mismatches, etc.)
else { Q_ASSERT_X(!src || !dst, Q_FUNC_INFO, "Unsupported src->mode() and dst->mode()"); return src.null(); }
......
......@@ -136,7 +136,7 @@ protected:
template<typename T>
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
bool tryBind( QUtf8Data& t) { if (current()->userType()
==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; }
......
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