32#ifndef _QX_CONVERT_IMPL_H_
33#define _QX_CONVERT_IMPL_H_
68#define QX_STR_CVT_QDATE_FORMAT "yyyyMMdd"
69#define QX_STR_CVT_QTIME_FORMAT "hhmmsszzz"
70#define QX_STR_CVT_QDATETIME_FORMAT "yyyyMMddhhmmsszzz"
72#ifdef _QX_ENABLE_BOOST_SERIALIZATION
73#if _QX_SERIALIZE_POLYMORPHIC
74#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::polymorphic_xml
75#elif _QX_SERIALIZE_XML
76#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::xml
77#elif _QX_SERIALIZE_TEXT
78#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::text
79#elif _QX_SERIALIZE_BINARY
80#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::binary
83#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::qt
86#define QX_CVT_USING_ARCHIVE_IMPL(className) \
87namespace qx { namespace cvt { namespace detail { \
88template <> struct QxConvert_ToString< className > { \
89static inline QString toString(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
90{ Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
91template <> struct QxConvert_FromString< className > { \
92static inline qx_bool fromString(const QString & s, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
93{ Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
94template <> struct QxConvert_ToVariant< className > { \
95static inline QVariant toVariant(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
96{ Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
97template <> struct QxConvert_FromVariant< className > { \
98static inline qx_bool fromVariant(const QVariant & v, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
99{ Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); QString s = v.toString(); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
102#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
103#define QX_JSON_DATE_TIME_FORMAT Qt::ISODateWithMs
104#define QX_JSON_DATE_TIME_FORMAT_SIZE 23
106#define QX_JSON_DATE_TIME_FORMAT Qt::ISODate
107#define QX_JSON_DATE_TIME_FORMAT_SIZE 19
122inline bool checkConvertQVariantToString(
const QVariant & v) {
return ((v.type() == QVariant::List) || (v.type() == QVariant::Map) || (v.type() == QVariant::Hash) || (v.type() == QVariant::StringList)); }
126template <
typename T,
typename H>
130 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_ToString",
"template must be specialized"); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QString(); }
133template <
typename T,
typename H>
137 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_FromString",
"template must be specialized"); Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return qx_bool(); }
140template <
typename T,
typename H>
144 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_ToVariant",
"template must be specialized"); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QVariant(); }
147template <
typename T,
typename H>
151 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_FromVariant",
"template must be specialized"); Q_UNUSED(v); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return qx_bool(); }
156template <
typename T,
typename H>
159 static inline QJsonValue
toJson(
const T & t,
const QString & format)
160 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_ToJson",
"template must be specialized"); Q_UNUSED(t); Q_UNUSED(format);
return QJsonValue(); }
163template <
typename T,
typename H>
167 {
qAssertMsg(
false,
"qx::cvt::detail::QxConvertHelper_FromJson",
"template must be specialized"); Q_UNUSED(j); Q_UNUSED(t); Q_UNUSED(format);
return qx_bool(); }
176 enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
180 Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
181 static_assert(qx_need_to_specialize_template_convert_to_string_from_string,
"qx_need_to_specialize_template_convert_to_string_from_string");
191 enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
195 Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
196 static_assert(qx_need_to_specialize_template_convert_to_string_from_string,
"qx_need_to_specialize_template_convert_to_string_from_string");
211 template <
bool isQVariantCompatible ,
int dummy>
217 {
static inline QVariant
toVariant(
const T & t,
const QString & format,
int index,
qx::cvt::context::ctx_type ctx) { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QVariant(t); }; };
230 template <
bool isQVariantCompatible ,
int dummy>
245 static inline QJsonValue
toJson(
const T & t,
const QString & format)
262 enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
266 Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
268 return t.toJson(format);
270 static_assert(qx_need_to_specialize_template_convert_to_string_from_string,
"qx_need_to_specialize_template_convert_to_string_from_string");
281 enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
285 Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
287 return t.fromJson(s, format);
289 static_assert(qx_need_to_specialize_template_convert_to_string_from_string,
"qx_need_to_specialize_template_convert_to_string_from_string");
300 enum { qx_need_to_specialize_template_convert_to_variant_from_variant = 0 };
304 Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
306 return QVariant(t.toJson(format));
308 static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant,
"qx_need_to_specialize_template_convert_to_variant_from_variant");
319 enum { qx_need_to_specialize_template_convert_to_variant_from_variant = 0 };
323 Q_UNUSED(v); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
325 return t.fromJson(v.toString(), format);
327 static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant,
"qx_need_to_specialize_template_convert_to_variant_from_variant");
339 static inline QJsonValue
toJson(
const T & t,
const QString & format)
385 static inline QJsonValue
toJson(
const T & t,
const QString & format)
447 static inline QJsonValue
toJson(
const T & t,
const QString & format)
464 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
471 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); }
478 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
485 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, v.toString()); }
493 static inline QJsonValue
toJson(
const T & t,
const QString & format)
510 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QString::number(
static_cast<long>(t)); }
517 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
bool bOk =
false; t =
static_cast<T
>(
static_cast<long>(s.toLongLong(& bOk)));
return bOk; }
524 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
return QVariant(
static_cast<qlonglong
>(t)); }
531 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
bool bOk =
false; t =
static_cast<T
>(
static_cast<long>(v.toLongLong(& bOk)));
return bOk; }
539 static inline QJsonValue
toJson(
const T & t,
const QString & format)
540 { Q_UNUSED(format);
return QJsonValue(
static_cast<int>(t)); }
547 { Q_UNUSED(format); t =
static_cast<T
>(
static_cast<long>(qRound(j.toDouble())));
return qx_bool(
true); }
604 static inline QJsonValue
toJson(
const T & t,
const QString & format)
621#include "../../inl/QxConvert/QxConvert_WithIndex.inl"
622#include "../../inl/QxConvert/QxConvert_ToString.inl"
623#include "../../inl/QxConvert/QxConvert_FromString.inl"
624#include "../../inl/QxConvert/QxConvert_ToVariant.inl"
625#include "../../inl/QxConvert/QxConvert_FromVariant.inl"
626#include "../../inl/QxConvert/QxConvert_ToJson.inl"
627#include "../../inl/QxConvert/QxConvert_FromJson.inl"
628#include "../../inl/QxConvert/QxConvert_Qt.inl"
Common interface (abstract class) for persistents classes using QX_PERSISTABLE_HPP() and QX_PERSISTAB...
Provide some tools to serialize a class registered into QxOrm context into/from binary/XML archive (f...
qx_bool : QxOrm library boolean type with code and description message when an error occured
Concrete class registered into QxOrm context.
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
Helper class to store a date value into database under neutral format (YYYYMMDD) => cross database co...
Helper class to store a date-time value into database under neutral format (YYYYMMDDHHMMSS) => cross ...
Invalid value when a property fails to pass a constraint.
#define qAssertMsg(test, where, what)
Used when _QX_ENABLE_BOOST_SERIALIZATION compilation option is not defined to provide serialization e...
Include all Qt QDataStream serialization method (save/load) provided by QxOrm library.
Provide a generic Qt QJson serialization method (save/load) for classes registered into QxOrm context...
Define a user SQL query added to default SQL query builded by QxOrm library, and used by qx::dao::xxx...
Helper class to store a time value into database under neutral format (HHMMSS) => cross database comp...
qx::IxDataMember : common interface for all class properties registered into QxOrm context
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)=0
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const =0
qx::IxPersistable : common interface (abstract class) for persistents classes using QX_PERSISTABLE_HP...
qx_bool : boolean type with code and description message when an error occured
static T * getSingleton()
qx::trait::construct_ptr<T>::get(T & t, bool bReset = false) : instantiate (or reset) a new pointer,...
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
Register all primitive and useful types of stl, boost and Qt libraries using QX_REGISTER_CLASS_NAME(T...
qx::trait::is_container<T>::value : return true if T is a container from stl, boost,...
qx::trait::is_qt_variant_compatible<T>::value : return true if T can be host into a QVariant object o...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...
bool checkConvertQVariantToString(const QVariant &v)
qx_bool from_variant(const QVariant &v, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
QVariant to_variant(const T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
QString to_string(const T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
qx_bool from_json(const QJsonValue &j, T &t, const QString &format=QString())
qx_bool from_string(const QString &s, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
QJsonValue to_json(const T &t, const QString &format=QString())
QString to_string(const T &obj, unsigned int flags=1)
qx_bool from_string(T &obj, const QString &sString, unsigned int flags=1)
qx_bool from_byte_array(T &obj, const QByteArray &data, unsigned int flags=1)
QByteArray to_byte_array(const T &obj, void *owner=NULL, unsigned int flags=1)
Root namespace for all QxOrm library features.
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QJsonValue toJson(const T &t, const QString &format)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QJsonValue toJson(const T &t, const QString &format)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
std::conditional< qx::trait::is_ix_persistable< T >::value, qx::cvt::detail::helper::QxConvertHelper_Persistable, qx::cvt::detail::helper::QxConvertHelper_Generic >::type type_str_cvt_helper_0
std::conditional< std::is_enum< T >::value, qx::cvt::detail::helper::QxConvertHelper_Enum, type_str_cvt_helper_4 >::type type_str_cvt_helper_5
std::conditional< qx::trait::is_qx_registered< T >::value, qx::cvt::detail::helper::QxConvertHelper_Registered, type_str_cvt_helper_3 >::type type_str_cvt_helper_4
std::conditional< qx::trait::is_smart_ptr< T >::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, type_str_cvt_helper_1 >::type type_str_cvt_helper_2
std::conditional< std::is_pointer< T >::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, type_str_cvt_helper_0 >::type type_str_cvt_helper_1
QxConvertHelper< T >::type_str_cvt_helper_5 type
std::conditional< qx::trait::is_container< T >::value, qx::cvt::detail::helper::QxConvertHelper_Container, type_str_cvt_helper_2 >::type type_str_cvt_helper_3
static QJsonValue save(const T &t, const QString &format)
static qx_bool load(const QJsonValue &j, T &t, const QString &format)
static void get(T &t, bool bReset=false)