Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit dde28216 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Fixed bugs with numeric types

Replaced QWriter+QReader with Cur<>
parent 5ed6be04
......@@ -172,10 +172,10 @@ public:
/**/ Val<T_> meta ( QMetaData& m) { outer->_meta(m); return std::move(*this); }
// TODO ? Add bind with default T specialised for Reader/Writer
/**/ Seq<T_> sequence(quint32* s=nullptr) { return outer->_sequence ( s) ? Seq<T_>(std::move(outer)) : Seq<T_>(); }
/**/ Rec<T_> record (quint32* s=nullptr) { return outer->_record ( s) ? Rec<T_>(std::move(outer)) : Rec<T_>(); }
/**/ T_ null ( ) { return outer->_null ( ) ? std::move(outer) : T_ (); }
/**/ T_ any ( ) { return outer->_any( ) ? std::move(outer) : T_ (); }
/**/ Seq<T_> sequence(quint32* s=nullptr) { return outer->_sequence (s) ? Seq<T_>(std::move(outer)) : Seq<T_>(); }
/**/ Rec<T_> record (quint32* s=nullptr) { return outer->_record (s) ? Rec<T_>(std::move(outer)) : Rec<T_>(); }
/**/ T_ null ( ) { return outer->_null ( ) ? std::move(outer) : T_ (); }
/**/ T_ any ( ) { return outer->_any ( ) ? std::move(outer) : T_ (); }
template<typename T> T_ bind ( T&& t) { return outer->_bind(std::forward<T>(t)) ? std::move(outer) : T_ (); }
// Literal metadata support
......@@ -194,7 +194,7 @@ public:
Seq(T_&& out) { std::swap(outer, out); }
// T_ can be either a TResult or any combination of nested Seq or Rec like Rec<Seq<TResult>
using TResult = typename T_::TResult; //!< Start and end point of the traversal as well as the associated processing (see QWriter for an example)
using TResult = typename T_::TResult;
operator bool() { return outer.operator bool(); } //!< Drives QBind<TResult,T>() traversal
TResult* operator->() { return outer.operator ->(); }
......@@ -227,7 +227,7 @@ public:
Rec(T_&& out) { std::swap(outer, out); }
// T_ can be either a TResult or any combination of nested Seq or Rec like Seq<Rec<TResult>
using TResult = typename T_::TResult; //!< the start and end point of the traversal as well as the associated processing (see QJsonWriter for an example)
using TResult = typename T_::TResult;
operator bool() { return outer.operator bool(); } //!< Drives QBind<TResult,T>() traversal
TResult* operator->() { return outer.operator ->(); }
......@@ -252,11 +252,14 @@ private:
T_ outer = T_();
};
//! Interface for Cur<> TImpl with a fixed subset of BindNative types and just a few optional methods
struct IBind;
//! A non-owning pointer to TImpl that transparently bypasses invalid calls to TImpl
//! \remark Can be used to easily implement Reader/Writers adding shortcut methods using Cur((TImpl*)this)
//! \warning Cur bypasses calls to a nullptr==impl
//! \remark A nullptr==impl results from using the same intermediate Val/Seq/Rec twice (a programmer error) or from runtime impl errors
template<class TImpl_> //!< Processing associated to the traversal
template<class TImpl_ = IBind> //!< Processing associated to the traversal
class Cur
{
Q_DISABLE_COPY(Cur)
......@@ -310,6 +313,28 @@ private:
//#include <QtCore/qdatetime.h>
//#include <QtCore/quuid.h>
template<> struct BindSupport<IBind,const char*> : BindNative {};
template<> struct BindSupport<IBind,QUtf8String> : BindNative {};
template<> struct BindSupport<IBind, QString> : BindNative {};
template<> struct BindSupport<IBind, QChar> : BindNative {};
template<> struct BindSupport<IBind, bool> : BindNative {};
template<> struct BindSupport<IBind, qint8> : BindNative {};
template<> struct BindSupport<IBind, quint8> : BindNative {};
template<> struct BindSupport<IBind, qint16> : BindNative {};
template<> struct BindSupport<IBind, quint16> : BindNative {};
template<> struct BindSupport<IBind, qint32> : BindNative {};
template<> struct BindSupport<IBind, quint32> : BindNative {};
template<> struct BindSupport<IBind, qint64> : BindNative {};
template<> struct BindSupport<IBind, quint64> : BindNative {};
//template<> struct BindSupport<IBind, qfloat16> : BindNative {};
template<> struct BindSupport<IBind, float> : BindNative {};
template<> struct BindSupport<IBind, double> : BindNative {};
//template<> struct BindSupport<IBind, QDate> : BindNative {};
//template<> struct BindSupport<IBind, QDateTime> : BindNative {};
//template<> struct BindSupport<IBind, QTime> : BindNative {};
//template<> struct BindSupport<IBind, QUuid> : BindNative {};
template<> struct BindSupport<IBind, QByteArray> : BindNative {};
struct IBind {
virtual ~IBind() = default;
......@@ -326,8 +351,6 @@ struct IBind {
virtual bool _item( ) = 0;
virtual bool _out ( ) = 0; //!< End of sequence or record
virtual bool _bind( const char* u) = 0;
virtual bool _bind( QUtf8String& r) = 0;
virtual bool _bind( QString& r) = 0;
virtual bool _bind( bool& r) = 0;
......@@ -377,33 +400,14 @@ struct IBind {
virtual bool _bind( double&& r) = 0;
virtual bool _bind( QByteArray&& r) = 0;
virtual bool _bind( const char* u) = 0;
//! \warning QMetaData is ignored by default and subject to various interpretation, so users should define or adopt existing meta data standards like XSD for sake of interoperability
virtual void _meta(QMetaData& ) {}
virtual void _meta(QMetaData&) {}
virtual void _setChoice(bool) {}
virtual void _reportError(const char*) {}
};
template<> struct BindSupport<IBind,const char*> : BindNative {};
template<> struct BindSupport<IBind,QUtf8String> : BindNative {};
template<> struct BindSupport<IBind, QString> : BindNative {};
template<> struct BindSupport<IBind, QChar> : BindNative {};
template<> struct BindSupport<IBind, bool> : BindNative {};
template<> struct BindSupport<IBind, qint8> : BindNative {};
template<> struct BindSupport<IBind, quint8> : BindNative {};
template<> struct BindSupport<IBind, qint16> : BindNative {};
template<> struct BindSupport<IBind, quint16> : BindNative {};
template<> struct BindSupport<IBind, qint32> : BindNative {};
template<> struct BindSupport<IBind, quint32> : BindNative {};
template<> struct BindSupport<IBind, qint64> : BindNative {};
template<> struct BindSupport<IBind, quint64> : BindNative {};
//template<> struct BindSupport<IBind, qfloat16> : BindNative {};
template<> struct BindSupport<IBind, float> : BindNative {};
template<> struct BindSupport<IBind, double> : BindNative {};
//template<> struct BindSupport<IBind, QDate> : BindNative {};
//template<> struct BindSupport<IBind, QDateTime> : BindNative {};
//template<> struct BindSupport<IBind, QTime> : BindNative {};
//template<> struct BindSupport<IBind, QUuid> : BindNative {};
template<> struct BindSupport<IBind, QByteArray> : BindNative {};
static char *qulltoa2(char *p, qulonglong n, int base=10)
{
......@@ -427,7 +431,7 @@ static char *qlltoa2(char *p, qlonglong n, int base=10)
return p;
}
//! Interface for runtime Cur<TImpl> implementations with BindMode::Write and a fixed subset of scalar types
//! Base IBind implementation with BindMode::Write
struct IWriter : public IBind
{
virtual ~IWriter() = default;
......@@ -495,11 +499,7 @@ struct IWriter : public IBind
};
template<typename T> struct BindSupport<IWriter,T> : BindSupport<IBind,T> {};
//! Writer with standard native types that replaces compile-time TResult with runtime IWriter
//! \remark Useful for code that do not know the Writer in advance like QLogger defined below
using QWriter = Cur<IWriter>;
//! Interface for runtime Cur<TImpl> implementations with BindMode::Read and a fixed subset of scalar types
//! Base IBind implementations with BindMode::Read
struct IReader : public IBind
{
virtual ~IReader() = default;
......@@ -513,12 +513,12 @@ struct IReader : public IBind
virtual bool _bind(QUtf8String& u) = 0;
virtual bool _bind( QString& s) { QUtf8String u; if (!_bind(u)) return false; s=QString::fromUtf8(u); return true; }
virtual bool _bind( bool& b) { QUtf8String u; if (!_bind(u)) return false; if (u.compare("true")) { b=true; } else if (u.compare("false")) { b=false; } else { _reportError(qBindExpectedBoolean); return false; } return true; }
virtual bool _bind( qint8& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint8>::min() || std::numeric_limits< qint8>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n= qint8(l); return true; }
virtual bool _bind( quint8& n) { quint64 l; if (!_bind(l)|| std::numeric_limits< quint8>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n= quint8(l); return true; }
virtual bool _bind( qint16& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint16>::min() || std::numeric_limits< qint16>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n= qint16(l); return true; }
virtual bool _bind( quint16& n) { quint64 l; if (!_bind(l)|| std::numeric_limits<quint16>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n=quint16(l); return true; }
virtual bool _bind( qint32& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint32>::min() || std::numeric_limits< qint32>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n= qint32(l); return true; }
virtual bool _bind( quint32& n) { quint64 l; if (!_bind(l)|| std::numeric_limits<quint32>::max()<l) _reportError(qBindExpectedSmallerNumber); return false; n=quint32(l); return true; }
virtual bool _bind( qint8& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint8>::min() || std::numeric_limits< qint8>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n= qint8(l); return true; }
virtual bool _bind( quint8& n) { quint64 l; if (!_bind(l)|| std::numeric_limits< quint8>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n= quint8(l); return true; }
virtual bool _bind( qint16& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint16>::min() || std::numeric_limits< qint16>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n= qint16(l); return true; }
virtual bool _bind( quint16& n) { quint64 l; if (!_bind(l)|| std::numeric_limits<quint16>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n=quint16(l); return true; }
virtual bool _bind( qint32& n) { qint64 l; if (!_bind(l)|| l<std::numeric_limits< qint32>::min() || std::numeric_limits< qint32>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n= qint32(l); return true; }
virtual bool _bind( quint32& n) { quint64 l; if (!_bind(l)|| std::numeric_limits<quint32>::max()<l) { _reportError(qBindExpectedSmallerNumber); return false; } n=quint32(l); return true; }
virtual bool _bind( qint64& n) { QUtf8String s; if (!_bind(s)) return false; bool isOk=false; qint64 v; v=s.toLongLong (&isOk); if (isOk) { n=v; return true; } _reportError(qBindExpectedDecimal); return false; }
virtual bool _bind( quint64& n) { QUtf8String s; if (!_bind(s)) return false; bool isOk=false; quint64 v; v=s.toULongLong(&isOk); if (isOk) { n=v; return true; } _reportError(qBindExpectedDecimal); return false; }
virtual bool _bind( float& n) { QUtf8String s; if (!_bind(s)) return false; bool isOk=false; float v; v=s.toFloat (&isOk); if (isOk) { n=v; return true; } _reportError(qBindExpectedDecimal); return false; }
......@@ -579,23 +579,19 @@ struct IReader : public IBind
return _bind(s);
}
};
template<typename T> struct BindSupport<IReader,T> : BindSupport<IBind,T> {};
//! Reader with standard native types that replaces compile-time TResult with runtime IReader
using QReader = Cur<IReader>;
// //////////////////////////////////////////////////////////////////////////
// Dynamic and deferred IWriter support
#include <QtCore/qatomic.h>
class QLogger : public QWriter
class QLogger : public Cur<>
{
static QAtomicPointer<IWriter> s_impl;
public:
static IWriter* setWriter(IWriter* i) { return s_impl.fetchAndStoreOrdered(i); }
QLogger() : QWriter(s_impl) {}
QLogger() : Cur<>(s_impl) {}
};
QAtomicPointer<IWriter> QLogger::s_impl = nullptr;
......
......@@ -108,11 +108,11 @@ public:
QCborWriter(QIODevice* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).value().meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).value().meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Val<Cur<>> meta ( QMetaData&& m) { return Cur<>(this).value().meta ( m); }
/**/ Val<Cur<>> meta ( QMetaData& m) { return Cur<>(this).value().meta ( m); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _isOk() { return io; }
......@@ -191,11 +191,11 @@ public:
QVector<Error> errors;
// Shortcuts
/**/ Val<QReader> value ( ) { return QReader(this).value() ; }
/**/ Val<QReader> meta ( QMetaData&& m) { return QReader(this).value().meta ( m); }
/**/ Val<QReader> meta ( QMetaData& m) { return QReader(this).value().meta ( m); }
/**/ Seq<QReader> sequence(quint32* s=nullptr) { return QReader(this).value().sequence ( s); }
template<typename T> QReader bind ( T&& t) { return QReader(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value() ; }
/**/ Val<Cur<>> meta ( QMetaData&& m) { return Cur<>(this).value().meta ( m); }
/**/ Val<Cur<>> meta ( QMetaData& m) { return Cur<>(this).value().meta ( m); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* =nullptr) { skipTag(); if (io->isArray () && io->enterContainer()) { return true; } _reportError(qBindExpectedSequence); return false; }
bool _record (quint32* =nullptr) { skipTag(); if (io->isMap () && io->enterContainer()) { return true; } _reportError(qBindExpectedRecord ); return false; }
......@@ -328,11 +328,11 @@ public:
QCborBuilder(QCborValue* v) : cbor(v) { Q_ASSERT(v); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).value().meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).value().meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Val<Cur<>> meta ( QMetaData&& m) { return Cur<>(this).value().meta ( m); }
/**/ Val<Cur<>> meta ( QMetaData& m) { return Cur<>(this).value().meta ( m); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step(nullptr)); return true; }
bool _record (quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step("" )); return true; }
......
......@@ -53,13 +53,13 @@
//! - bind the same C++ root data type (when unknown, QVariant can be used on both side)
//! - use the same set of registered QMetaTypeIds with operator<< defined
//! - use compatible ByteOrder, FloatingPointPrecision, and Version
class QDataWriter : public IWriter // allows runtime flexibility using a compile-time QWriter but handles smaller numeric types
class QDataWriter : public IWriter // allows runtime flexibility without BindNative support for QColor
{
Q_DISABLE_COPY(QDataWriter)
public:
QDataWriter(QDataStream* io) : io(io) { Q_ASSERT(io); }
virtual BindMode mode() const { return BindMode::Write; }
BindMode mode() const { return BindMode::Write; }
// Shortcuts
Val<Cur<QDataWriter>> value ( ) { return Cur<QDataWriter>(this).value() ; }
......@@ -67,7 +67,7 @@ public:
Val<Cur<QDataWriter>> meta ( QMetaData& m) { return Cur<QDataWriter>(this).value().meta (m); }
Seq<Cur<QDataWriter>> sequence(quint32* s=nullptr) { return Cur<QDataWriter>(this).value().sequence(s); }
template<typename T> QWriter bind(T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); } //!< Only the standard QWriter is compatible with QWritable
template<typename T> Cur<> bind(T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); } //!< Only the standard Cur<> is compatible with QWritable
protected:
friend class Cur<QDataWriter>;
bool _sequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
......@@ -87,15 +87,8 @@ private:
QDataStream* io;
};
template<typename T> struct BindSupport<QDataWriter,T> : BindSupport<IWriter,T> {};
// TODO BindNative smallest numeric types
template<> struct BindSupport<QDataWriter, qint32> : BindNative {};
template<> struct BindSupport<QDataWriter,quint32> : BindNative {};
// TODO BindNative other types that cannot be QBind with types above
// TODO BindNative other types that should bind specifically for compatibility with QDataStream
template<> struct BindSupport<QDataWriter, QColor> : BindNative {};
template<typename T> struct BindSupport<QDataWriter, T,typename std::enable_if<
QtPrivate::IsAssociativeContainer<RemoveCvRef<T>>::Value // Not handled correctly by _record()._item(k) which makes the keys implicit
>::type
> : BindNative {};
// --------------------------------------------------------------------------
......
......@@ -59,9 +59,9 @@ public:
QJsonBuilder(QJsonValue* v) : json(v) { Q_ASSERT(v); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step(nullptr)); return true; }
bool _record (quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step("" )); return true; }
......@@ -114,9 +114,9 @@ public:
}
// Shortcuts
/**/ Val<QReader> value ( ) { return QReader(this).value(); }
/**/ Seq<QReader> sequence(quint32* s=nullptr) { return QReader(this).value().sequence ( s); }
template<typename T> QReader bind ( T&& t) { return QReader(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* s=nullptr) { Q_UNUSED(s); if (current()->isArray ()) { steps.push(Step()); return true; } _reportError(qBindExpectedSequence); return false; }
bool _record (quint32* s=nullptr) { Q_UNUSED(s); if (current()->isObject()) { steps.push(Step()); return true; } _reportError(qBindExpectedRecord ); return false; }
......@@ -155,9 +155,9 @@ public:
~QJsonWriter() { for (auto&& level : levels) io->write(level.end); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step{"","]"}); return io->write("["); }
bool _record (quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step{"","}"}); return io->write("{"); }
......@@ -221,9 +221,9 @@ public:
QVector<Error> errors;
// Shortcuts
/**/ Val<QReader> value ( ) { return QReader(this).value(); }
/**/ Seq<QReader> sequence(quint32* s=nullptr) { return QReader(this).value().sequence(s); }
template<typename T> QReader bind ( T&& t) { return QReader(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence(s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* =nullptr) { if (get('[', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"]")); return true; } _reportError(qBindExpectedSequence); return false; }
bool _record (quint32* =nullptr) { if (get('{', "[{\"ntf-0123456789.")) { levels.push(Step(-1,"}")); return true; } _reportError(qBindExpectedRecord ); return false; }
......@@ -257,8 +257,8 @@ protected:
double( std::numeric_limits<float >::max())<d) { n = float(d); return true; } _reportError(qBindExpectedSmallerNumber ); } return false; }
bool _bind ( double& n) { double d; quint64 i; bool neg; bool r=getNumber(d,i,neg); if (r) { n = d ; } return r; }
bool _bind ( quint64& t) { double d; quint64 i; bool neg; bool r=getNumber(d,i,neg); if (r) { if (!neg ) { t = i ; return true; } _reportError(qBindExpectedPositiveNumber); } return false; }
bool _bind ( qint64& t) { double d; quint64 i; bool neg; bool r=getNumber(d,i,neg); if (r) { if (!neg && quint64(std::numeric_limits<qint64>::max())<i) { t = qint64(i); return true; }
if ( neg && -quint64(std::numeric_limits<qint64>::min())<i) { t = -qint64(i); return true; } _reportError(qBindExpectedSmallerNumber ); } return false; }
bool _bind ( qint64& t) { double d; quint64 i; bool neg; bool r=getNumber(d,i,neg); if (r) { if (!neg && quint64( std::numeric_limits<qint64>::max())<i) { t = qint64(i); return true; }
if ( neg && quint64(-std::numeric_limits<qint64>::min())<i) { t = -qint64(i); return true; } _reportError(qBindExpectedSmallerNumber ); } return false; }
bool _any ( ) { isChoice=true; QString t; double d; bool b; // FIXME Use QString instead of QByteArray
( (_sequence() && _out())
......
......@@ -61,7 +61,7 @@ class QModelWriter : public IWriter
public:
QModelWriter(QAbstractItemModel* m) : m(m) { Q_ASSERT(m); }
Val<QWriter> meta(QMetaData&& m) { return QWriter(this).value().meta(m); }
Val<Cur<>> meta(QMetaData&& m) { return Cur<>(this).value().meta(m); }
protected:
void _meta(QMetaData& meta) {
if (meta.find(qmChildren)!=meta.end()) {
......
......@@ -55,9 +55,9 @@ public:
~QVariantBuilder() { while (!levels.isEmpty()) _out(); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
template<typename T>
bool _bind ( T&& t) { set(QVariant::fromValue(t)); return true; }
......
......@@ -110,9 +110,9 @@ public:
TextWriter(QIODevice* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value(); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).value().sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); }
/**/ Val<Cur<>> value ( ) { return Cur<>(this).value(); }
/**/ Seq<Cur<>> sequence(quint32* s=nullptr) { return Cur<>(this).value().sequence ( s); }
template<typename T> Cur<> bind ( T&& t) { return Cur<>(this).value().bind(std::forward<T>(t)); }
protected:
bool _isOk() { return io; }
......@@ -298,7 +298,7 @@ int main(int argc, char *argv[])
<< color;
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
QWritable<QWriter> writables[5];
QWritable<Cur<>> writables[5];
START {
writables[0] = 1.333333333333f;
writables[1] = PI;
......@@ -377,7 +377,7 @@ int main(int argc, char *argv[])
};
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
QWritable<QWriter> writable;
QWritable<Cur<>> writable;
START {
writable = transform;
}
......@@ -462,7 +462,7 @@ int main(int argc, char *argv[])
d << person;
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
QWritable<QWriter> writable;
QWritable<Cur<>> writable;
START {
writable = person;
}
......
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