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

fixed is_integral support

added QDatastream bench (best perf but implicit structure)
parent 4c4b40e9
......@@ -162,5 +162,4 @@ template<> struct BindSupport<CborWriter,const char*> : BindNative {};
template<> struct BindSupport<CborWriter, bool&> : BindNative {};
template<> struct BindSupport<CborWriter, float&> : BindNative {};
template<> struct BindSupport<CborWriter, double&> : BindNative {};
template<> struct BindSupport<CborWriter, int&> : BindNative {}; // TODO remove
template<typename T> struct BindSupport<CborWriter,T&,typename std::enable_if<std::is_integral<T>::value,T&>::type> : BindNative {};
template<typename T> struct BindSupport<CborWriter,T&,typename std::enable_if<std::is_integral<T>::value>::type> : BindNative {};
......@@ -87,7 +87,7 @@ protected:
bool _bind( bool& b) { set(QJsonValue(b)); return true; }
bool _bind( double& d) { set(QJsonValue(d)); return true; }
template<typename T> bool _bind(T& t, typename std::enable_if<std::is_arithmetic<T>::value>::type* = nullptr) { double d(t); return _bind(d); }
template<typename T> bool _bind(T& t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr) { double d(t); return _bind(d); }
template<class T_> friend class Seq; // calls methods below
......@@ -115,8 +115,7 @@ QJsonBuilder::QJsonBuilder(QJsonValue* v) : QScopedResult(new QJsonBuilderImpl(v
template<> struct BindSupport<QJsonBuilderImpl,const char*> : BindNative {};
template<> struct BindSupport<QJsonBuilderImpl, bool&> : BindNative {};
template<> struct BindSupport<QJsonBuilderImpl, double&> : BindNative {};
template<> struct BindSupport<QJsonBuilderImpl, int&> : BindNative {}; // TODO remove
template<typename T> struct BindSupport<QJsonBuilderImpl,T&,typename std::enable_if<std::is_arithmetic<T>::value,T&>::type> : BindNative {};
template<typename T> struct BindSupport<QJsonBuilderImpl,T&,typename std::enable_if<std::is_integral<T>::value>::type> : BindNative {};
// --------------------------------------------------------------------------
......@@ -170,7 +169,7 @@ protected:
bool _bind(QString& v) { if (current()->isString()) { v = current()->toString(); return true; } reportError(qBindExpectedText ); return false; }
bool _bind( bool& v) { if (current()->isBool ()) { v = current()->toBool (); return true; } reportError(qBindExpectedBoolean ); return false; }
bool _bind( double& v) { if (current()->isDouble()) { v = current()->toDouble(); return true; } reportError(qBindExpectedDecimal ); return false; }
template<typename T> bool _bind(T& t, typename std::enable_if<std::is_arithmetic<T>::value>::type* = nullptr) { double d; if (_bind(d)) { t = d; return true; } return false; }
template<typename T> bool _bind(T& t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr) { double d; if (_bind(d)) { t = d; return true; } return false; }
template<class T_> friend class Seq; // calls methods below
......@@ -190,8 +189,7 @@ template<> struct BindSupport<JsonVisitorImpl,const char*> : BindNative {};
template<> struct BindSupport<JsonVisitorImpl, QString&> : BindNative {};
template<> struct BindSupport<JsonVisitorImpl, bool&> : BindNative {};
template<> struct BindSupport<JsonVisitorImpl, double&> : BindNative {};
template<> struct BindSupport<JsonVisitorImpl, int&> : BindNative {}; // TODO remove
template<typename T> struct BindSupport<JsonVisitorImpl,T&,typename std::enable_if<std::is_arithmetic<T>::value,T&>::type> : BindNative {};
template<typename T> struct BindSupport<JsonVisitorImpl,T&,typename std::enable_if<std::is_integral<T>::value>::type> : BindNative {};
// --------------------------------------------------------------------------
......@@ -255,8 +253,7 @@ template<> struct BindSupport<QJsonWriterImpl,const char*> : BindNative {};
template<> struct BindSupport<QJsonWriterImpl, bool&> : BindNative {};
template<> struct BindSupport<QJsonWriterImpl, float&> : BindNative {};
template<> struct BindSupport<QJsonWriterImpl, double&> : BindNative {};
template<> struct BindSupport<QJsonWriterImpl, int&> : BindNative {}; // TODO remove
template<typename T> struct BindSupport<QJsonWriterImpl,T&,typename std::enable_if<std::is_integral<T>::value,T&>::type> : BindNative {};
template<typename T> struct BindSupport<QJsonWriterImpl,T&,typename std::enable_if<std::is_integral<T>::value>::type> : BindNative {};
// --------------------------------------------------------------------------
......@@ -484,8 +481,7 @@ template<> struct BindSupport<QJsonReaderImpl,QByteArray&> : BindNative {};
template<> struct BindSupport<QJsonReaderImpl, bool&> : BindNative {};
template<> struct BindSupport<QJsonReaderImpl, float&> : BindNative {};
template<> struct BindSupport<QJsonReaderImpl, double&> : BindNative {};
template<> struct BindSupport<QJsonReaderImpl, int&> : BindNative {}; // TODO remove
template<typename T> struct BindSupport<QJsonReaderImpl,T&,typename std::enable_if<std::is_integral<T>::value,T&>::type> : BindNative {};
template<typename T> struct BindSupport<QJsonReaderImpl,T&,typename std::enable_if<std::is_integral<T>::value>::type> : BindNative {};
// //////////////////////////////////////////////////////////////////////////
// QBind<TResult,QJson*> support
......
......@@ -108,6 +108,7 @@ using Text = Utf8Result<TextWriter>;
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qfile.h>
#include <QtCore/qbuffer.h>
#include <QtCore/qdatastream.h>
#include <QtCore/qdebug.h>
#include <QtCore/qjsonvalue.h>
#include <QtCore/qjsondocument.h>
......@@ -158,6 +159,16 @@ int main()
// TODO Benchmark against QDataStream
GROUP("<atoms")
{
START {
b.seek(0); b.buffer().clear();
QDataStream(&b)
<< 1.333333333333f
<< PI
<< text
<< false
;
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
START {
s.clear();
QDebug(&s)
......@@ -220,6 +231,14 @@ int main()
GROUP_STOP;
GROUP("<doubles")
{
START {
b.seek(0); b.buffer().clear();
QDataStream data(&b);
for (int i=0; i < 16; i++) {
data << transform[i];
};
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
START {
s.clear();
QDebug data(&s);
......@@ -258,12 +277,24 @@ int main()
GROUP_STOP
GROUP("<Person")
{
START {
b.seek(0); b.buffer().clear();
QDataStream(&b)
<< person.firstName.constData()
<< person. lastName.constData()
<< person. height
<< person. age
<< person. phones
;
}
STOP("QDataStream",QString::fromUtf8(b.buffer().toHex()));
START {
s.clear();
QDebug(&s) << '['
<< person.firstName << '|'
<< person. lastName << '|'
<< person. height << '|'
<< person. age << '|'
<< person. phones << '|'
;
}
......
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