QxOrm  1.4.5
C++ Object Relational Mapping library
QxFunctionMacro.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_MACRO_H_
00033 #define _QX_FUNCTION_MACRO_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00039 #include <QxConvert/QxConvert.h>
00040 
00041 #define QX_FUNCTION_CLASS_FCT(className) \
00042 public: \
00043 type_fct m_fct; \
00044 className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
00045 virtual ~className() { ; }; \
00046 virtual qx_bool invoke(const QString & params = QString(), qx::any * ret = NULL) const \
00047 { return QxInvokerFct<QString, ! std::is_same<R, void>::value>::invoke(params, ret, this); } \
00048 virtual qx_bool invoke(const type_any_params & params, qx::any * ret = NULL) const \
00049 { return QxInvokerFct<type_any_params, ! std::is_same<R, void>::value>::invoke(params, ret, this); } \
00050 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), qx::any * ret = NULL) const \
00051 { Q_UNUSED(pOwner); Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
00052 virtual qx_bool invoke(void * pOwner, const type_any_params & params, qx::any * ret = NULL) const \
00053 { Q_UNUSED(pOwner); Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
00054 virtual qx_bool isValidFct() const \
00055 { return ((! m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_FCT) : qx_bool(true)); }
00056 
00057 #define QX_FUNCTION_CLASS_MEMBER_FCT(className) \
00058 public: \
00059 type_fct m_fct; \
00060 className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
00061 virtual ~className() { ; }; \
00062 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), qx::any * ret = NULL) const \
00063 { return QxInvokerFct<QString, ! std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); } \
00064 virtual qx_bool invoke(void * pOwner, const type_any_params & params, qx::any * ret = NULL) const \
00065 { return QxInvokerFct<type_any_params, ! std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); } \
00066 virtual qx_bool invoke(const QString & params = QString(), qx::any * ret = NULL) const \
00067 { Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
00068 virtual qx_bool invoke(const type_any_params & params, qx::any * ret = NULL) const \
00069 { Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
00070 virtual qx_bool isValidFct() const \
00071 { return ((! m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_MEMBER_FCT) : qx_bool(true)); }
00072 
00073 #define QX_FUNCTION_CATCH_AND_RETURN_INVOKE() \
00074 catch (const std::exception & e) { bValid = qx_bool(false, 0, e.what()); } \
00075 catch (...) { bValid = qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
00076 if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); } \
00077 return bValid;
00078 
00079 #define QX_FUNCTION_INVOKE_START_WITH_OWNER() \
00080 if (ret) { (* ret) = qx::any(); } \
00081 qx_bool bValid = pThis->isValid<T, Owner>(pOwner, params, NULL); \
00082 if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bValid; }
00083 
00084 #define QX_FUNCTION_INVOKE_START_WITHOUT_OWNER() \
00085 if (ret) { (* ret) = qx::any(); } \
00086 qx_bool bValid = pThis->isValid(params); \
00087 if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bValid; }
00088 
00089 #define QX_FUNCTION_FETCH_PARAM(TYPE, VALUE, FCT) \
00090 typename std::remove_const< TYPE >::type VALUE; \
00091 { qx_bool bTmp = qx::function::detail::FCT(params, VALUE, pThis); \
00092 if (! bTmp) { QString sMsgDebug = bTmp.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bTmp; } }
00093 
00094 #define QX_FUNCTION_GET_PARAM_TYPE_ANY(PARAMCOUNT) \
00095 Q_UNUSED(qx_fct); \
00096 if (params.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
00097 qx_bool bValid = true; \
00098 try { p = qx::any_cast<P>(params[PARAMCOUNT - 1]); } \
00099 catch (...) { bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); } \
00100 return bValid;
00101 
00102 #define QX_FUNCTION_GET_PARAM_TYPE_STRING(PARAMCOUNT) \
00103 if (! qx_fct) { return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
00104 QStringList lst = params.split(qx_fct->getSeparator()); \
00105 if (lst.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
00106 qx_bool bValid = true; \
00107 try { bValid = qx::cvt::from_string(lst.at(PARAMCOUNT - 1), p); } \
00108 catch (...) { bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); } \
00109 return bValid;
00110 
00111 #define QX_FUNCTION_GET_PARAM_TYPE_STRING_TO_QSTRING(PARAMCOUNT) \
00112 if (! qx_fct) { return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
00113 QStringList lst = params.split(qx_fct->getSeparator()); \
00114 if (lst.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
00115 p = lst.at(PARAMCOUNT - 1); \
00116 return true;
00117 
00118 #endif // _QX_FUNCTION_MACRO_H_