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

WIP QBind<_,T>::bind &&, &, const & as needed for performance

parent 58ead5f9
This diff is collapsed.
......@@ -125,9 +125,8 @@ protected:
? putInteger (*cols , cbor::MapType )
: putMajorValue (cbor::IndefiniteLength, cbor::MapType ); }
bool _null ( ) { return putSimpleValue(cbor::Null ); }
bool _bind ( QByteArray& s) { return putInteger (quint64(s.size()) ,cbor::ByteStringType) && (Q_LIKELY(io->write(s)) || *s=='\0'); }
bool _bind ( const char* s) { return putInteger (strlen(s) ,cbor::TextStringType) && (Q_LIKELY(io->write(s)) || *s=='\0'); }
bool _bind ( QString& s) { QUtf8String u(s.toUtf8());
bool _bind ( QString&& s) { QUtf8String u(s.toUtf8());
return putInteger (quint64(u.size()) ,cbor::TextStringType) && (Q_LIKELY(io->write(u)) || u.isEmpty()); }
//static const char mimeHeader[] = "Content-Type:text/plain;charset=utf-16\xD\xA\xD\xA";
//QByteArray utf16(QByteArray::fromRawData(reinterpret_cast<const char*>(s.utf16()), s.size()*int(sizeof(QChar))));
......@@ -135,13 +134,14 @@ protected:
// putInteger (sizeof(mimeHeader)+
// utf16.size() ,cbor::ByteStringType) && io->write(mimeHeader, sizeof(mimeHeader))
// && (Q_LIKELY(io->write(utf16)) || s[0]==QChar('\0')); }
bool _bind ( bool& b) { return putSimpleValue(b ? cbor::True : cbor::False); }
bool _bind ( float& n) { return Q_LIKELY(putSimpleValue(cbor::Next32BitFloat)) && putBigEndian(n); }
bool _bind ( double& n) { return Q_LIKELY(putSimpleValue(cbor::Next64BitFloat)) && putBigEndian(n); }
bool _bind ( QByteArray&& s) { return putInteger (quint64(s.size()) ,cbor::ByteStringType) && (Q_LIKELY(io->write(s)) || *s=='\0'); }
bool _bind ( bool&& b) { return putSimpleValue(b ? cbor::True : cbor::False); }
bool _bind ( float&& n) { return Q_LIKELY(putSimpleValue(cbor::Next32BitFloat)) && putBigEndian(n); }
bool _bind ( double&& n) { return Q_LIKELY(putSimpleValue(cbor::Next64BitFloat)) && putBigEndian(n); }
// This dispatch would be more simple with C++17 constexpr if
bool _bind ( qulonglong& t) { return putInteger(quint64( t), cbor::UnsignedIntType); }
bool _bind ( qlonglong& t) { return t<0 ? putInteger(quint64(-1-t), cbor::NegativeIntType) // see https://tools.ietf.org/html/rfc7049#section-2.1
bool _bind ( qulonglong&& t) { return putInteger(quint64( t), cbor::UnsignedIntType); }
bool _bind ( qlonglong&& t) { return t<0 ? putInteger(quint64(-1-t), cbor::NegativeIntType) // see https://tools.ietf.org/html/rfc7049#section-2.1
: putInteger(quint64( t), cbor::UnsignedIntType); }
bool _item(QName n) { return (Q_LIKELY(putInteger(qstrlen(n), cbor::TextStringType)) && (Q_LIKELY(io->write(n)) || *n=='\0')); }
......
......@@ -71,7 +71,7 @@ protected:
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; }
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); }
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); } // TODO &&
template<typename T>
bool _bind ( T&& t) { *io << t; return true; } // Use QVariant to explicit the parts that may be unknown to the reader
......@@ -86,11 +86,11 @@ private:
};
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, 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<
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 {};
......
This diff is collapsed.
......@@ -81,15 +81,15 @@ protected:
}
}
bool _null( ) { return m->setData(idx, QVariant( )); }
bool _bind(const char* s) { return m->setData(idx, QVariant(s)); }
bool _bind( QString& s) { return m->setData(idx, QVariant(s)); }
bool _bind( bool& b) { return m->setData(idx, QVariant(b)); }
bool _bind( float& f) { return m->setData(idx, QVariant(f)); }
bool _bind( double& d) { return m->setData(idx, QVariant(d)); }
bool _bind(qulonglong& i) { return m->setData(idx, QVariant(i)); }
bool _bind( qlonglong& u) { return m->setData(idx, QVariant(u)); }
bool _bind(QByteArray& b) { return m->setData(idx, QVariant(b)); }
bool _null( ) { return m->setData(idx, QVariant( )); }
bool _bind( const char* s) { return m->setData(idx, QVariant(s)); }
bool _bind( QString&& s) { return m->setData(idx, QVariant(s)); }
bool _bind( bool&& b) { return m->setData(idx, QVariant(b)); }
bool _bind( float&& f) { return m->setData(idx, QVariant(f)); }
bool _bind( double&& d) { return m->setData(idx, QVariant(d)); }
bool _bind(qulonglong&& i) { return m->setData(idx, QVariant(i)); }
bool _bind( qlonglong&& u) { return m->setData(idx, QVariant(u)); }
bool _bind(QByteArray&& b) { return m->setData(idx, QVariant(b)); }
// TODO BindNative all types in http://doc.qt.io/qt-5/qitemeditorfactory.html#details ?
bool _out ( ) { if (d> T) { --d; return true; } return false; }
......
......@@ -60,7 +60,7 @@ public:
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; }
bool _bind ( T&& t) { set(QVariant::fromValue(t)); return true; }
bool _bind ( const char* t) { set(QVariant (t)); return true; }
bool _null ( ) { set(QVariant ( )); return true; }
......@@ -136,27 +136,38 @@ private:
//// QBind<TResult,QVariant&> example support for the fixed set of QVariantBuilder's BindNative types + other convenient types
template<class TResult>
struct QBind<TResult, QVariant&, IsWriter<TResult>> { static TResult bind(Val<TResult>&& dst, QVariant& src) {
if (src.type()==QVariant::List ) return dst.bind(src.value<QVariantList>()); // TODO QSequentialIterable ?
if (src.type()==QVariant::Map ) return dst.bind(src.value<QVariantMap >()); // TODO QAssociativeIterable ?
// TODO QVariant::Hash
if (src.type()==QVariant::Bool ) return dst.bind(src.value< bool>());
if (src.type()==QVariant::ByteArray) return dst.bind(src.value< QByteArray>());
if (src.type()==QVariant::String ) return dst.bind(src.value< QString>());
if (src.type()==QVariant::Char ) return dst.bind(src.toString());
if (src.type()==QVariant::ULongLong) return dst.bind(src.value< qulonglong>());
if (src.type()==QVariant::UInt ) return dst.bind(src.value<unsigned int>());
if (src.type()==QVariant::LongLong ) return dst.bind(src.value< qlonglong>());
if (src.type()==QVariant::Int ) return dst.bind(src.value< int>());
if (src.type()==QVariant::Double ) return dst.bind(src.value< double>());
// TODO convert builtin types which canConvert<QString>
// \sa QBind<TSrcResult, Val<TDst>&&, IsReader<TSrcResult>>
return dst.null();
}};
struct QBind<TResult, QVariant> {
static TResult bind(Val<TResult>&& dst, QVariant&& src) {
/*constexpr*/ if (TResult::Mode==Write) {
if (src.type()==QVariant::List ) return dst.bind(src.value<QVariantList>()); // TODO QSequentialIterable ?
if (src.type()==QVariant::Map ) return dst.bind(src.value<QVariantMap >()); // TODO QAssociativeIterable ?
// TODO QVariant::Hash
if (src.type()==QVariant::Bool ) return dst.bind(src.value< bool>());
if (src.type()==QVariant::ByteArray) return dst.bind(src.value< QByteArray>());
if (src.type()==QVariant::String ) return dst.bind(src.value< QString>());
if (src.type()==QVariant::Char ) return dst.bind(src.toString());
if (src.type()==QVariant::ULongLong) return dst.bind(src.value< qulonglong>());
if (src.type()==QVariant::UInt ) return dst.bind(src.value<unsigned int>());
if (src.type()==QVariant::LongLong ) return dst.bind(src.value< qlonglong>());
if (src.type()==QVariant::Int ) return dst.bind(src.value< int>());
if (src.type()==QVariant::Double ) return dst.bind(src.value< double>());
// TODO convert builtin types which canConvert<QString>
// \sa QBind<TSrcResult, Val<TDst>&&, IsReader<TSrcResult>>
return dst.null();
}
static_assert(TResult::Mode!=Write,"Unsupported TResult::Mode");
}
static TResult bind(Val<TResult>&& src, QVariant& dst) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(dst));
}
static_assert(TResult::Mode!=Write,"Unsupported TResult::Mode");
}
};
//template<class TResult>
//struct QBind<TResult, QVariant&, IsReader<TResult>> { static TResult bind(Val<TResult>&& src, QVariant& dst) {
......
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