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