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 ff55116e authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Replaced QReader/QBaseWriter with Cur<IReader/IWriter>

Fixed some bool handled as numeric
parent ce2b376c
This diff is collapsed.
......@@ -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).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
protected:
bool _isOk() { return io; }
......@@ -192,11 +192,11 @@ public:
QVector<Error> errors;
// Shortcuts
/**/ Val<QReader<>> value ( ) { return QReader<>(this).value ( ); }
/**/ Val<QReader<>> meta ( QMetaData&& m) { return QReader<>(this).meta ( m); }
/**/ Val<QReader<>> meta ( QMetaData& m) { return QReader<>(this).meta ( m); }
/**/ Seq<QReader<>> sequence(quint32* s=nullptr) { return QReader<>(this).sequence ( s); }
template<typename T> QReader<> bind ( T&& t) { return QReader<>(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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; }
......@@ -330,11 +330,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).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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,24 +53,21 @@
//! - 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
, public QBaseWriter<QDataWriter> // allows using QDataStream << for small numeric types and more performance by removing an indirection level
class QDataWriter : public IWriter// allows runtime flexibility using a compile-time QWriter but loses smaller numeric types
{
protected:
QDataWriter(const QDataWriter &o) : QBaseWriter(), io(o.io) {}
QDataWriter &operator=(const QDataWriter &) = delete;
Q_DISABLE_COPY(QDataWriter)
public:
Q_ENABLE_MOVE(QDataWriter, std::swap(io, o.io); )
QDataWriter(QDataStream* io) : io(io) { Q_ASSERT(io); }
operator bool() { return io && io->status()==QDataStream::Ok; } // for QBaseWriter
protected:
friend class QBaseWriter<QDataWriter>;
template<class T_> friend class Val; // calls methods below
template<class T_> friend class Seq;
template<class T_> friend class Rec;
// Shortcuts
Val<Cur<QDataWriter>> value ( ) { return Cur<QDataWriter>(this).value() ; }
Val<Cur<QDataWriter>> meta ( QMetaData&& m) { return Cur<QDataWriter>(this).value().meta (m); }
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
protected:
friend class Cur<QDataWriter>;
bool _sequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _record (quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _null ( ) { *io << nullptr; return true; }
......@@ -83,28 +80,20 @@ protected:
bool _out( ) { return true; }
bool _item( ) { return true; }
bool _item(QUtf8String&) { return true; } // record keys are implicit, maps should be serialized as a sequence of records with key and value items
// Literals support
bool _item( QName) { return true; } // for QBaseWriter
private:
QDataStream* io;
};
//template<> struct BindSupport<QDataWriter,const char*> : BindNative {};
template<> struct BindSupport<QDataWriter, QString&> : BindNative {};
template<> struct BindSupport<QDataWriter,QByteArray&> : BindNative {};
template<> struct BindSupport<QDataWriter, bool&> : BindNative {};
template<> struct BindSupport<QDataWriter, float&> : BindNative {};
template<> struct BindSupport<QDataWriter, double&> : BindNative {};
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 {};
template<> struct BindSupport<QDataWriter, qlonglong&> : BindNative {};
template<> struct BindSupport<QDataWriter,qulonglong&> : BindNative {};
template<typename T> struct BindSupport<QDataWriter,T&,typename std::enable_if<
template<> struct BindSupport<QDataWriter, qint32&> : BindNative {};
template<> struct BindSupport<QDataWriter,quint32&> : BindNative {};
// TODO BindNative all types for which T stream operators are defined : QMetaTypeId<typename std::remove_reference<typename std::remove_cv<T>>>::Defined ?
template<> struct BindSupport<QDataWriter, QColor&> : BindNative {};
template<typename T> struct BindSupport<QDataWriter, T&,typename std::enable_if<
QtPrivate::IsAssociativeContainer<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::Value // Not handled correctly by _record()._item(k) which makes the keys implicit
>::type
> : BindNative {};
// TODO BindNative all types for which T stream operators are defined : QMetaTypeId<typename std::remove_reference<typename std::remove_cv<T>>>::Defined ?
// --------------------------------------------------------------------------
......
......@@ -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).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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).sequence ( s); }
template<typename T> QReader<> bind ( T&& t) { return QReader<>(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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).sequence ( s); }
template<typename T> QReader<> bind ( T&& t) { return QReader<>(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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; }
......
......@@ -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).meta(m); }
Val<QWriter> meta(QMetaData&& m) { return QWriter(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).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
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).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ 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)); }
protected:
bool _isOk() { return io; }
......@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
STOP("Variant",v.toString());
START {
b.seek(0); b.buffer().clear();
QCborWriter(&b).sequence()
QCborWriter(&b).value().sequence(5)
.bind(1.333333333333f)
.bind(PI)
.bind(ascii.toUtf8().constData())
......@@ -261,7 +261,7 @@ int main(int argc, char *argv[])
START {
b.seek(0); b.buffer().clear();
QCborStreamWriter s(&b);
s.startArray();
s.startArray(5);
s.append(1.333333333333f);
s.append(PI);
s.append(ascii);
......@@ -365,7 +365,7 @@ int main(int argc, char *argv[])
START {
b.seek(0); b.buffer().clear();
QDataStream d(&b);
QDataWriter(&d).bind(transform);
QDataWriter(&d).value().bind(transform);
}
STOP("Data",QString::fromUtf8(b.buffer().toHex()));
START {
......@@ -453,7 +453,7 @@ int main(int argc, char *argv[])
START {
b.seek(0); b.buffer().clear();
QDataStream d(&b);
QDataWriter(&d).bind(person);
QDataWriter(&d).value().bind(person);
}
STOP("Data",QString::fromUtf8(b.buffer().toHex()));
START {
......
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