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

Use again pointer with a single allocation for correctness and facilitate writing implementations

simplified implementations interface (always return bool)
parent 8c357b03
......@@ -44,6 +44,10 @@
Class ( ) = default; \
Class (Class&& o) = default; \
Class& operator=(Class&& o) = default;
#define Q_ENABLE_SWAP(Class, Statements) \
Class ( ) = default; \
Class (Class&& o) noexcept { Statements } \
Class& operator=(Class&& o) noexcept { if (this!=&o) { Statements } return *this; }
// //////////////////////////////////////////////////////////////////////////
// Generic fluent interface for traversing and processing structured value types (serialize, deserialize, construct generic in-memory data structures, etc...)
......@@ -58,12 +62,6 @@ template<class T_> class Val //!< a choice of sequence(), null(), or any value
Q_DISABLE_COPY(Val)
public:
Q_ENABLE_DEFAULT_MOVE(Val)
// T_ can be either a TResult or any combination of nested Seq or Rec like T_ = Rec<Seq<TResult>
using TResult = typename T_::TResult; //!< the start and end point of the traversal as well as the associated processing (see QJsonWriter below for an example)
using TValue = typename TResult::TValue;
static const BindMode Mode = TResult::Mode;
Val(T_&& out) { std::swap(m_out, out); }
operator bool() { return bool(m_out); } //!< to drive QBind<TResult,T>() traversal
......@@ -84,9 +82,9 @@ template<class T_> class Seq
public:
Q_ENABLE_DEFAULT_MOVE(Seq)
using TResult = typename T_::TResult;
using TValue = typename TResult::TValue;
static const BindMode Mode = TResult::Mode;
// T_ can be either a TResult or any combination of nested Seq or Rec like T_ = Rec<Seq<TResult>
using TResult = typename T_::TResult; //!< the start and end point of the traversal as well as the associated processing (see QJsonWriter below for an example)
using TImpl = typename TResult::TImpl;
Seq(T_&& out) { std::swap(m_out, out); }
......@@ -103,29 +101,37 @@ public:
template<typename T> Seq<T_> bind( T& t) { return item().bind(t); }
template<typename T> Seq<T_> bind( T&& t) { return item().bind(t); }
TValue operator->() { return m_out.operator->(); }
TImpl* operator->() { return m_out.operator->(); }
private:
T_ m_out = T_();
};
template<class TDerived, class TResultShared>
class QBindResult
template<class TResult_, class TImpl_, BindMode Mode_>
class Top // : public Val<TImpl_>
{
Q_DISABLE_COPY(QBindResult)
Q_DISABLE_COPY(Top)
public:
Q_ENABLE_DEFAULT_MOVE(QBindResult)
Q_ENABLE_SWAP(Top, std::swap(m, o.m); std::swap(m_owned, o.m_owned); )
~Top() { if (m && m_owned) delete m; }
using TResult = TDerived;
using TValue = TResultShared*;
static const BindMode Mode = TResult::Mode;
using TResult = TResult_;
using TImpl = TImpl_;
static const BindMode Mode = Mode_;
operator bool() { return m; } //!< to drive QBind<TResult,T>() traversal
TValue operator->() { return m ? &m : nullptr; }
// Shortcuts
/**/ Seq<TResult> sequence() { return static_cast<TResult*>(this)->begin().sequence(); }
template<typename T> TResult bind( T& t) { return static_cast<TResult*>(this)->begin(). bind(t); } // TODO only for readers ?
template<typename T> TResult bind(const T& t) { return static_cast<TResult*>(this)->begin(). bind(t); }
template<typename T> TResult bind( T&& t) { return static_cast<TResult*>(this)->begin(). bind(t); }
TImpl* operator->() { Q_ASSERT_X(m,Q_FUNC_INFO,"check operator bool() before calling operator->()"); return m; }
protected:
QBindResult( TResultShared&& m) : m(m) {}
QBindResult(const TResultShared& m) : m(m) {} // for nested QBind only
Top(TImpl_* m, bool owned = true) : m(m), m_owned(owned) {}
TResultShared m = TResultShared(); //!< gives semantic to the traversal (nullptr if already moved)
TImpl* m = nullptr; //!< gives semantic to the traversal (nullptr if already moved)
bool m_owned = true; //!< for nested QBind only
};
// //////////////////////////////////////////////////////////////////////////
......@@ -199,14 +205,15 @@ struct QBind<TResult, QString> {
static TResult bind(Val<TResult> dst, QString& src, std::enable_if_t<TResult::Mode==Write>* = nullptr) {
return dst.bind(src.toUtf8().constData());
}
//static TResult bind(Val<TResult> src, QString& dst, std::enable_if_t<TResult::Mode==Read >* = nullptr) {
// QByteArray ba;
// auto result = src.bind(ba);
// if (result)
// dst = QString::fromUtf8(ba);
//
// return result;
//}
// C++17 constexpr if is required to handle situations where one of these definitions is not used
static TResult bind(Val<TResult> src, QString& dst, std::enable_if_t<TResult::Mode==Read >* = nullptr) {
QByteArray ba;
auto result = src.bind(ba);
if (result)
dst = QString::fromUtf8(ba);
return result;
}
};
#include <QtCore/qvector.h>
......@@ -229,16 +236,17 @@ struct QBind<TResult, QVector<T>> {
}
return s;
}
//static TResult bind(Val<TResult> src, QVector<T>& dst, std::enable_if_t<TResult::Mode==Read >* = nullptr) {
// auto s(src.sequence());
// for (auto i = s.item(); i; i = s.item()) {
// T t;
// s = i.bind(t);
// if (s)
// dst.push_back(t);
// }
// return s;
//}
// C++17 constexpr if is required to handle situations where one of these definitions is not used
static TResult bind(Val<TResult> src, QVector<T>& dst, std::enable_if_t<TResult::Mode==Read >* = nullptr) {
auto s(src.sequence());
for (auto i = s.item(); i; i = s.item()) {
T t;
s = i.bind(t);
if (s)
dst.push_back(t);
}
return s;
}
};
// --------------------------------------------------------------------------
......
......@@ -100,13 +100,16 @@ class QCborWriterShared
QIODevice* io;
int levels = 0; //!< minimal dynamic context to ensure well-formedness in case TResult is abandoned
public:
QCborWriterShared() = default;
QCborWriterShared(QIODevice* io) : io(io) { Q_ASSERT(io); }
~QCborWriterShared() { while (levels) out(); }
operator bool() { return io; } //!< to drive QBind<TResult,T>() traversal
protected:
template<class T_> friend class Val; // calls methods below
QCborWriterShared* sequence() { levels++;
bool sequence() { levels++;
io->putChar(cbor::IndefiniteLengthArrayByte);
return this; }
return true; }
bool null() { io->putChar(cbor::NullByte);
return true; }
bool bind(const char* s) { putInteger (cbor::TextStringType, strlen(s));
......@@ -130,13 +133,13 @@ protected:
return true; }
// Val<TResult> prevents QBind from getting out() of an outer Seq for instance
template<typename T> bool bind(const T& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(this, QCborWriter(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(this, QCborWriter(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(this, QCborWriter(this)), t ); }
template<typename T> bool bind(const T& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(QCborWriter(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(QCborWriter(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QCborWriter,T>::bind(Val<QCborWriter>(QCborWriter(this)), t ); }
template<class T_> friend class Seq; // calls methods below
QCborWriterShared* item() { return this; }
QCborWriterShared* out() { io->putChar(cbor::BreakByte); levels--; return this; }
bool item() { return true; }
bool out() { io->putChar(cbor::BreakByte); levels--; return true; }
private:
void putInteger(char majorType, quint64 n)
{
......@@ -152,23 +155,15 @@ private:
}
}
};
class QCborWriter : public QBindResult<QCborWriter, QCborWriterShared>
class QCborWriter : public Top<QCborWriter, QCborWriterShared, BindMode::Write>
{
Q_DISABLE_COPY(QCborWriter) // but not swap
public:
Q_ENABLE_DEFAULT_MOVE(QCborWriter)
QCborWriter(QIODevice* io) : Top(new QCborWriterShared(io)) {}
static const BindMode Mode = BindMode::Write;
QCborWriter(QIODevice* io) : QBindResult(new QCborWriterShared(io)) {}
Val<QCborWriter> begin() { auto beforeMove = m; return std::move(Val<QCborWriter>(beforeMove, std::move(*this))); }
// Shortcuts
Seq<QCborWriter> sequence() { return begin().sequence(); }
template<typename T> QCborWriter bind(const T& t) { return begin().bind(t); }
template<typename T> QCborWriter bind( T&& t) { return begin().bind(t); }
Val<QCborWriter> begin() { return std::move(Val<QCborWriter>(std::move(*this))); }
private:
friend class QCborWriterShared; // uses method below
QCborWriter(QCborWriterShared* shared) : QBindResult(shared, false) {}
QCborWriter(QCborWriterShared* outer) : Top(outer, false) {}
};
......@@ -63,8 +63,8 @@ public:
protected:
template<class T_> friend class Val; // calls methods below
QJsonBuilderShared* record() { levels.push(Level("" )); return this; }
QJsonBuilderShared* sequence() { levels.push(Level(nullptr)); return this; }
bool record() { levels.push(Level("" )); return true; }
bool sequence() { levels.push(Level(nullptr)); return true; }
bool null() { set(QJsonValue () ); return true; }
bool bind(const char* s) { set(s ); return true; }
bool bind(double d) { set(d ); return true; }
......@@ -73,14 +73,14 @@ protected:
template<typename T> bool bind(T t, std::enable_if_t<std::is_arithmetic<T>::value>* = nullptr) { return bind(double(t)); }
// Val<TResult> prevents QBind from getting out() of an outer Seq for instance
template<typename T> bool bind(const T& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(this, QJsonBuilder(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(this, QJsonBuilder(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(this, QJsonBuilder(this)), t ); }
template<typename T> bool bind(const T& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(QJsonBuilder(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(QJsonBuilder(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QJsonBuilder,T>::bind(Val<QJsonBuilder>(QJsonBuilder(this)), t ); }
template<class T_> friend class Seq; // calls methods below
QJsonBuilderShared* item(const char* key=nullptr) { levels.last().key=key; return this; }
QJsonBuilderShared* out() { auto level = levels.pop(); set(level.key ? QJsonValue(level.object) : QJsonValue(level.array)); return this; }
bool item(const char* key=nullptr) { levels.last().key=key; return true; }
bool out() { auto level = levels.pop(); set(level.key ? QJsonValue(level.object) : QJsonValue(level.array)); return true; }
private:
void set(QJsonValue v) {
if (levels.isEmpty()) {
......@@ -94,25 +94,17 @@ private:
}
}
};
class QJsonBuilder : public QBindResult<QJsonBuilder, QJsonBuilderShared>
class QJsonBuilder : public Top<QJsonBuilder, QJsonBuilderShared, BindMode::Write>
{
Q_DISABLE_COPY(QJsonBuilder) // but not swap
Q_DISABLE_COPY(QJsonBuilder)
public:
Q_ENABLE_DEFAULT_MOVE(QJsonBuilder)
QJsonBuilder(QJsonValue* v) : Top(new QJsonBuilderShared(v)) {}
static const BindMode Mode = BindMode::Write;
QJsonBuilder(QJsonValue* v) : QBindResult(new QJsonBuilderShared(v)) {}
Val<TResult> begin() { auto beforeMove = m; return std::move(Val<TResult>(beforeMove, std::move(*this))); }
// Shortcuts
Seq<TResult> sequence() { return begin().sequence(); }
template<typename T> TResult bind(const T& t) { return begin().bind(t) ; }
template<typename T> TResult bind( T&& t) { return begin().bind(t) ; }
Val<TResult> begin() { return std::move(Val<TResult>(std::move(*this))); }
private:
friend class QJsonBuilderShared; // uses method below
QJsonBuilder(QJsonBuilderShared* shared) : QBindResult(shared, false) {}
QJsonBuilder(QJsonBuilderShared* outer) : Top(outer, false) {}
};
class QJsonWriter;
......@@ -128,15 +120,12 @@ public:
protected:
template<class T_> friend class Val; // calls methods below
QJsonWriterShared* sequence() { levels.push(Level{"","]"});
io->write( "[" );
return this; }
bool null() { io->write( "null" );
return true; }
bool sequence() { levels.push(Level{"","]"});
io->write( "[" ); return true; }
bool null() { io->write( "null" ); return true; }
bool bind(const char* s) { io->write( "\"" );
io->write( s ); // TODO escape
io->write( "\"" );
return true; }
io->write( "\"" ); return true; }
// Natively supported overloads
bool bind( float n) { io->write(QByteArray::number(n, 'g', std::numeric_limits< float>::max_digits10)); return true; }
......@@ -149,34 +138,26 @@ protected:
template<typename T> bool bind(T t, std::enable_if_t<std::is_integral<T>::value && std:: is_signed<T>::value>* = nullptr) { return bind( qlonglong(t)); }
// Val<TResult> prevents QBind from getting out() of an outer Seq for instance
template<typename T> bool bind(const T& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(this, QJsonWriter(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(this, QJsonWriter(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(this, QJsonWriter(this)), t ); }
template<typename T> bool bind(const T& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(QJsonWriter(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(QJsonWriter(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QJsonWriter,T>::bind(Val<QJsonWriter>(QJsonWriter(this)), t ); }
template<class T_> friend class Seq; // calls methods below
QJsonWriterShared* item() { io->write(levels.last().sep); levels.last().sep = ","; return this; }
QJsonWriterShared* out() { io->write(levels.pop() .end) ; return this; }
bool item() { io->write(levels.last().sep); levels.last().sep = ","; return this; }
bool out() { io->write(levels.pop() .end) ; return this; }
};
class QJsonWriter : public QBindResult<QJsonWriter, QJsonWriterShared>
class QJsonWriter : public Top<QJsonWriter, QJsonWriterShared, BindMode::Write>
{
Q_DISABLE_COPY(QJsonWriter) // but not swap
Q_DISABLE_COPY(QJsonWriter)
public:
Q_ENABLE_DEFAULT_MOVE(QJsonWriter)
QJsonWriter(QIODevice* io) : Top(new QJsonWriterShared(io)) {}
static const BindMode Mode = BindMode::Write;
QJsonWriter(QIODevice* io) : QBindResult(new QJsonWriterShared(io)) {}
Val<QJsonWriter> begin() { auto beforeMove = m; return std::move(Val<QJsonWriter>(beforeMove, std::move(*this))); }
// Shortcuts
Seq<QJsonWriter> sequence() { return begin().sequence(); }
template<typename T> QJsonWriter bind(const T& t) { return begin().bind(t); }
template<typename T> QJsonWriter bind( T&& t) { return begin().bind(t); }
Val<QJsonWriter> begin() { return std::move(Val<QJsonWriter>(std::move(*this))); }
private:
friend class QJsonWriterShared; // uses method below
QJsonWriter(QJsonWriterShared* shared) : QBindResult(shared, false) {}
QJsonWriter(QJsonWriterShared* outer) : Top(outer, false) {}
};
class QJsonReader;
......@@ -191,11 +172,11 @@ public:
protected:
template<class T_> friend class Val; // calls methods below
QJsonReaderShared* sequence() { if (!get('[', "ntf-.0123456789[{\"")) {
return nullptr;
bool sequence() { if (!get('[', "ntf-.0123456789[{\"")) {
return false;
}
levels.push(Level{true,"]"});
return this; }
return true; }
bool null() { if ( !get('n', "[{\"ntf-.0123456789")) return false;
if (nextChar == 'u') getChar(); else { next("[{\""); return false; }
if (nextChar == 'l') getChar(); else { next("[{\""); return false; }
......@@ -269,22 +250,22 @@ protected:
return true; }
// Val<TResult> prevents QBind from getting out() of an outer Seq for instance
template<typename T> bool bind(T& t) { return QBind<QJsonReader,T>::bind(Val<QJsonReader>(this, QJsonReader(this)), t); }
template<typename T> bool bind(T& t) { return QBind<QJsonReader,T>::bind(Val<QJsonReader>(QJsonReader(this)), t); }
// TODO static_assert on const T& and T&& ?
template<class T_> friend class Seq; // calls methods below
QJsonReaderShared* item() { Level& level = levels.last();
bool item() { Level& level = levels.last();
if (!level.isFirst && !get(',',level.end)) {
return nullptr;
return false;
}
level.isFirst = false;
return this; }
QJsonReaderShared* out() { auto level = levels.pop();
return true; }
bool out() { auto level = levels.pop();
while (get(',', level.end)) {
skipItem();
}
return get(*level.end) ? this : nullptr; }
return get(*level.end); }
private:
int getDigit() {
return '0' <= nextChar && nextChar <= '9' ? (getChar())-'0' : -1;
......@@ -360,23 +341,17 @@ private:
;
}
};
class QJsonReader : public QBindResult<QJsonReader, QJsonReaderShared>
class QJsonReader : public Top<QJsonReader, QJsonReaderShared, BindMode::Read>
{
Q_DISABLE_COPY(QJsonReader) // but not swap
Q_DISABLE_COPY(QJsonReader)
public:
Q_ENABLE_DEFAULT_MOVE(QJsonReader)
QJsonReader(QIODevice* io) : Top(new QJsonReaderShared(io)) {}
static const BindMode Mode = BindMode::Read;
QJsonReader(QIODevice* io) : QBindResult(new QJsonReaderShared(io)) {}
Val<QJsonReader> begin() { auto beforeMove = m; return std::move(Val<QJsonReader>(beforeMove, std::move(*this))); }
// Shortcuts
template<typename T> QJsonReader bind(T& t) { return begin().bind(t); }
Val<QJsonReader> begin() { return std::move(Val<QJsonReader>(std::move(*this))); }
private:
friend class QJsonReaderShared; // uses method below
QJsonReader(QJsonReaderShared* shared) : QBindResult(shared, false) {}
QJsonReader(QJsonReaderShared* outer) : Top(outer, false) {}
};
// //////////////////////////////////////////////////////////////////////////
......
......@@ -46,8 +46,8 @@
// Extensible set of TResult implementations providing concrete syntax to the logical data structure in a specific Mode among Write, Read, ...
//#include "QJson.hpp" // QJsonWriter, QJsonReader, QJsonBuilder and QBind<_,QJsonValue> support
//#include "QCborWriter.hpp" // QCborWriter demonstrating the performance potential of the approach
#include "QJson.hpp" // QJsonWriter, QJsonReader, QJsonBuilder and QBind<_,QJsonValue> support
#include "QCborWriter.hpp" // QCborWriter demonstrating the performance potential of the approach
// //////////////////////////////////////////////////////////////////////////
// QBind<_,T> basic example using an internal bind<TResult> method
......@@ -74,45 +74,40 @@ struct Person
#include <type_traits>
#include <QtCore/qiodevice.h>
class QTextWriter;
class QTextWriterShared
class TextWriter;
class TextWriterShared
{
QIODevice* io = nullptr;
QIODevice* io;
public:
QTextWriterShared() = default;
QTextWriterShared(QIODevice* io) : io(io) { Q_ASSERT(io); }
operator bool() { return io; } //!< to drive QBind<TResult,T>() traversal
TextWriterShared(QIODevice* io) : io(io) { Q_ASSERT(io); }
protected:
template<class T_> friend class Val; // enables calling methods below through operator->()
bool sequence() { io->write( "[" ); return true; }
bool null() { return true; }
bool bind(const char* s) { io->write( s ); return true; }
bool sequence() { io->write("["); return true; }
bool null() { return true; }
bool bind(const char* s) { io->write( s ); return true; }
// Val<TResult> prevents QBind from getting out() of an outer Seq for instance
template<typename T> bool bind(const T& t) { return QBind<QTextWriter,T>::bind(Val<QTextWriter>(QTextWriter(*this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<QTextWriter,T>::bind(Val<QTextWriter>(QTextWriter(*this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<QTextWriter,T>::bind(Val<QTextWriter>(QTextWriter(*this)), t ); }
template<typename T> bool bind(const T& t) { return QBind<TextWriter,T>::bind(Val<TextWriter>(TextWriter(this)), const_cast<T&>(t)); } // t will not be modified anyway
template<typename T> bool bind( T& t) { return QBind<TextWriter,T>::bind(Val<TextWriter>(TextWriter(this)), t ); }
template<typename T> bool bind( T&& t) { return QBind<TextWriter,T>::bind(Val<TextWriter>(TextWriter(this)), t ); }
template<class T_> friend class Seq; // enables calling methods below through operator->()
bool item() { io->write(" "); return true; }
bool out() { io->write("]"); return true; }
};
class QTextWriter : public QBindResult<QTextWriter, QTextWriterShared>
class TextWriter : public Top<TextWriter, TextWriterShared, BindMode::Write>
{
Q_DISABLE_COPY(QTextWriter)
Q_DISABLE_COPY(TextWriter)
public:
Q_ENABLE_DEFAULT_MOVE(QTextWriter)
static const BindMode Mode = BindMode::Write;
QTextWriter(QIODevice* io) : QBindResult(std::move(QTextWriterShared(io))) {}
Q_ENABLE_DEFAULT_MOVE(TextWriter)
TextWriter(QIODevice* io) : Top(new TextWriterShared(io)) {}
Val<QTextWriter> begin() { return std::move(Val<TResult>(std::move(*this))); }
Val<TextWriter> begin() { return std::move(Val<TResult>(std::move(*this))); }
private:
friend class QTextWriterShared; // uses method below
QTextWriter(const QTextWriterShared& shared) : QBindResult(shared) {}
friend class TextWriterShared; // uses method below
TextWriter(TextWriterShared* outer) : Top(outer, false) {}
};
// //////////////////////////////////////////////////////////////////////////
......@@ -182,8 +177,7 @@ int main()
START {
s.clear();
QDebug(&s)
<< '['
<< ',' << 1.333333333333f
<< '[' << 1.333333333333f
<< ',' << text
<< ']'
;
......@@ -191,42 +185,42 @@ int main()
STOP("QDebug",s);
START {
b.seek(0); b.buffer().clear();
QTextWriter(&b).begin()
TextWriter(&b).begin()
.sequence()
.bind(123)
.bind(text)
;
}
STOP("Text",QString::fromUtf8(b.buffer()));
// START {
// b.seek(0); b.buffer().clear();
// QJsonWriter(&b)
// .sequence()
// .bind(1.333333333333f)
// .bind(text)
// ;
// }
// START {
// b.seek(0); b.buffer().clear();
// QCborWriter(&b)
// .sequence()
// .bind(1.333333333333f)
// .bind(text)
// ;
// }
// STOP("Cbor",QString::fromUtf8(b.buffer().toHex()));
// QVector<QWritable<QCborWriter>> writables;
// START {
// writables.clear();
// writables.append(1.333333333333f);
// writables.append(text);
// }
// STOP("QWritable","");
// START {
// b.seek(0); b.buffer().clear();
// QCborWriter(&b).bind(writables);
// }
// STOP("QWritable>Cbor",QString::fromUtf8(b.buffer().toHex()));
START {
b.seek(0); b.buffer().clear();
QJsonWriter(&b)
.sequence()
.bind(1.333333333333f)
.bind(text)
;
}
START {
b.seek(0); b.buffer().clear();
QCborWriter(&b)
.sequence()
.bind(1.333333333333f)
.bind(text)
;
}
STOP("Cbor",QString::fromUtf8(b.buffer().toHex()));
QVector<QWritable<QCborWriter>> writables;
START {
writables.clear();
writables.append(1.333333333333f);
writables.append(text);
}
STOP("QWritable","");
START {
b.seek(0); b.buffer().clear();
QCborWriter(&b).bind(writables);
}
STOP("QWritable>Cbor",QString::fromUtf8(b.buffer().toHex()));
}
GROUP_STOP;
GROUP("Format << doubles")
......@@ -242,31 +236,31 @@ int main()
STOP("QDebug",s);
START {
b.seek(0); b.buffer().clear();
QTextWriter(&b).begin()
TextWriter(&b).begin()
.bind(transform)
;
}
STOP("Text",QString::fromUtf8(b.buffer()));
// START {
// b.seek(0); b.buffer().clear();
// QJsonWriter(&b).bind(transform);
// }
// STOP("Json",b.buffer())
// START {
// b.seek(0); b.buffer().clear();
// QCborWriter(&b).bind(transform);
// }
// STOP("Cbor",QString::fromUtf8(b.buffer().toHex()));
// QWritable<QCborWriter> writable;
// START {
// writable = transform;
// }