QxOrm  1.2.7
C++ Object Relational Mapping library
QxFunction_2.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_FUNCTION_2_H_
00033 #define _QX_FUNCTION_2_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, typename P2>
00056 class QxFunction_2 : public IxFunction
00057 {
00058 
00059 public:
00060 
00061    typedef boost::function<R (Owner *, P1, P2)> type_fct;
00062    typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
00063    typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
00064    QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_2);
00065 
00066    virtual qx_bool isValidParams(const QString & params) const          { Q_UNUSED(params); return true; }
00067    virtual qx_bool isValidParams(const type_any_params & params) const  { Q_UNUSED(params); return true; }
00068 
00069 private:
00070 
00071    template <class T, bool bReturnValue /* = false */>
00072    struct QxInvokerFct
00073    {
00074       static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_2 * pThis)
00075       {
00076          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00077          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00078          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00079          try { pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2); }
00080          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00081       }
00082    };
00083 
00084    template <class T>
00085    struct QxInvokerFct<T, true>
00086    {
00087       static inline qx_bool invoke(void * pOwner, const T & params, boost::any * ret, const QxFunction_2 * pThis)
00088       {
00089          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00090          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00091          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00092          try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2); if (ret) { (* ret) = boost::any(retTmp); } }
00093          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00094       }
00095    };
00096 
00097 };
00098 
00099 template <typename R, typename P1, typename P2>
00100 class QxFunction_2<void, R, P1, P2> : public IxFunction
00101 {
00102 
00103 public:
00104 
00105    typedef boost::function<R (P1, P2)> type_fct;
00106    typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
00107    typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
00108    QX_FUNCTION_CLASS_FCT(QxFunction_2);
00109 
00110    virtual qx_bool isValidParams(const QString & params) const          { Q_UNUSED(params); return true; }
00111    virtual qx_bool isValidParams(const type_any_params & params) const  { Q_UNUSED(params); return true; }
00112 
00113 private:
00114 
00115    template <class T, bool bReturnValue /* = false */>
00116    struct QxInvokerFct
00117    {
00118       static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_2 * pThis)
00119       {
00120          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00121          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00122          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00123          try { pThis->m_fct(p1, p2); }
00124          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00125       }
00126    };
00127 
00128    template <class T>
00129    struct QxInvokerFct<T, true>
00130    {
00131       static inline qx_bool invoke(const T & params, boost::any * ret, const QxFunction_2 * pThis)
00132       {
00133          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00134          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00135          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00136          try { R retTmp = pThis->m_fct(p1, p2); if (ret) { (* ret) = boost::any(retTmp); } }
00137          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00138       }
00139    };
00140 
00141 };
00142 
00143 namespace function {
00144 
00145 template <class Owner, typename R, typename P1, typename P2>
00146 IxFunction_ptr bind_fct_2(const typename QxFunction_2<Owner, R, P1, P2>::type_fct & fct)
00147 {
00148    typedef boost::is_same<Owner, void> qx_verify_owner_tmp;
00149    BOOST_STATIC_ASSERT(qx_verify_owner_tmp::value);
00150    IxFunction_ptr ptr; ptr.reset(new QxFunction_2<void, R, P1, P2>(fct));
00151    return ptr;
00152 }
00153 
00154 template <class Owner, typename R, typename P1, typename P2>
00155 IxFunction_ptr bind_member_fct_2(const typename QxFunction_2<Owner, R, P1, P2>::type_fct & fct)
00156 {
00157    typedef boost::is_same<Owner, void> qx_verify_owner_tmp;
00158    BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value);
00159    IxFunction_ptr ptr; ptr.reset(new QxFunction_2<Owner, R, P1, P2>(fct));
00160    return ptr;
00161 }
00162 
00163 } // namespace function
00164 } // namespace qx
00165 
00166 #endif // _QX_FUNCTION_2_H_