QxOrm  1.5.0
C++ Object Relational Mapping library
QxFunction_4.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://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_4_H_
00033 #define _QX_FUNCTION_4_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, typename P3, typename P4>
00056 class QxFunction_4 : public IxFunction
00057 {
00058 
00059 public:
00060 
00061    typedef std::function<R (Owner *, P1, P2, P3, P4)> 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    typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
00065    typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
00066    QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_4);
00067 
00068    virtual int getParamCount() const                                    { return 4; }
00069    virtual qx_bool isValidParams(const QString & params) const          { Q_UNUSED(params); return true; }
00070    virtual qx_bool isValidParams(const type_any_params & params) const  { Q_UNUSED(params); return true; }
00071 
00072 private:
00073 
00074    template <class T, bool bReturnValue /* = false */>
00075    struct QxInvokerFct
00076    {
00077       static inline qx_bool invoke(void * pOwner, const T & params, qx::any * ret, const QxFunction_4 * pThis)
00078       {
00079          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00080          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00081          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00082          QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
00083          QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
00084          try { pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4); }
00085          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00086       }
00087    };
00088 
00089    template <class T>
00090    struct QxInvokerFct<T, true>
00091    {
00092       static inline qx_bool invoke(void * pOwner, const T & params, qx::any * ret, const QxFunction_4 * pThis)
00093       {
00094          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00095          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00096          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00097          QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
00098          QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
00099          try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4); if (ret) { (* ret) = qx::any(retTmp); } }
00100          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00101       }
00102    };
00103 
00104 };
00105 
00106 template <typename R, typename P1, typename P2, typename P3, typename P4>
00107 class QxFunction_4<void, R, P1, P2, P3, P4> : public IxFunction
00108 {
00109 
00110 public:
00111 
00112    typedef std::function<R (P1, P2, P3, P4)> type_fct;
00113    typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
00114    typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
00115    typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
00116    typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
00117    QX_FUNCTION_CLASS_FCT(QxFunction_4);
00118 
00119    virtual int getParamCount() const                                    { return 4; }
00120    virtual qx_bool isValidParams(const QString & params) const          { Q_UNUSED(params); return true; }
00121    virtual qx_bool isValidParams(const type_any_params & params) const  { Q_UNUSED(params); return true; }
00122 
00123 private:
00124 
00125    template <class T, bool bReturnValue /* = false */>
00126    struct QxInvokerFct
00127    {
00128       static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_4 * pThis)
00129       {
00130          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00131          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00132          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00133          QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
00134          QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
00135          try { pThis->m_fct(p1, p2, p3, p4); }
00136          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00137       }
00138    };
00139 
00140    template <class T>
00141    struct QxInvokerFct<T, true>
00142    {
00143       static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_4 * pThis)
00144       {
00145          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00146          QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
00147          QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
00148          QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
00149          QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
00150          try { R retTmp = pThis->m_fct(p1, p2, p3, p4); if (ret) { (* ret) = qx::any(retTmp); } }
00151          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00152       }
00153    };
00154 
00155 };
00156 
00157 namespace function {
00158 
00159 template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4>
00160 IxFunction_ptr bind_fct_4(const typename QxFunction_4<Owner, R, P1, P2, P3, P4>::type_fct & fct)
00161 {
00162    typedef std::is_same<Owner, void> qx_verify_owner_tmp;
00163    static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
00164    IxFunction_ptr ptr = std::make_shared<QxFunction_4<void, R, P1, P2, P3, P4> >(fct);
00165    return ptr;
00166 }
00167 
00168 template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4>
00169 IxFunction_ptr bind_member_fct_4(const typename QxFunction_4<Owner, R, P1, P2, P3, P4>::type_fct & fct)
00170 {
00171    typedef std::is_same<Owner, void> qx_verify_owner_tmp;
00172    static_assert(! qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
00173    IxFunction_ptr ptr = std::make_shared<QxFunction_4<Owner, R, P1, P2, P3, P4> >(fct);
00174    return ptr;
00175 }
00176 
00177 } // namespace function
00178 } // namespace qx
00179 
00180 #endif // _QX_FUNCTION_4_H_