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

WIP fixed a few issues

parent a7f543eb
......@@ -122,8 +122,8 @@ static QName qmChildren = "children"; //!< name of a sequence of records with re
template<class T_> class Val;
enum BindMode { Read=0, Write=1 }; //!< Specifies QBind::bind traversal and processing (the design would support other BindMode like Append or Diff)
template<class TResult> using IsReader = typename std::enable_if<TResult::Mode==Read ,TResult>::type;
template<class TResult> using IsWriter = typename std::enable_if<TResult::Mode==Write,TResult>::type;
template<class TResult> using IsReader = typename std::enable_if<TResult::Mode==Read >::type;
template<class TResult> using IsWriter = typename std::enable_if<TResult::Mode==Write>::type;
template<class T> using RemoveCvRef = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
......@@ -304,7 +304,7 @@ private:
bool _item( ) { return Q_LIKELY(impl) && impl->_item( ); }
bool _out ( ) { return Q_LIKELY(impl) && impl->_out ( ); }
private:
Cur _unsafeCopy() { return Cur(impl); }
Cur _unsafeCopy() { return impl ? Cur(impl) : Cur(); }
TImpl* impl = nullptr;
};
......@@ -344,7 +344,7 @@ struct IWriter
// TODO QChar, QDateTime, QDate, QTime, QUuid, QUrl, QRegularExpression, QMimeData
template<typename T> bool _bind(T& t) { return _bind(const_cast<const T&>(t)); } //!< Call _bind(T&&) with a single const T& copy by default \warning Cannot std::move(t) since Write must not change t
template<typename T> typename std::enable_if<!std::is_reference<T>::value,bool>::type _bind(const T& t) { T copy(t); return _bind(std::move(copy)); } //!< Call _bind(T&&) with a single const T& copy by default \warning Cannot std::move(t) since Write must not change t
virtual bool _bind(const QString& s) { return _bind(s.toUtf8().constData()); }
// TODO Other BindNative to avoid a copy
......@@ -510,7 +510,7 @@ struct QBind<TResult, T, typename std::enable_if<std::is_unsigned<T>::value && s
}
static TResult bind(Val<TResult>&& src, T& t) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(t));
return bind(std::move(src),T(t));
}
else /*constexpr*/ if (TResult::Mode==Read) {
qulonglong u; auto r=src.bind(u); if (r) { t=u; } return r;
......@@ -520,14 +520,14 @@ struct QBind<TResult, T, typename std::enable_if<std::is_unsigned<T>::value && s
template<class TResult, typename T>
struct QBind<TResult, T, typename std::enable_if<std::is_signed<T>::value && std::is_integral<T>::value && !std::is_same<T,bool>::value>::type> {
static TResult bind(Val<TResult>&& dst, T&& t) {
/*constexpr*/ if (TResult::Mode==Write) {
// /*constexpr*/ if (TResult::Mode==Write) {
return dst.bind(qlonglong(t));
}
// FIXME static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
// }
// FIXME static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
}
static TResult bind(Val<TResult>&& src, T& t) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(t));
return bind(std::move(src),T(t));
}
else /*constexpr*/ if (TResult::Mode==Read) {
qlonglong u; auto r=src.bind(u); if (r) { t=u; } return r;
......@@ -537,21 +537,15 @@ struct QBind<TResult, T, typename std::enable_if<std::is_signed<T>::value && std
template<class TResult, typename T, unsigned Size>
struct QBind<TResult, T[Size]> {
static TResult bind(Val<TResult>&& dst, T(&& src)[Size]) {
static TResult bind(Val<TResult>&& src, T(& dst)[Size]) {
/*constexpr*/ if (TResult::Mode==Write) {
quint32 size=Size;
auto s(dst.sequence(&size));
for (auto&& t : src) {
auto s(src.sequence(&size));
for (auto&& t : dst) {
s = s.bind(t);
}
return s;
}
static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
}
static TResult bind(Val<TResult>&& src, T(& dst)[Size]) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(dst));
}
else /*constexpr*/ if (TResult::Mode==Read) {
auto s(src.sequence());
Val<Seq<TResult>> i; unsigned j=0;
......@@ -572,8 +566,17 @@ struct QBind<TResult, T[Size]> {
template<class TResult>
struct QBind<TResult, QString> {
static TResult bind(Val<TResult>&& dst, QString&& src) {
/*constexpr*/ if (TResult::Mode==Write) {
return dst.bind(src.toUtf8().constData());
}
//static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
}
static TResult bind(Val<TResult>&& src, QString& dst) {
/*constexpr*/ if (TResult::Mode==Read) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),QString(dst));
}
else /*constexpr*/ if (TResult::Mode==Read) {
QByteArray ba;
auto r = src.bind(ba); // FIXME QByteArray is raw data that does not necessarily represent a utf8 string
if (r) {
......@@ -581,7 +584,6 @@ struct QBind<TResult, QString> {
}
return r;
}
static_assert(TResult::Mode==Read,"Unsupported TResult::Mode");
}
};
......@@ -590,19 +592,24 @@ struct QBind<TResult, QString> {
template<class TResult, typename T>
struct QBind<TResult, QVector<T>> {
static TResult bind(Val<TResult>&& dst, QVector<T>&& src) {
/*constexpr*/ if (TResult::Mode==Write) {
// /*constexpr*/ if (TResult::Mode==Write) {
quint32 size=src.size();
auto s(dst.sequence(&size));
for (auto&& t : src) {
s = s.bind(t);
}
return s;
}
//static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
// }
// static_assert(TResult::Mode==Write,"Unsupported TResult::Mode");
}
static TResult bind(Val<TResult>&& src, QVector<T>& dst) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(dst));
quint32 size=dst.size();
auto s(src.sequence(&size));
for (auto&& t : dst) {
s = s.bind(t);
}
return s;
}
else /*constexpr*/ if (TResult::Mode==Read) {
auto s(src.sequence());
......@@ -634,7 +641,7 @@ struct QBind<TResult, QList<T>> {
}
static TResult bind(Val<TResult>&& src, QList<T>& dst) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(dst));
return bind(std::move(src),QList<T>(dst));
}
else /*constexpr*/ if (TResult::Mode==Read) {
auto s(src.sequence());
......@@ -666,7 +673,7 @@ struct QBind<TResult, QMap<QString,T>> {
}
static TResult bind(Val<TResult>&& src, QMap<QString,T>& dst) {
/*constexpr*/ if (TResult::Mode==Write) {
return bind(std::move(src),std::move(dst));
return bind(std::move(src),QMap<QString,T>(dst));
}
else /*constexpr*/ if (TResult::Mode==Read) {
auto s(src.record());
......@@ -693,7 +700,7 @@ struct QBind<TResult, QColor> {
.bind("B",src.blue ());
}
static TResult bind(Val<TResult>&& dst, QColor& src) {
return bind(std::move(dst),std::move(src));
return bind(std::move(dst),QColor(src));
}
};
......
......@@ -97,6 +97,6 @@ template<typename T> struct BindSupport<QDataWriter, T,typename std::enable
// --------------------------------------------------------------------------
// Providing a general QDataStreamReader may be deceiving because the QDataStream structure is implicit:
// Providing a general QDataReader may be deceiving because the QDataStream structure is implicit:
// A reader is assumed to specify exactly what to read based on the stream origin and version
// QVariant could be used though for parts which type are not known in advance
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