QxOrm  1.4.9
C++ Object Relational Mapping library
QxFunction_0.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_0_H_
00033 #define _QX_FUNCTION_0_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>
00056 class QxFunction_0 : public IxFunction
00057 {
00058 
00059 public:
00060 
00061    typedef std::function<R (Owner *)> type_fct;
00062    QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_0);
00063 
00064    virtual int getParamCount() const                                    { return 0; }
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, qx::any * ret, const QxFunction_0 * pThis)
00074       {
00075          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00076          try { pThis->m_fct(static_cast<Owner *>(pOwner)); }
00077          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00078       }
00079    };
00080 
00081    template <class T>
00082    struct QxInvokerFct<T, true>
00083    {
00084       static inline qx_bool invoke(void * pOwner, const T & params, qx::any * ret, const QxFunction_0 * pThis)
00085       {
00086          QX_FUNCTION_INVOKE_START_WITH_OWNER();
00087          try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner)); if (ret) { (* ret) = qx::any(retTmp); } }
00088          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00089       }
00090    };
00091 
00092 };
00093 
00094 template <typename R>
00095 class QxFunction_0<void, R> : public IxFunction
00096 {
00097 
00098 public:
00099 
00100    typedef std::function<R ()> type_fct;
00101    QX_FUNCTION_CLASS_FCT(QxFunction_0);
00102 
00103    virtual int getParamCount() const                                    { return 0; }
00104    virtual qx_bool isValidParams(const QString & params) const          { Q_UNUSED(params); return true; }
00105    virtual qx_bool isValidParams(const type_any_params & params) const  { Q_UNUSED(params); return true; }
00106 
00107 private:
00108 
00109    template <class T, bool bReturnValue /* = false */>
00110    struct QxInvokerFct
00111    {
00112       static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_0 * pThis)
00113       {
00114          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00115          try { pThis->m_fct(); }
00116          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00117       }
00118    };
00119 
00120    template <class T>
00121    struct QxInvokerFct<T, true>
00122    {
00123       static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_0 * pThis)
00124       {
00125          QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
00126          try { R retTmp = pThis->m_fct(); if (ret) { (* ret) = qx::any(retTmp); } }
00127          QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
00128       }
00129    };
00130 
00131 };
00132 
00133 namespace function {
00134 
00135 template <class Owner, typename R>
00136 IxFunction_ptr bind_fct_0(const typename QxFunction_0<Owner, R>::type_fct & fct)
00137 {
00138    typedef std::is_same<Owner, void> qx_verify_owner_tmp;
00139    static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
00140    IxFunction_ptr ptr = std::make_shared<QxFunction_0<void, R> >(fct);
00141    return ptr;
00142 }
00143 
00144 template <class Owner, typename R>
00145 IxFunction_ptr bind_member_fct_0(const typename QxFunction_0<Owner, R>::type_fct & fct)
00146 {
00147    typedef std::is_same<Owner, void> qx_verify_owner_tmp;
00148    static_assert(! qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
00149    IxFunction_ptr ptr = std::make_shared<QxFunction_0<Owner, R> >(fct);
00150    return ptr;
00151 }
00152 
00153 } // namespace function
00154 } // namespace qx
00155 
00156 #endif // _QX_FUNCTION_0_H_