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

cosmetic changes

WIP simplified ModelWriter as just IWriter
parent 4ed1be47
......@@ -55,7 +55,7 @@ protected: \
#include <QtCore/qbytearray.h>
using Name = const char*;
using Name = const char*; // utf8 encoded
// //////////////////////////////////////////////////////////////////////////
// Standard error names
......@@ -177,7 +177,7 @@ public:
/**/ Val<T_> meta ( MetaData&& m) { auto mref=m; return meta(mref); }
/**/ Val<T_> meta ( MetaData& m) { if (Q_LIKELY(m_out)) m_out->_meta(m); return std::move(*this); }
// TODO ? Add bind with default T specialised for Reader/Writer (do not write default?) or use meta since default T values may not be appropriate (e.g. for bool)
// TODO ? Add bind with default T specialised for Reader/Writer
/**/ Seq<T_> sequence(quint32* s=nullptr) { if (Q_LIKELY(m_out) && m_out->_sequence ( s)) return Seq<T_>(std::move(m_out)); else return Seq<T_>(); }
/**/ Rec<T_> record (quint32* s=nullptr) { if (Q_LIKELY(m_out) && m_out->_record ( s)) return Rec<T_>(std::move(m_out)); else return Rec<T_>(); }
......@@ -654,11 +654,15 @@ struct IWriter
virtual bool _bind ( QString& s) { return _bind(s.toUtf8().constData()); }
virtual bool _bind ( bool& s) { return _bind(s ? "true" : "false"); }
virtual bool _bind ( float& n) { auto s(QByteArray::number(n,'g',std::numeric_limits< float>::max_digits10)); return _bind(s.constData()); } // with specific precision
virtual bool _bind ( double& n) { auto s(QByteArray::number(n,'g',std::numeric_limits<double>::max_digits10)); return _bind(s.constData()); } // with specific precision
virtual bool _bind ( qulonglong& s) { char n[1+std::numeric_limits<qulonglong>::digits10+1]; ulltoa(s,n,sizeof(n)); return _bind(static_cast<const char*>(n)); }; // handling all unsigned integral types
virtual bool _bind ( qlonglong& s) { char n[1+std::numeric_limits< qlonglong>::digits10+1]; lltoa(s,n,sizeof(n)); return _bind(static_cast<const char*>(n)); }; // handling all signed integral types
virtual bool _bind ( QByteArray& s) { return _bind(s.constData()); }
virtual bool _bind ( float& n) { auto s(QByteArray::number(double(n),'g',std::numeric_limits< float>::max_digits10)); return _bind(s.constData()); } // with specific precision
virtual bool _bind ( double& n) { auto s(QByteArray::number( n ,'g',std::numeric_limits<double>::max_digits10)); return _bind(s.constData()); } // with specific precision
#if Q_CC_MSVC
# define ulltoa _ui64toa
# define lltoa _i64toa
#endif
virtual bool _bind ( qulonglong& s) { char n[1+std::numeric_limits<qulonglong>::digits10+1]; ulltoa(s,n,sizeof(n)); return _bind(static_cast<const char*>(n)); } // handling all unsigned integral types
virtual bool _bind ( qlonglong& s) { char n[1+std::numeric_limits< qlonglong>::digits10+1]; lltoa(s,n,sizeof(n)); return _bind(static_cast<const char*>(n)); } // handling all signed integral types
virtual bool _bind ( QByteArray& s) { QByteArray hex("0x"); hex.append(s.toHex()); return _bind(hex.constData()); }
// TODO QChar, QDateTime, QDate, QTime, QUuid, QUrl, QRegularExpression
};
......@@ -670,7 +674,6 @@ protected:
Writer &operator=(const Writer &) = delete;
public:
Q_ENABLE_MOVE(Writer, std::swap(impl, o.impl); )
// TODO for safety ? ~Writer() { if (impl) impl->_end(); }
Writer(IWriter* i) : impl(i) { Q_ASSERT(impl); }
operator bool() { return impl && impl->operator bool(); } // for QMovedWriter
......
......@@ -182,7 +182,7 @@ private:
}
QIODevice* io = nullptr;
std::vector<bool> levels; //!< minimal dynamic context to ensure well-formedness in case TResult is abandoned: true indicates Definite levels with prefixed size
std::vector<bool> levels; //!< minimal dynamic context to ensure well-formedness in case TResult is not returned: true indicates Definite levels with prefixed size
};
template<> struct BindSupport<CborWriter,const char*> : BindNative {};
template<> struct BindSupport<CborWriter,QByteArray&> : BindNative {};
......
......@@ -263,7 +263,7 @@ private:
}
QIODevice* io;
QStack<Step> levels = QStack<Step>(); // TODO Replace with 2 std::vector<bool> for performance //!< minimal dynamic context to implement out() and ensure well-formedness in case TResult is abandoned
QStack<Step> levels = QStack<Step>(); // TODO Replace with std::vector<bool> for performance //!< minimal dynamic context to implement out() and ensure well-formedness in case TResult is abandoned
};
// --------------------------------------------------------------------------
......
......@@ -46,22 +46,16 @@
#include "QBind_impl.h"
// //////////////////////////////////////////////////////////////////////////
// QBind<QModel*,T> support
// QBind<Q*Model,T> support
class ModelWriter : public QMovedWriter<ModelWriter>, public IWriter
class ModelWriter : public IWriter
{
protected:
ModelWriter(const ModelWriter &o) : QMovedWriter(), m(o.m) {}
ModelWriter &operator=(const ModelWriter &) = delete;
Q_DISABLE_COPY(ModelWriter)
public:
Q_ENABLE_MOVE(ModelWriter, std::swap(m, o.m); std::swap(idx, o.idx); )
ModelWriter(QAbstractItemModel* m) : m(m), idx(), d(Vertical) { Q_ASSERT(m); }
operator bool() { return true; }
Val<Writer> meta(MetaData& m) { return Writer(this).meta(m); }
protected:
friend class QMovedWriter<ModelWriter>;
template<class T_> friend class Val; // calls methods below
bool _sequence(quint32* rows=nullptr) { if (d==Child || !rows) { d=Vertical ; idx=idx.child(0,0); } else
if (d==Vertical ) { d=Horizontal; } else
if (d==Horizontal ) { d=Child ; }
......@@ -77,12 +71,10 @@ protected:
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 ( qint32& i) { return m->setData(idx, QVariant(i)); }
bool _bind ( quint32& u) { return m->setData(idx, QVariant(u)); }
// TODO BindNative all types in IWriter and http://doc.qt.io/qt-5/qstyleditemdelegate.html#details ?
template<class T_> friend class Seq; // calls methods below
template<class T_> friend class Rec; // calls methods below
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/qstyleditemdelegate.html#details ?
bool _item(QByteArray& k) { idx = d==Vertical ? idx.siblingAtRow(idx.row()+1) : idx.siblingAtColumn(idx.column()+1);
m->setHeaderData(d==Vertical ? idx.row() : idx.column(), d==Vertical ? Qt::Vertical : Qt::Horizontal, k);
......@@ -94,8 +86,6 @@ protected:
idx = d==Child ? idx.parent() : ? idx.siblingAtColumn(idx.column()+1); }
private:
QAbstractItemModel* m ;
QModelIndex idx;
enum Dimension { Vertical = Qt::Vertical, Horizontal = Qt::Horizontal, Child } d;
// TODO
// Encode _sequence(n) or _record(n) as above
......@@ -107,13 +97,5 @@ private:
// Encode cols or rows > 0 as
// TODO setHeaderData on 1st item and
};
template<> struct BindSupport<ModelWriter,const char*> : BindNative {};
template<> struct BindSupport<ModelWriter, QString&> : BindNative {};
template<> struct BindSupport<ModelWriter, bool&> : BindNative {};
template<> struct BindSupport<ModelWriter, float&> : BindNative {};
template<> struct BindSupport<ModelWriter, double&> : BindNative {};
template<> struct BindSupport<ModelWriter, qint32&> : BindNative {};
template<> struct BindSupport<ModelWriter, quint32&> : BindNative {};
// TODO BindNative a subset of QVariant types
// --------------------------------------------------------------------------
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