Commit 975bdfa4 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

Renaming _isOk > isValid

parent 99d363dc
...@@ -112,7 +112,7 @@ public: ...@@ -112,7 +112,7 @@ public:
/**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); } /**/ QSequence sequence(quint32* s=nullptr) { return QValueStatus(this).value().sequence(s); }
template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); } template<typename T> QValueStatus bind ( T&& t) { return QValueStatus(this).value().bind(std::forward<T>(t)); }
protected: protected:
bool _isOk() const noexcept { return io; } bool isValid() const noexcept { return io; }
bool trySequence(quint32* rows=nullptr) { levels.push_back(rows); bool trySequence(quint32* rows=nullptr) { levels.push_back(rows);
if (Q_LIKELY(rows)) { putInteger (*rows , cbor::ArrayType); } if (Q_LIKELY(rows)) { putInteger (*rows , cbor::ArrayType); }
...@@ -264,7 +264,7 @@ protected: ...@@ -264,7 +264,7 @@ protected:
bool tryItem( ) { steps.last().idx++; return !(steps.last().item = current(1).toArray(). at(steps.last().idx )).isUndefined(); } bool tryItem( ) { steps.last().idx++; return !(steps.last().item = current(1).toArray(). at(steps.last().idx )).isUndefined(); }
bool tryOut ( ) { steps.pop() ; return true; } bool tryOut ( ) { steps.pop() ; return true; }
bool _isOk() const noexcept { return cbor; } bool isValid() const noexcept { return cbor; }
void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString(currentPath().latin1()).append(context)); } void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString(currentPath().latin1()).append(context)); }
private: private:
const QCborValue& current(int outer=0) const { Q_ASSERT(0<=outer); return steps.size()-outer <= 0 ? *cbor : steps[steps.size()-outer-1].item; } const QCborValue& current(int outer=0) const { Q_ASSERT(0<=outer); return steps.size()-outer <= 0 ? *cbor : steps[steps.size()-outer-1].item; }
...@@ -419,7 +419,7 @@ protected: ...@@ -419,7 +419,7 @@ protected:
return leaveContainer(); } return leaveContainer(); }
bool tryAny() { return next(); } bool tryAny() { return next(); }
bool _isOk() const noexcept { return const_cast<QCborReader*>(this)->lastError()==QCborError::NoError; } bool isValid() const noexcept { return const_cast<QCborReader*>(this)->lastError()==QCborError::NoError; }
void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString("at index:%1 ").arg(currentOffset()).append(context)); } void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString("at index:%1 ").arg(currentOffset()).append(context)); }
private: private:
void skipTag() { if (isTag()) next(); } void skipTag() { if (isTag()) next(); }
......
...@@ -89,7 +89,7 @@ protected: ...@@ -89,7 +89,7 @@ protected:
bool tryBind ( QByteArray&& t) { *io << t; return true; } bool tryBind ( QByteArray&& t) { *io << t; return true; }
bool tryBind ( QVariant&& t) { *io << t; return true; } bool tryBind ( QVariant&& t) { *io << t; return true; }
bool _isOk() const noexcept { return io && io->status()==QDataStream::Ok; } bool isValid() const noexcept { return io && io->status()==QDataStream::Ok; }
bool tryOut ( ) { return true; } bool tryOut ( ) { return true; }
bool tryItem( ) { return true; } bool tryItem( ) { return true; }
......
...@@ -136,7 +136,7 @@ protected: ...@@ -136,7 +136,7 @@ protected:
bool tryItem( ) { steps.last().idx++; return !(steps.last().item = current(1).toArray (). at(steps.last().idx )).isUndefined(); } bool tryItem( ) { steps.last().idx++; return !(steps.last().item = current(1).toArray (). at(steps.last().idx )).isUndefined(); }
bool tryOut ( ) { steps.removeLast(); return true; } bool tryOut ( ) { steps.removeLast(); return true; }
bool _isOk() const noexcept { return true; } bool isValid() const noexcept { return true; }
void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString(currentPath().latin1()).append(context)); } void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString(currentPath().latin1()).append(context)); }
private: private:
const QJsonValue& current(int outer=0) const { Q_ASSERT(0<=outer && json); return steps.size()-outer <= 0 ? *json : steps[steps.size()-outer-1].item; } const QJsonValue& current(int outer=0) const { Q_ASSERT(0<=outer && json); return steps.size()-outer <= 0 ? *json : steps[steps.size()-outer-1].item; }
...@@ -374,7 +374,7 @@ protected: ...@@ -374,7 +374,7 @@ protected:
level.index++; level.index++;
return true; } return true; }
bool _isOk() const noexcept { return io; } bool isValid() const noexcept { return io; }
void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString("at (%1,%2) ").arg(line).arg(column).append(context)); } void reportError(QIdentifierLiteral e, QString context = QString()) { if (errorHandler) errorHandler(e, QString("at (%1,%2) ").arg(line).arg(column).append(context)); }
private: private:
CachedNumber getNumber() { CachedNumber getNumber() {
......
...@@ -229,7 +229,7 @@ public: ...@@ -229,7 +229,7 @@ public:
QModelWriter(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), w(&ba) {} QModelWriter(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), w(&ba) {}
virtual QValueMode mode() const noexcept { return QValueMode::Write; } virtual QValueMode mode() const noexcept { return QValueMode::Write; }
virtual bool _isOk() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc. virtual bool isValid() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc.
protected: protected:
virtual bool tryOut() { virtual bool tryOut() {
d--; d--;
...@@ -418,7 +418,7 @@ public: ...@@ -418,7 +418,7 @@ public:
QModelReader(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), r(&io) { io.open(QIODevice::ReadOnly); } QModelReader(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), r(&io) { io.open(QIODevice::ReadOnly); }
virtual QValueMode mode() const noexcept { return QValueMode::Read; } virtual QValueMode mode() const noexcept { return QValueMode::Read; }
virtual bool _isOk() const noexcept { return true; } //!< Read status ignored by default (QAbstractItemModel is not sequential) virtual bool isValid() const noexcept { return true; } //!< Read status ignored by default (QAbstractItemModel is not sequential)
protected: protected:
virtual bool tryOut() { virtual bool tryOut() {
if (I<=d) { if (I<=d) {
......
...@@ -135,7 +135,7 @@ protected: ...@@ -135,7 +135,7 @@ protected:
bool tryItem( ) { levels.last().idx++ ; return true; } bool tryItem( ) { levels.last().idx++ ; return true; }
bool tryOut ( ) { levels.pop(); settings->endGroup(); return true; } bool tryOut ( ) { levels.pop(); settings->endGroup(); return true; }
bool _isOk() const noexcept { return settings; } bool isValid() const noexcept { return settings; }
void reportError(QIdentifierLiteral error, QString context = QString()) { if (errorHandler) errorHandler(error, QString(currentPath().latin1()).append(context)); } void reportError(QIdentifierLiteral error, QString context = QString()) { if (errorHandler) errorHandler(error, QString(currentPath().latin1()).append(context)); }
private: private:
template<typename T> template<typename T>
......
...@@ -154,7 +154,7 @@ struct QAbstractValue { ...@@ -154,7 +154,7 @@ struct QAbstractValue {
virtual QValueMode mode() const noexcept = 0; //!< \remark a static constexpr QValueMode Mode did not exhibit noticeable performance improvements and may trigger twice more code generation for Read/Write independant QTransmogrifier like Person::bind virtual QValueMode mode() const noexcept = 0; //!< \remark a static constexpr QValueMode Mode did not exhibit noticeable performance improvements and may trigger twice more code generation for Read/Write independant QTransmogrifier like Person::bind
virtual bool _isOk() const noexcept = 0; //!< Current operation status virtual bool isValid() const noexcept = 0; //!< Current operation status
virtual bool trySequence(quint32* size=nullptr) = 0; virtual bool trySequence(quint32* size=nullptr) = 0;
virtual bool tryRecord (quint32* size=nullptr) = 0; virtual bool tryRecord (quint32* size=nullptr) = 0;
...@@ -262,7 +262,7 @@ public: ...@@ -262,7 +262,7 @@ public:
explicit QValueStatus(QAbstractValue* i) : impl(i) { Q_ASSERT(impl); } explicit QValueStatus(QAbstractValue* i) : impl(i) { Q_ASSERT(impl); }
QValueMode mode() const noexcept { return impl ? impl->mode() : QValueMode::Invalid; } QValueMode mode() const noexcept { return impl ? impl->mode() : QValueMode::Invalid; }
operator bool() const noexcept { return impl && impl->_isOk(); } //!< Drives QTransmogrifier<T>::bind() traversal operator bool() const noexcept { return impl && impl->isValid(); } //!< Drives QTransmogrifier<T>::bind() traversal
QValueStatus* operator ->() noexcept { return this; } QValueStatus* operator ->() noexcept { return this; }
QVal<QValueStatus> value() noexcept ; QVal<QValueStatus> value() noexcept ;
...@@ -517,7 +517,7 @@ struct QAbstractValueWriter : public QAbstractValue ...@@ -517,7 +517,7 @@ struct QAbstractValueWriter : public QAbstractValue
virtual QValueMode mode() const noexcept { return QValueMode::Write; } virtual QValueMode mode() const noexcept { return QValueMode::Write; }
virtual bool _isOk() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc. virtual bool isValid() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc.
virtual bool tryItem( ) = 0; virtual bool tryItem( ) = 0;
virtual bool tryItem(QIdentifier& n) = 0; virtual bool tryItem(QIdentifier& n) = 0;
......
...@@ -144,27 +144,27 @@ protected: ...@@ -144,27 +144,27 @@ protected:
// Convert numerical types to strictly larger ones // TODO convert all compatible values // 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; } reportError(qBindExpectedInteger ); return false; } bool tryBind( qint8& t) { if (current()->type()==qMetaTypeId< qint8>()) { t = current()->value< qint8>(); return true; } reportError(qBindExpectedInteger ); return false; }
bool tryBind( qint16& t) { if (current()->type()==qMetaTypeId< qint8>()|| bool tryBind( qint16& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()) { t = current()->value< qint16>(); return true; } reportError(qBindExpectedInteger ); return false; } current()->type()==qMetaTypeId< qint16>()) { t = current()->value< qint16>(); return true; } reportError(qBindExpectedInteger ); return false; }
bool tryBind( qint32& t) { if (current()->type()==qMetaTypeId< qint8>()|| bool tryBind( qint32& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()|| current()->type()==qMetaTypeId< qint16>()||
current()->type()==qMetaTypeId< qint32>()) { t = current()->value< qint32>(); return true; } reportError(qBindExpectedInteger ); return false; } current()->type()==qMetaTypeId< qint32>()) { t = current()->value< qint32>(); return true; } reportError(qBindExpectedInteger ); return false; }
bool tryBind( qint64& t) { if (current()->type()==qMetaTypeId< qint8>()|| bool tryBind( qint64& t) { if (current()->type()==qMetaTypeId< qint8>()||
current()->type()==qMetaTypeId< qint16>()|| current()->type()==qMetaTypeId< qint16>()||
current()->type()==qMetaTypeId< qint32>()|| current()->type()==qMetaTypeId< qint32>()||
current()->type()==qMetaTypeId< qint64>()) { t = current()->value< qint64>(); return true; } reportError(qBindExpectedInteger ); return false; } current()->type()==qMetaTypeId< qint64>()) { t = current()->value< qint64>(); return true; } reportError(qBindExpectedInteger ); return false; }
bool tryBind( quint8& t) { if (current()->type()==qMetaTypeId< quint8>()) { t = current()->value< quint8>(); return true; } reportError(qBindExpectedPositiveInteger); return false; } bool tryBind( quint8& t) { if (current()->type()==qMetaTypeId< quint8>()) { t = current()->value< quint8>(); return true; } reportError(qBindExpectedPositiveInteger); return false; }
bool tryBind( quint16& t) { if (current()->type()==qMetaTypeId< quint8>()|| bool tryBind( quint16& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()) { t = current()->value< quint16>(); return true; } reportError(qBindExpectedPositiveInteger); return false; } current()->type()==qMetaTypeId< quint16>()) { t = current()->value< quint16>(); return true; } reportError(qBindExpectedPositiveInteger); return false; }
bool tryBind( quint32& t) { if (current()->type()==qMetaTypeId< quint8>()|| bool tryBind( quint32& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()|| current()->type()==qMetaTypeId< quint16>()||
current()->type()==qMetaTypeId< quint32>()) { t = current()->value< quint32>(); return true; } reportError(qBindExpectedPositiveInteger); return false; } current()->type()==qMetaTypeId< quint32>()) { t = current()->value< quint32>(); return true; } reportError(qBindExpectedPositiveInteger); return false; }
bool tryBind( quint64& t) { if (current()->type()==qMetaTypeId< quint8>()|| bool tryBind( quint64& t) { if (current()->type()==qMetaTypeId< quint8>()||
current()->type()==qMetaTypeId< quint16>()|| current()->type()==qMetaTypeId< quint16>()||
current()->type()==qMetaTypeId< quint32>()|| current()->type()==qMetaTypeId< quint32>()||
current()->type()==qMetaTypeId< quint64>()) { t = current()->value< quint64>(); return true; } reportError(qBindExpectedPositiveInteger); return false; } current()->type()==qMetaTypeId< quint64>()) { t = current()->value< quint64>(); return true; } reportError(qBindExpectedPositiveInteger); return false; }
bool tryBind( float& t) { if (current()->type()==qMetaTypeId< float>()) { t = current()->value< float>(); return true; } reportError(qBindExpectedDecimal ); return false; } bool tryBind( float& t) { if (current()->type()==qMetaTypeId< float>()) { t = current()->value< float>(); return true; } reportError(qBindExpectedDecimal ); return false; }
bool tryBind( double& t) { if (current()->type()==qMetaTypeId< float>()|| bool tryBind( double& t) { if (current()->type()==qMetaTypeId< float>()||
current()->type()==qMetaTypeId< double>()) { t = current()->value< double>(); return true; } reportError(qBindExpectedDecimal ); return false; } current()->type()==qMetaTypeId< double>()) { t = current()->value< double>(); return true; } reportError(qBindExpectedDecimal ); return false; }
bool trySequence(quint32* =nullptr) { if (current()->type()==QVariant::List ) { levels.push(Level()); return true; } reportError(qBindExpectedSequence); return false; } bool trySequence(quint32* =nullptr) { if (current()->type()==QVariant::List ) { levels.push(Level()); return true; } reportError(qBindExpectedSequence); return false; }
bool tryRecord (quint32* =nullptr) { if (current()->type()==QVariant::Map ) { levels.push(Level()); return true; } reportError(qBindExpectedRecord ); return false; } bool tryRecord (quint32* =nullptr) { if (current()->type()==QVariant::Map ) { levels.push(Level()); return true; } reportError(qBindExpectedRecord ); return false; }
...@@ -174,7 +174,7 @@ protected: ...@@ -174,7 +174,7 @@ protected:
bool tryItem( ) { levels.last().idx++; return (levels.last().item = current(1)->toList().value( levels.last().idx , QVariant())).isValid(); } bool tryItem( ) { levels.last().idx++; return (levels.last().item = current(1)->toList().value( levels.last().idx , QVariant())).isValid(); }
bool tryOut ( ) { levels.pop() ; return true; } bool tryOut ( ) { levels.pop() ; return true; }
bool _isOk() const noexcept { return value; } bool isValid() const noexcept { return value; }
void reportError(QIdentifierLiteral error, QString context = QString()) { if (errorHandler) errorHandler(error, QString(currentPath().latin1()).append(context)); } void reportError(QIdentifierLiteral error, QString context = QString()) { if (errorHandler) errorHandler(error, QString(currentPath().latin1()).append(context)); }
private: private:
const QVariant* current(unsigned outer=0) const { return unsigned(levels.size())-outer <= 0 ? value : &(levels[unsigned(levels.size())-outer-1].item); } const QVariant* current(unsigned outer=0) const { return unsigned(levels.size())-outer <= 0 ? value : &(levels[unsigned(levels.size())-outer-1].item); }
......
...@@ -85,7 +85,7 @@ protected: ...@@ -85,7 +85,7 @@ protected:
bool tryBind ( double&& n) { static QString s; s.setNum( n ,'g',std::numeric_limits<double>::max_digits10); writeText("decimal" , s); return true; } // with specific precision bool tryBind ( double&& n) { static QString s; s.setNum( n ,'g',std::numeric_limits<double>::max_digits10); writeText("decimal" , s); return true; } // with specific precision
bool tryBind ( QByteArray&& s) { QString h; h.reserve(s.size()*2+2+1); h.append("0x").append(s.toHex().toUpper()) ; writeText("hexBinary", h); return true; } bool tryBind ( QByteArray&& s) { QString h; h.reserve(s.size()*2+2+1); h.append("0x").append(s.toHex().toUpper()) ; writeText("hexBinary", h); return true; }
bool _isOk() const noexcept { return !io->hasError(); } bool isValid() const noexcept { return !io->hasError(); }
bool tryOut ( ) { io->writeEndElement(); return true; } bool tryOut ( ) { io->writeEndElement(); return true; }
bool tryItem( ) { return true; } bool tryItem( ) { return true; }
......
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