![]() |
QxOrm 1.1.9
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** http://sourceforge.net/projects/qxorm/ 00005 ** Original file by Lionel Marty 00006 ** 00007 ** This file is part of the QxOrm library 00008 ** 00009 ** This software is provided 'as-is', without any express or implied 00010 ** warranty. In no event will the authors be held liable for any 00011 ** damages arising from the use of this software. 00012 ** 00013 ** GNU Lesser General Public License Usage 00014 ** This file must be used under the terms of the GNU Lesser 00015 ** General Public License version 2.1 as published by the Free Software 00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the 00017 ** packaging of this file. Please review the following information to 00018 ** ensure the GNU Lesser General Public License version 2.1 requirements 00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 00020 ** 00021 ** If you have questions regarding the use of this file, please contact : 00022 ** contact@qxorm.com 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef _QX_FUNCTION_0_H_ 00027 #define _QX_FUNCTION_0_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00040 #include <QxFunction/IxFunction.h> 00041 #include <QxFunction/QxParameters.h> 00042 00043 namespace qx { 00044 00049 template <class Owner, typename R> 00050 class QxFunction_0 : public IxFunction 00051 { 00052 00053 public: 00054 00055 typedef boost::function<R (Owner *)> type_fct; 00056 QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_0); 00057 00058 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; } 00059 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; } 00060 00061 private: 00062 00063 template <class T, bool bReturnValue /* = false */> 00064 struct QxInvokerFct 00065 { 00066 static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_0 * pThis) 00067 { 00068 QX_FUNCTION_INVOKE_START_WITH_OWNER(); 00069 try { pThis->m_fct(static_cast<Owner *>(pOwner)); } 00070 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00071 } 00072 }; 00073 00074 template <class T> 00075 struct QxInvokerFct<T, true> 00076 { 00077 static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_0 * pThis) 00078 { 00079 QX_FUNCTION_INVOKE_START_WITH_OWNER(); 00080 try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner)); if (ret) { (* ret) = boost::any(retTmp); } } 00081 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00082 } 00083 }; 00084 00085 }; 00086 00087 template <typename R> 00088 class QxFunction_0<void, R> : public IxFunction 00089 { 00090 00091 public: 00092 00093 typedef boost::function<R ()> type_fct; 00094 QX_FUNCTION_CLASS_FCT(QxFunction_0); 00095 00096 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; } 00097 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; } 00098 00099 private: 00100 00101 template <class T, bool bReturnValue /* = false */> 00102 struct QxInvokerFct 00103 { 00104 static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_0 * pThis) 00105 { 00106 QX_FUNCTION_INVOKE_START_WITHOUT_OWNER(); 00107 try { pThis->m_fct(); } 00108 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00109 } 00110 }; 00111 00112 template <class T> 00113 struct QxInvokerFct<T, true> 00114 { 00115 static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_0 * pThis) 00116 { 00117 QX_FUNCTION_INVOKE_START_WITHOUT_OWNER(); 00118 try { R retTmp = pThis->m_fct(); if (ret) { (* ret) = boost::any(retTmp); } } 00119 QX_FUNCTION_CATCH_AND_RETURN_INVOKE(); 00120 } 00121 }; 00122 00123 }; 00124 00125 namespace function { 00126 00127 template <class Owner, typename R> 00128 IxFunction_ptr bind_fct_0(const typename QxFunction_0<Owner, R>::type_fct & fct) 00129 { 00130 typedef boost::is_same<Owner, void> qx_verify_owner_tmp; 00131 BOOST_STATIC_ASSERT(qx_verify_owner_tmp::value); 00132 IxFunction_ptr ptr; ptr.reset(new QxFunction_0<void, R>(fct)); 00133 return ptr; 00134 } 00135 00136 template <class Owner, typename R> 00137 IxFunction_ptr bind_member_fct_0(const typename QxFunction_0<Owner, R>::type_fct & fct) 00138 { 00139 typedef boost::is_same<Owner, void> qx_verify_owner_tmp; 00140 BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value); 00141 IxFunction_ptr ptr; ptr.reset(new QxFunction_0<Owner, R>(fct)); 00142 return ptr; 00143 } 00144 00145 } // namespace function 00146 } // namespace qx 00147 00148 #endif // _QX_FUNCTION_0_H_