QxOrm  1.4.9
C++ Object Relational Mapping library
QxConvert_Impl.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://www.qxorm.com/
00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifndef _QX_CONVERT_IMPL_H_
00033 #define _QX_CONVERT_IMPL_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00039 #include <QxConvert/QxConvert.h>
00040 #include <QxCommon/QxBool.h>
00041 
00042 #include <QxDao/QxDateNeutral.h>
00043 #include <QxDao/QxTimeNeutral.h>
00044 #include <QxDao/QxDateTimeNeutral.h>
00045 #include <QxDao/QxSqlQuery.h>
00046 #include <QxDao/IxPersistable.h>
00047 
00048 #include <QxCollection/QxCollection.h>
00049 
00050 #include <QxRegister/QxClass.h>
00051 
00052 #include <QxSerialize/QxArchive.h>
00053 #include <QxSerialize/QxSerializeQDataStream.h>
00054 #include <QxSerialize/QDataStream/QxSerializeQDataStream_all_include.h>
00055 #include <QxSerialize/QJson/QxSerializeQJson_qx_registered_class.h>
00056 
00057 #include <QxValidator/QxInvalidValue.h>
00058 #include <QxValidator/QxInvalidValueX.h>
00059 
00060 #include <QxTraits/is_smart_ptr.h>
00061 #include <QxTraits/is_container.h>
00062 #include <QxTraits/is_qx_registered.h>
00063 #include <QxTraits/is_qt_variant_compatible.h>
00064 #include <QxTraits/get_class_name_primitive.h>
00065 #include <QxTraits/construct_ptr.h>
00066 #include <QxTraits/generic_container.h>
00067 
00068 #define QX_STR_CVT_QDATE_FORMAT        "yyyyMMdd"
00069 #define QX_STR_CVT_QTIME_FORMAT        "hhmmsszzz"
00070 #define QX_STR_CVT_QDATETIME_FORMAT    "yyyyMMddhhmmsszzz"
00071 
00072 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00073 #if _QX_SERIALIZE_POLYMORPHIC
00074 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::polymorphic_xml
00075 #elif _QX_SERIALIZE_XML
00076 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::xml
00077 #elif _QX_SERIALIZE_TEXT
00078 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::text
00079 #elif _QX_SERIALIZE_BINARY
00080 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::binary
00081 #endif // _QX_SERIALIZE_XML
00082 #else // _QX_ENABLE_BOOST_SERIALIZATION
00083 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::qt
00084 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00085 
00086 #define QX_CVT_USING_ARCHIVE_IMPL(className) \
00087 namespace qx { namespace cvt { namespace detail { \
00088 template <> struct QxConvert_ToString< className > { \
00089 static inline QString toString(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
00090 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
00091 template <> struct QxConvert_FromString< className > { \
00092 static inline qx_bool fromString(const QString & s, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
00093 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
00094 template <> struct QxConvert_ToVariant< className > { \
00095 static inline QVariant toVariant(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
00096 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
00097 template <> struct QxConvert_FromVariant< className > { \
00098 static inline qx_bool fromVariant(const QVariant & v, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
00099 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); QString s = v.toString(); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
00100 } } } // namespace qx::cvt::detail
00101 
00102 #if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
00103 #define QX_JSON_DATE_TIME_FORMAT Qt::ISODateWithMs
00104 #define QX_JSON_DATE_TIME_FORMAT_SIZE 23 // yyyy-MM-ddTHH:mm:ss.zzz
00105 #else // (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
00106 #define QX_JSON_DATE_TIME_FORMAT Qt::ISODate
00107 #define QX_JSON_DATE_TIME_FORMAT_SIZE 19 // yyyy-MM-ddTHH:mm:ss
00108 #endif // (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
00109 
00110 namespace qx {
00111 namespace cvt {
00112 namespace detail {
00113 namespace helper {
00114 
00115 struct QxConvertHelper_Generic { };
00116 struct QxConvertHelper_Ptr { };
00117 struct QxConvertHelper_Registered { };
00118 struct QxConvertHelper_Persistable { };
00119 struct QxConvertHelper_Container { };
00120 struct QxConvertHelper_Enum { };
00121 
00122 inline bool checkConvertQVariantToString(const QVariant & v) { return ((v.type() == QVariant::List) || (v.type() == QVariant::Map) || (v.type() == QVariant::Hash) || (v.type() == QVariant::StringList)); }
00123 
00124 } // namespace helper
00125 
00126 template <typename T, typename H>
00127 struct QxConvertHelper_ToString
00128 {
00129    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00130    { 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(); }
00131 };
00132 
00133 template <typename T, typename H>
00134 struct QxConvertHelper_FromString
00135 {
00136    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00137    { 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(); }
00138 };
00139 
00140 template <typename T, typename H>
00141 struct QxConvertHelper_ToVariant
00142 {
00143    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00144    { 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(); }
00145 };
00146 
00147 template <typename T, typename H>
00148 struct QxConvertHelper_FromVariant
00149 {
00150    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00151    { 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(); }
00152 };
00153 
00154 #ifndef _QX_NO_JSON
00155 
00156 template <typename T, typename H>
00157 struct QxConvertHelper_ToJson
00158 {
00159    static inline QJsonValue toJson(const T & t, const QString & format)
00160    { qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_ToJson", "template must be specialized"); Q_UNUSED(t); Q_UNUSED(format); return QJsonValue(); }
00161 };
00162 
00163 template <typename T, typename H>
00164 struct QxConvertHelper_FromJson
00165 {
00166    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00167    { qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_FromJson", "template must be specialized"); Q_UNUSED(j); Q_UNUSED(t); Q_UNUSED(format); return qx_bool(); }
00168 };
00169 
00170 #endif // _QX_NO_JSON
00171 
00172 template <typename T>
00173 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00174 {
00175 
00176    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
00177 
00178    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00179    {
00180       Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00181       static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToString< MyType >'
00182       return QString();
00183    }
00184 
00185 };
00186 
00187 template <typename T>
00188 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00189 {
00190 
00191    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
00192 
00193    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00194    {
00195       Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00196       static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromString< MyType >'
00197       return qx_bool(true);
00198    }
00199 
00200 };
00201 
00202 template <typename T>
00203 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00204 {
00205 
00206    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00207    { return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::toVariant(t, format, index, ctx); }
00208 
00209 private:
00210 
00211    template <bool isQVariantCompatible /* = false */, int dummy>
00212    struct cvtQVariant
00213    { static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) { return qx::cvt::to_string(t, format, index, ctx); }; };
00214 
00215    template <int dummy>
00216    struct cvtQVariant<true, dummy>
00217    { 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); }; };
00218 
00219 };
00220 
00221 template <typename T>
00222 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00223 {
00224 
00225    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00226    { return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::fromVariant(v, t, format, index, ctx); }
00227 
00228 private:
00229 
00230    template <bool isQVariantCompatible /* = false */, int dummy>
00231    struct cvtQVariant
00232    { static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) { return qx::cvt::from_string(v.toString(), t, format, index, ctx); }; };
00233 
00234    template <int dummy>
00235    struct cvtQVariant<true, dummy>
00236    { static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); t = v.value<T>(); return qx_bool(true); }; };
00237 
00238 };
00239 
00240 #ifndef _QX_NO_JSON
00241 
00242 template <typename T>
00243 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00244 {
00245    static inline QJsonValue toJson(const T & t, const QString & format)
00246    { return QJsonValue::fromVariant(qx::cvt::detail::QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>::toVariant(t, format, -1, qx::cvt::context::e_no_context)); }
00247 };
00248 
00249 template <typename T>
00250 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
00251 {
00252    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00253    { QVariant v = j.toVariant(); return qx::cvt::detail::QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>::fromVariant(v, t, format, -1, qx::cvt::context::e_no_context); }
00254 };
00255 
00256 #endif // _QX_NO_JSON
00257 
00258 template <typename T>
00259 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00260 {
00261 
00262    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
00263 
00264    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00265    {
00266       Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00267 #ifndef _QX_NO_JSON
00268       return t.toJson(format);
00269 #else // _QX_NO_JSON
00270       static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToString< MyType >'
00271       return QString();
00272 #endif // _QX_NO_JSON
00273    }
00274 
00275 };
00276 
00277 template <typename T>
00278 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00279 {
00280 
00281    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
00282 
00283    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00284    {
00285       Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00286 #ifndef _QX_NO_JSON
00287       return t.fromJson(s, format);
00288 #else // _QX_NO_JSON
00289       static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromString< MyType >'
00290       return qx_bool(true);
00291 #endif // _QX_NO_JSON
00292    }
00293 
00294 };
00295 
00296 template <typename T>
00297 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00298 {
00299 
00300    enum { qx_need_to_specialize_template_convert_to_variant_from_variant = 0 };
00301 
00302    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00303    {
00304       Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00305 #ifndef _QX_NO_JSON
00306       return QVariant(t.toJson(format));
00307 #else // _QX_NO_JSON
00308       static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant, "qx_need_to_specialize_template_convert_to_variant_from_variant"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToVariant< MyType >'
00309       return QVariant();
00310 #endif // _QX_NO_JSON
00311    }
00312 
00313 };
00314 
00315 template <typename T>
00316 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00317 {
00318 
00319    enum { qx_need_to_specialize_template_convert_to_variant_from_variant = 0 };
00320 
00321    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00322    {
00323       Q_UNUSED(v); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
00324 #ifndef _QX_NO_JSON
00325       return t.fromJson(v.toString(), format);
00326 #else // _QX_NO_JSON
00327       static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant, "qx_need_to_specialize_template_convert_to_variant_from_variant"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromVariant< MyType >'
00328       return qx_bool(true);
00329 #endif // _QX_NO_JSON
00330    }
00331 
00332 };
00333 
00334 #ifndef _QX_NO_JSON
00335 
00336 template <typename T>
00337 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00338 {
00339    static inline QJsonValue toJson(const T & t, const QString & format)
00340    { const qx::IxPersistable * p = static_cast<const qx::IxPersistable *>(& t); return qx::cvt::to_json((* p), format); }
00341 };
00342 
00343 template <typename T>
00344 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
00345 {
00346    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00347    { qx::IxPersistable * p = static_cast<qx::IxPersistable *>(& t); return qx::cvt::from_json(j, (* p), format); }
00348 };
00349 
00350 #endif // _QX_NO_JSON
00351 
00352 template <typename T>
00353 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00354 {
00355    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00356    { return (t ? qx::cvt::to_string((* t), format, index, ctx) : ""); }
00357 };
00358 
00359 template <typename T>
00360 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00361 {
00362    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00363    { if (! t) { qx::trait::construct_ptr<T>::get(t); }; return (t ? qx::cvt::from_string(s, (* t), format, index, ctx) : qx_bool(false)); }
00364 };
00365 
00366 template <typename T>
00367 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00368 {
00369    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00370    { return (t ? qx::cvt::to_variant((* t), format, index, ctx) : QVariant()); }
00371 };
00372 
00373 template <typename T>
00374 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00375 {
00376    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00377    { if (! t && ! v.isNull()) { qx::trait::construct_ptr<T>::get(t); } else if (v.isNull()) { qx::trait::construct_ptr<T>::get(t, true); }; return (t ? qx::cvt::from_variant(v, (* t), format, index, ctx) : qx_bool(false)); }
00378 };
00379 
00380 #ifndef _QX_NO_JSON
00381 
00382 template <typename T>
00383 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00384 {
00385    static inline QJsonValue toJson(const T & t, const QString & format)
00386    { return (t ? qx::cvt::to_json((* t), format) : QJsonValue()); }
00387 };
00388 
00389 template <typename T>
00390 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
00391 {
00392    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00393    { if (! t && ! j.isNull()) { qx::trait::construct_ptr<T>::get(t); } else if (j.isNull()) { qx::trait::construct_ptr<T>::get(t, true); }; return (t ? qx::cvt::from_json(j, (* t), format) : qx_bool(false)); }
00394 };
00395 
00396 #endif // _QX_NO_JSON
00397 
00398 template <typename T>
00399 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00400 {
00401    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00402    {
00403       if (ctx != qx::cvt::context::e_serialize_registered)
00404       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->toVariant((& t), format, index, ctx).toString() : QString()); }
00405       return qx::serialization::qt::to_string<T>(t);
00406    }
00407 };
00408 
00409 template <typename T>
00410 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00411 {
00412    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00413    {
00414       if (ctx != qx::cvt::context::e_serialize_registered)
00415       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); QVariant tmp(s); return (pId ? pId->fromVariant((& t), tmp, format, index, ctx) : qx_bool(false)); }
00416       return qx::serialization::qt::from_string<T>(t, s);
00417    }
00418 };
00419 
00420 template <typename T>
00421 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00422 {
00423    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00424    {
00425       if (ctx != qx::cvt::context::e_serialize_registered)
00426       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->toVariant((& t), format, index, ctx) : QVariant()); }
00427       return qx::serialization::qt::to_byte_array<T>(t);
00428    }
00429 };
00430 
00431 template <typename T>
00432 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00433 {
00434    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00435    {
00436       if (ctx != qx::cvt::context::e_serialize_registered)
00437       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->fromVariant((& t), v, format, index, ctx) : qx_bool(false)); }
00438       return qx::serialization::qt::from_byte_array<T>(t, v.toByteArray());
00439    }
00440 };
00441 
00442 #ifndef _QX_NO_JSON
00443 
00444 template <typename T>
00445 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00446 {
00447    static inline QJsonValue toJson(const T & t, const QString & format)
00448    { return qx::cvt::detail::QxSerializeJsonRegistered<T>::save(t, format); }
00449 };
00450 
00451 template <typename T>
00452 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
00453 {
00454    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00455    { return qx::cvt::detail::QxSerializeJsonRegistered<T>::load(j, t, format); }
00456 };
00457 
00458 #endif // _QX_NO_JSON
00459 
00460 template <typename T>
00461 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00462 {
00463    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00464    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
00465 };
00466 
00467 template <typename T>
00468 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00469 {
00470    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00471    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); }
00472 };
00473 
00474 template <typename T>
00475 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00476 {
00477    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00478    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
00479 };
00480 
00481 template <typename T>
00482 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00483 {
00484    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00485    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, v.toString()); }
00486 };
00487 
00488 #ifndef _QX_NO_JSON
00489 
00490 template <typename T>
00491 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00492 {
00493    static inline QJsonValue toJson(const T & t, const QString & format)
00494    { return QJsonValue::fromVariant(qx::cvt::detail::QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>::toVariant(t, format, -1, qx::cvt::context::e_no_context)); }
00495 };
00496 
00497 template <typename T>
00498 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
00499 {
00500    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00501    { QVariant v = j.toVariant(); return qx::cvt::detail::QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>::fromVariant(v, t, format, -1, qx::cvt::context::e_no_context); }
00502 };
00503 
00504 #endif // _QX_NO_JSON
00505 
00506 template <typename T>
00507 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00508 {
00509    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00510    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QString::number(static_cast<long>(t)); }
00511 };
00512 
00513 template <typename T>
00514 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00515 {
00516    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00517    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); bool bOk = false; t = static_cast<T>(static_cast<long>(s.toLongLong(& bOk))); return bOk; }
00518 };
00519 
00520 template <typename T>
00521 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00522 {
00523    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00524    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QVariant(static_cast<qlonglong>(t)); }
00525 };
00526 
00527 template <typename T>
00528 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00529 {
00530    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00531    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); bool bOk = false; t = static_cast<T>(static_cast<long>(v.toLongLong(& bOk))); return bOk; }
00532 };
00533 
00534 #ifndef _QX_NO_JSON
00535 
00536 template <typename T>
00537 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00538 {
00539    static inline QJsonValue toJson(const T & t, const QString & format)
00540    { Q_UNUSED(format); return QJsonValue(static_cast<int>(t)); }
00541 };
00542 
00543 template <typename T>
00544 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
00545 {
00546    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00547    { Q_UNUSED(format); t = static_cast<T>(static_cast<long>(qRound(j.toDouble()))); return qx_bool(true); }
00548 };
00549 
00550 #endif // _QX_NO_JSON
00551 
00552 template <typename T>
00553 struct QxConvertHelper
00554 {
00555 
00556 private:
00557 
00558    typedef typename 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;
00559    typedef typename std::conditional< std::is_pointer<T>::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, type_str_cvt_helper_0 >::type type_str_cvt_helper_1;
00560    typedef typename 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;
00561    typedef typename 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;
00562    typedef typename 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;
00563    typedef typename std::conditional< std::is_enum<T>::value, qx::cvt::detail::helper::QxConvertHelper_Enum, type_str_cvt_helper_4 >::type type_str_cvt_helper_5;
00564 
00565 public:
00566 
00567    typedef typename QxConvertHelper<T>::type_str_cvt_helper_5 type;
00568 
00569 };
00570 
00571 template <typename T>
00572 struct QxConvert_ToString
00573 {
00574    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00575    { return qx::cvt::detail::QxConvertHelper_ToString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toString(t, format, index, ctx); }
00576 };
00577 
00578 template <typename T>
00579 struct QxConvert_FromString
00580 {
00581    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00582    { return qx::cvt::detail::QxConvertHelper_FromString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromString(s, t, format, index, ctx); }
00583 };
00584 
00585 template <typename T>
00586 struct QxConvert_ToVariant
00587 {
00588    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00589    { return qx::cvt::detail::QxConvertHelper_ToVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toVariant(t, format, index, ctx); }
00590 };
00591 
00592 template <typename T>
00593 struct QxConvert_FromVariant
00594 {
00595    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
00596    { return qx::cvt::detail::QxConvertHelper_FromVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromVariant(v, t, format, index, ctx); }
00597 };
00598 
00599 #ifndef _QX_NO_JSON
00600 
00601 template <typename T>
00602 struct QxConvert_ToJson
00603 {
00604    static inline QJsonValue toJson(const T & t, const QString & format)
00605    { return qx::cvt::detail::QxConvertHelper_ToJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toJson(t, format); }
00606 };
00607 
00608 template <typename T>
00609 struct QxConvert_FromJson
00610 {
00611    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
00612    { return qx::cvt::detail::QxConvertHelper_FromJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromJson(j, t, format); }
00613 };
00614 
00615 #endif // _QX_NO_JSON
00616 
00617 } // namespace detail
00618 } // namespace cvt
00619 } // namespace qx
00620 
00621 #include "../../inl/QxConvert/QxConvert_WithIndex.inl"
00622 #include "../../inl/QxConvert/QxConvert_ToString.inl"
00623 #include "../../inl/QxConvert/QxConvert_FromString.inl"
00624 #include "../../inl/QxConvert/QxConvert_ToVariant.inl"
00625 #include "../../inl/QxConvert/QxConvert_FromVariant.inl"
00626 #include "../../inl/QxConvert/QxConvert_ToJson.inl"
00627 #include "../../inl/QxConvert/QxConvert_FromJson.inl"
00628 #include "../../inl/QxConvert/QxConvert_Qt.inl"
00629 
00630 #endif // _QX_CONVERT_IMPL_H_