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