![]() |
QxOrm
1.2.8
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_FUNCTION_1_H_ 00033 #define _QX_FUNCTION_1_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QxFunction/IxFunction.h> 00047 #include <QxFunction/QxParameters.h> 00048 00049 namespace qx { 00050 00055 template <class Owner, typename R, typename P1> 00056 class QxFunction_1 : public IxFunction 00057 { 00058 00059 public: 00060 00061 typedef boost::function<R (Owner *, P1)> type_fct; 00062 typedef typename qx::trait::remove_attr<P1, false>::type type_P1; 00063 QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_1); 00064 00065 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; } 00066 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; } 00067 00068 private: 00069 00070 template <class T, bool bReturnValue /* = false */> 00071 struct QxInvokerFct 00072 { 00073 static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_1 * pThis) 00074 { 00075 QX_FUNCTION_INVOKE_START_WITH_OWNER(); 00076 QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1); 00077 try { pThis->m_fct(static_cast<Owner *>(pOwner), p1); } 00078 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00079 } 00080 }; 00081 00082 template <class T> 00083 struct QxInvokerFct<T, true> 00084 { 00085 static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_1 * pThis) 00086 { 00087 QX_FUNCTION_INVOKE_START_WITH_OWNER(); 00088 QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1); 00089 try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1); if (ret) { (* ret) = boost::any(retTmp); } } 00090 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00091 } 00092 }; 00093 00094 }; 00095 00096 template <typename R, typename P1> 00097 class QxFunction_1<void, R, P1> : public IxFunction 00098 { 00099 00100 public: 00101 00102 typedef boost::function<R (P1)> type_fct; 00103 typedef typename qx::trait::remove_attr<P1, false>::type type_P1; 00104 QX_FUNCTION_CLASS_FCT(QxFunction_1); 00105 00106 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; } 00107 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; } 00108 00109 private: 00110 00111 template <class T, bool bReturnValue /* = false */> 00112 struct QxInvokerFct 00113 { 00114 static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_1 * pThis) 00115 { 00116 QX_FUNCTION_INVOKE_START_WITHOUT_OWNER(); 00117 QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1); 00118 try { pThis->m_fct(p1); } 00119 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00120 } 00121 }; 00122 00123 template <class T> 00124 struct QxInvokerFct<T, true> 00125 { 00126 static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_1 * pThis) 00127 { 00128 QX_FUNCTION_INVOKE_START_WITHOUT_OWNER(); 00129 QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1); 00130 try { R retTmp = pThis->m_fct(p1); if (ret) { (* ret) = boost::any(retTmp); } } 00131 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00132 } 00133 }; 00134 00135 }; 00136 00137 namespace function { 00138 00139 template <class Owner, typename R, typename P1> 00140 IxFunction_ptr bind_fct_1(const typename QxFunction_1<Owner, R, P1>::type_fct & fct) 00141 { 00142 typedef boost::is_same<Owner, void> qx_verify_owner_tmp; 00143 BOOST_STATIC_ASSERT(qx_verify_owner_tmp::value); 00144 IxFunction_ptr ptr; ptr.reset(new QxFunction_1<void, R, P1>(fct)); 00145 return ptr; 00146 } 00147 00148 template <class Owner, typename R, typename P1> 00149 IxFunction_ptr bind_member_fct_1(const typename QxFunction_1<Owner, R, P1>::type_fct & fct) 00150 { 00151 typedef boost::is_same<Owner, void> qx_verify_owner_tmp; 00152 BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value); 00153 IxFunction_ptr ptr; ptr.reset(new QxFunction_1<Owner, R, P1>(fct)); 00154 return ptr; 00155 } 00156 00157 } // namespace function 00158 } // namespace qx 00159 00160 #endif // _QX_FUNCTION_1_H_