![]() |
QxOrm
1.4.4
C++ Object Relational Mapping library
|
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_ENABLE_BOOST 00033 #ifndef _QX_BOOST_OPTIONAL_ONLY_H_ 00034 #define _QX_BOOST_OPTIONAL_ONLY_H_ 00035 00036 #ifdef _MSC_VER 00037 #pragma once 00038 #endif 00039 00047 #include <boost/optional.hpp> 00048 #include <boost/none.hpp> 00049 00050 #include <QxOrm.h> 00051 00052 #define _QX_ENABLE_BOOST 00053 #include <QxSerialize/QDataStream/QxSerializeQDataStream_boost_optional.h> 00054 #undef _QX_ENABLE_BOOST 00055 00056 QX_REGISTER_CLASS_NAME_TEMPLATE_1(boost::optional) 00057 00058 namespace qx { 00059 namespace trait { 00060 00061 template <typename T> 00062 struct get_sql_type< boost::optional<T> > 00063 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } }; 00064 00065 } // namespace trait 00066 } // namespace qx 00067 00068 namespace qx { 00069 namespace cvt { 00070 namespace detail { 00071 00072 #ifndef _QX_NO_JSON 00073 00074 template <typename T> struct QxConvert_ToJson< boost::optional<T> > { 00075 static inline QJsonValue toJson(const boost::optional<T> & t, const QString & format) 00076 { if (t) { return qx::cvt::to_json((* t), format); }; return QJsonValue(); } }; 00077 00078 template <typename T> struct QxConvert_FromJson< boost::optional<T> > { 00079 static inline qx_bool fromJson(const QJsonValue & j, boost::optional<T> & t, const QString & format) 00080 { 00081 if (j.isNull()) { t = boost::none; return qx_bool(true); } 00082 else if (! t) { t = T(); } 00083 return qx::cvt::from_json(j, (* t), format); 00084 } }; 00085 00086 #endif // _QX_NO_JSON 00087 00088 template <typename T> struct QxConvert_ToString< boost::optional<T> > { 00089 static inline QString toString(const boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) 00090 { if (t) { return qx::cvt::to_string((* t), format, index, ctx); }; return QString(); } }; 00091 00092 template <typename T> struct QxConvert_FromString< boost::optional<T> > { 00093 static inline qx_bool fromString(const QString & s, boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) 00094 { if (! t) { t = T(); }; return qx::cvt::from_string(s, (* t), format, index, ctx); } }; 00095 00096 template <typename T> struct QxConvert_ToVariant< boost::optional<T> > { 00097 static inline QVariant toVariant(const boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) 00098 { if (t) { return qx::cvt::to_variant((* t), format, index, ctx); }; return QVariant(); } }; 00099 00100 template <typename T> struct QxConvert_FromVariant< boost::optional<T> > { 00101 static inline qx_bool fromVariant(const QVariant & v, boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx) 00102 { 00103 if (v.isNull()) { t = boost::none; return qx_bool(true); } 00104 else if (! t) { t = T(); } 00105 return qx::cvt::from_variant(v, (* t), format, index, ctx); 00106 } }; 00107 00108 } // namespace detail 00109 } // namespace cvt 00110 } // namespace qx 00111 00112 #endif // _QX_BOOST_OPTIONAL_ONLY_H_ 00113 #endif // _QX_ENABLE_BOOST