| QxOrm 1.4.4 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxConvert_Impl.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://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
    00047 #include <QxCollection/QxCollection.h>
    00048
    00049 #include <QxRegister/QxClass.h>
    00050
    00051 #include <QxSerialize/QxArchive.h>
    00052 #include <QxSerialize/QxSerializeQDataStream.h>
    00053 #include <QxSerialize/QDataStream/QxSerializeQDataStream_all_include.h>
    00054 #include <QxSerialize/QJson/QxSerializeQJson_qx_registered_class.h>
    00055
    00056 #include <QxValidator/QxInvalidValue.h>
    00057 #include <QxValidator/QxInvalidValueX.h>
    00058
    00059 #include <QxTraits/is_smart_ptr.h>
    00060 #include <QxTraits/is_container.h>
    00061 #include <QxTraits/is_qx_registered.h>
    00062 #include <QxTraits/is_qt_variant_compatible.h>
    00063 #include <QxTraits/get_class_name_primitive.h>
    00064 #include <QxTraits/construct_ptr.h>
    00065 #include <QxTraits/generic_container.h>
    00066
    00067 #define QX_STR_CVT_QDATE_FORMAT        "yyyyMMdd"
    00068 #define QX_STR_CVT_QTIME_FORMAT        "hhmmsszzz"
    00069 #define QX_STR_CVT_QDATETIME_FORMAT    "yyyyMMddhhmmsszzz"
    00070
    00071 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
    00072 #if _QX_SERIALIZE_POLYMORPHIC
    00073 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::polymorphic_xml
    00074 #elif _QX_SERIALIZE_XML
    00075 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::xml
    00076 #elif _QX_SERIALIZE_TEXT
    00077 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::text
    00078 #elif _QX_SERIALIZE_BINARY
    00079 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::binary
    00080 #endif // _QX_SERIALIZE_XML
    00081 #else // _QX_ENABLE_BOOST_SERIALIZATION
    00082 #define QX_CVT_DEFAULT_ARCHIVE         qx::serialization::qt
    00083 #endif // _QX_ENABLE_BOOST_SERIALIZATION
    00084
    00085 #define QX_CVT_USING_ARCHIVE_IMPL(className) \
    00086 namespace qx { namespace cvt { namespace detail { \
    00087 template <> struct QxConvert_ToString< className > { \
    00088 static inline QString toString(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
    00089 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
    00090 template <> struct QxConvert_FromString< className > { \
    00091 static inline qx_bool fromString(const QString & s, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
    00092 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
    00093 template <> struct QxConvert_ToVariant< className > { \
    00094 static inline QVariant toVariant(const className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
    00095 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); } }; \
    00096 template <> struct QxConvert_FromVariant< className > { \
    00097 static inline qx_bool fromVariant(const QVariant & v, className & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) \
    00098 { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); QString s = v.toString(); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); } }; \
    00099 } } } // namespace qx::cvt::detail
    00100
    00101 namespace qx {
    00102 namespace cvt {
    00103 namespace detail {
    00104 namespace helper {
    00105
    00106 struct QxConvertHelper_Generic { };
    00107 struct QxConvertHelper_Ptr { };
    00108 struct QxConvertHelper_Registered { };
    00109 struct QxConvertHelper_Container { };
    00110 struct QxConvertHelper_Enum { };
    00111
    00112 inline bool checkConvertQVariantToString(const QVariant & v) { return ((v.type() == QVariant::List) || (v.type() == QVariant::Map) || (v.type() == QVariant::Hash) || (v.type() == QVariant::StringList)); }
    00113
    00114 } // namespace helper
    00115
    00116 template <typename T, typename H>
    00117 struct QxConvertHelper_ToString
    00118 {
    00119    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00120    { 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(); }
    00121 };
    00122
    00123 template <typename T, typename H>
    00124 struct QxConvertHelper_FromString
    00125 {
    00126    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00127    { 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(); }
    00128 };
    00129
    00130 template <typename T, typename H>
    00131 struct QxConvertHelper_ToVariant
    00132 {
    00133    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00134    { 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(); }
    00135 };
    00136
    00137 template <typename T, typename H>
    00138 struct QxConvertHelper_FromVariant
    00139 {
    00140    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00141    { 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(); }
    00142 };
    00143
    00144 #ifndef _QX_NO_JSON
    00145
    00146 template <typename T, typename H>
    00147 struct QxConvertHelper_ToJson
    00148 {
    00149    static inline QJsonValue toJson(const T & t, const QString & format)
    00150    { qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_ToJson", "template must be specialized"); Q_UNUSED(t); Q_UNUSED(format); return QJsonValue(); }
    00151 };
    00152
    00153 template <typename T, typename H>
    00154 struct QxConvertHelper_FromJson
    00155 {
    00156    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00157    { qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_FromJson", "template must be specialized"); Q_UNUSED(j); Q_UNUSED(t); Q_UNUSED(format); return qx_bool(); }
    00158 };
    00159
    00160 #endif // _QX_NO_JSON
    00161
    00162 template <typename T>
    00163 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00164 {
    00165
    00166    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
    00167
    00168    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00169    {
    00170       Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
    00171       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 >'
    00172       return QString();
    00173    }
    00174
    00175 };
    00176
    00177 template <typename T>
    00178 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00179 {
    00180
    00181    enum { qx_need_to_specialize_template_convert_to_string_from_string = 0 };
    00182
    00183    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00184    {
    00185       Q_UNUSED(s); Q_UNUSED(t); Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx);
    00186       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 >'
    00187       return qx_bool(true);
    00188    }
    00189
    00190 };
    00191
    00192 template <typename T>
    00193 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00194 {
    00195
    00196    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00197    { return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::toVariant(t, format, index, ctx); }
    00198
    00199 private:
    00200
    00201    template <bool isQVariantCompatible /* = false */, int dummy>
    00202    struct cvtQVariant
    00203    { 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); }; };
    00204
    00205    template <int dummy>
    00206    struct cvtQVariant<true, dummy>
    00207    { 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); }; };
    00208
    00209 };
    00210
    00211 template <typename T>
    00212 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00213 {
    00214
    00215    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00216    { return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::fromVariant(v, t, format, index, ctx); }
    00217
    00218 private:
    00219
    00220    template <bool isQVariantCompatible /* = false */, int dummy>
    00221    struct cvtQVariant
    00222    { 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); }; };
    00223
    00224    template <int dummy>
    00225    struct cvtQVariant<true, dummy>
    00226    { 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); }; };
    00227
    00228 };
    00229
    00230 #ifndef _QX_NO_JSON
    00231
    00232 template <typename T>
    00233 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00234 {
    00235    static inline QJsonValue toJson(const T & t, const QString & format)
    00236    { 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)); }
    00237 };
    00238
    00239 template <typename T>
    00240 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
    00241 {
    00242    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00243    { 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); }
    00244 };
    00245
    00246 #endif // _QX_NO_JSON
    00247
    00248 template <typename T>
    00249 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00250 {
    00251    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00252    { return (t ? qx::cvt::to_string((* t), format, index, ctx) : ""); }
    00253 };
    00254
    00255 template <typename T>
    00256 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00257 {
    00258    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00259    { if (! t) { qx::trait::construct_ptr<T>::get(t); }; return (t ? qx::cvt::from_string(s, (* t), format, index, ctx) : qx_bool(false)); }
    00260 };
    00261
    00262 template <typename T>
    00263 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00264 {
    00265    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00266    { return (t ? qx::cvt::to_variant((* t), format, index, ctx) : QVariant()); }
    00267 };
    00268
    00269 template <typename T>
    00270 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00271 {
    00272    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00273    { if (! t && ! v.isNull()) { qx::trait::construct_ptr<T>::get(t); }; return (t ? qx::cvt::from_variant(v, (* t), format, index, ctx) : qx_bool(false)); }
    00274 };
    00275
    00276 #ifndef _QX_NO_JSON
    00277
    00278 template <typename T>
    00279 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00280 {
    00281    static inline QJsonValue toJson(const T & t, const QString & format)
    00282    { return (t ? qx::cvt::to_json((* t), format) : QJsonValue()); }
    00283 };
    00284
    00285 template <typename T>
    00286 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
    00287 {
    00288    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00289    { if (! t && ! j.isNull()) { qx::trait::construct_ptr<T>::get(t); }; return (t ? qx::cvt::from_json(j, (* t), format) : qx_bool(false)); }
    00290 };
    00291
    00292 #endif // _QX_NO_JSON
    00293
    00294 template <typename T>
    00295 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00296 {
    00297    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00298    {
    00299       if (ctx != qx::cvt::context::e_serialize_registered)
    00300       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->toVariant((& t), format, index, ctx).toString() : QString()); }
    00301       return qx::serialization::qt::to_string<T>(t);
    00302    }
    00303 };
    00304
    00305 template <typename T>
    00306 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00307 {
    00308    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00309    {
    00310       if (ctx != qx::cvt::context::e_serialize_registered)
    00311       { 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)); }
    00312       return qx::serialization::qt::from_string<T>(t, s);
    00313    }
    00314 };
    00315
    00316 template <typename T>
    00317 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00318 {
    00319    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00320    {
    00321       if (ctx != qx::cvt::context::e_serialize_registered)
    00322       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->toVariant((& t), format, index, ctx) : QVariant()); }
    00323       return qx::serialization::qt::to_byte_array<T>(t);
    00324    }
    00325 };
    00326
    00327 template <typename T>
    00328 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00329 {
    00330    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00331    {
    00332       if (ctx != qx::cvt::context::e_serialize_registered)
    00333       { qx::IxDataMember * pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy(); return (pId ? pId->fromVariant((& t), v, format, index, ctx) : qx_bool(false)); }
    00334       return qx::serialization::qt::from_byte_array<T>(t, v.toByteArray());
    00335    }
    00336 };
    00337
    00338 #ifndef _QX_NO_JSON
    00339
    00340 template <typename T>
    00341 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00342 {
    00343    static inline QJsonValue toJson(const T & t, const QString & format)
    00344    { return qx::cvt::detail::QxSerializeJsonRegistered<T>::save(t, format); }
    00345 };
    00346
    00347 template <typename T>
    00348 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
    00349 {
    00350    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00351    { return qx::cvt::detail::QxSerializeJsonRegistered<T>::load(j, t, format); }
    00352 };
    00353
    00354 #endif // _QX_NO_JSON
    00355
    00356 template <typename T>
    00357 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00358 {
    00359    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00360    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
    00361 };
    00362
    00363 template <typename T>
    00364 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00365 {
    00366    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00367    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); }
    00368 };
    00369
    00370 template <typename T>
    00371 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00372 {
    00373    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00374    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::to_string(t); }
    00375 };
    00376
    00377 template <typename T>
    00378 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00379 {
    00380    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00381    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QX_CVT_DEFAULT_ARCHIVE::from_string(t, v.toString()); }
    00382 };
    00383
    00384 #ifndef _QX_NO_JSON
    00385
    00386 template <typename T>
    00387 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00388 {
    00389    static inline QJsonValue toJson(const T & t, const QString & format)
    00390    { 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)); }
    00391 };
    00392
    00393 template <typename T>
    00394 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
    00395 {
    00396    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00397    { 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); }
    00398 };
    00399
    00400 #endif // _QX_NO_JSON
    00401
    00402 template <typename T>
    00403 struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00404 {
    00405    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00406    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QString::number(static_cast<long>(t)); }
    00407 };
    00408
    00409 template <typename T>
    00410 struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00411 {
    00412    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00413    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); bool bOk = false; t = static_cast<T>(static_cast<long>(s.toLongLong(& bOk))); return bOk; }
    00414 };
    00415
    00416 template <typename T>
    00417 struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00418 {
    00419    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00420    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); return QVariant(static_cast<qlonglong>(t)); }
    00421 };
    00422
    00423 template <typename T>
    00424 struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00425 {
    00426    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00427    { Q_UNUSED(format); Q_UNUSED(index); Q_UNUSED(ctx); bool bOk = false; t = static_cast<T>(static_cast<long>(v.toLongLong(& bOk))); return bOk; }
    00428 };
    00429
    00430 #ifndef _QX_NO_JSON
    00431
    00432 template <typename T>
    00433 struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00434 {
    00435    static inline QJsonValue toJson(const T & t, const QString & format)
    00436    { Q_UNUSED(format); return QJsonValue(static_cast<int>(t)); }
    00437 };
    00438
    00439 template <typename T>
    00440 struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
    00441 {
    00442    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00443    { Q_UNUSED(format); t = static_cast<T>(static_cast<long>(qRound(j.toDouble()))); return qx_bool(true); }
    00444 };
    00445
    00446 #endif // _QX_NO_JSON
    00447
    00448 template <typename T>
    00449 struct QxConvertHelper
    00450 {
    00451
    00452 private:
    00453
    00454    typedef typename std::conditional< std::is_pointer<T>::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, qx::cvt::detail::helper::QxConvertHelper_Generic >::type type_str_cvt_helper_1;
    00455    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;
    00456    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;
    00457    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;
    00458    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;
    00459
    00460 public:
    00461
    00462    typedef typename QxConvertHelper<T>::type_str_cvt_helper_5 type;
    00463
    00464 };
    00465
    00466 template <typename T>
    00467 struct QxConvert_ToString
    00468 {
    00469    static inline QString toString(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00470    { return qx::cvt::detail::QxConvertHelper_ToString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toString(t, format, index, ctx); }
    00471 };
    00472
    00473 template <typename T>
    00474 struct QxConvert_FromString
    00475 {
    00476    static inline qx_bool fromString(const QString & s, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00477    { return qx::cvt::detail::QxConvertHelper_FromString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromString(s, t, format, index, ctx); }
    00478 };
    00479
    00480 template <typename T>
    00481 struct QxConvert_ToVariant
    00482 {
    00483    static inline QVariant toVariant(const T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00484    { return qx::cvt::detail::QxConvertHelper_ToVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toVariant(t, format, index, ctx); }
    00485 };
    00486
    00487 template <typename T>
    00488 struct QxConvert_FromVariant
    00489 {
    00490    static inline qx_bool fromVariant(const QVariant & v, T & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
    00491    { return qx::cvt::detail::QxConvertHelper_FromVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromVariant(v, t, format, index, ctx); }
    00492 };
    00493
    00494 #ifndef _QX_NO_JSON
    00495
    00496 template <typename T>
    00497 struct QxConvert_ToJson
    00498 {
    00499    static inline QJsonValue toJson(const T & t, const QString & format)
    00500    { return qx::cvt::detail::QxConvertHelper_ToJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toJson(t, format); }
    00501 };
    00502
    00503 template <typename T>
    00504 struct QxConvert_FromJson
    00505 {
    00506    static inline qx_bool fromJson(const QJsonValue & j, T & t, const QString & format)
    00507    { return qx::cvt::detail::QxConvertHelper_FromJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromJson(j, t, format); }
    00508 };
    00509
    00510 #endif // _QX_NO_JSON
    00511
    00512 } // namespace detail
    00513 } // namespace cvt
    00514 } // namespace qx
    00515
    00516 #include "../../inl/QxConvert/QxConvert_WithIndex.inl"
    00517 #include "../../inl/QxConvert/QxConvert_ToString.inl"
    00518 #include "../../inl/QxConvert/QxConvert_FromString.inl"
    00519 #include "../../inl/QxConvert/QxConvert_ToVariant.inl"
    00520 #include "../../inl/QxConvert/QxConvert_FromVariant.inl"
    00521 #include "../../inl/QxConvert/QxConvert_ToJson.inl"
    00522 #include "../../inl/QxConvert/QxConvert_FromJson.inl"
    00523 #include "../../inl/QxConvert/QxConvert_Qt.inl"
    00524
    00525 #endif // _QX_CONVERT_IMPL_H_