QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxFunctionMacro.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_FUNCTION_MACRO_H_
33#define _QX_FUNCTION_MACRO_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
39#include <QxConvert/QxConvert.h>
40
41#define QX_FUNCTION_CLASS_FCT(className) \
42public: \
43type_fct m_fct; \
44className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
45virtual ~className() { ; }; \
46virtual qx_bool invoke(const QString & params = QString(), qx::any * ret = NULL) const \
47{ return QxInvokerFct<QString, ! std::is_same<R, void>::value>::invoke(params, ret, this); } \
48virtual qx_bool invoke(const type_any_params & params, qx::any * ret = NULL) const \
49{ return QxInvokerFct<type_any_params, ! std::is_same<R, void>::value>::invoke(params, ret, this); } \
50virtual qx_bool invoke(void * pOwner, const QString & params = QString(), qx::any * ret = NULL) const \
51{ Q_UNUSED(pOwner); Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
52virtual qx_bool invoke(void * pOwner, const type_any_params & params, qx::any * ret = NULL) const \
53{ Q_UNUSED(pOwner); Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
54virtual qx_bool isValidFct() const \
55{ return ((! m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_FCT) : qx_bool(true)); }
56
57#define QX_FUNCTION_CLASS_MEMBER_FCT(className) \
58public: \
59type_fct m_fct; \
60className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
61virtual ~className() { ; }; \
62virtual qx_bool invoke(void * pOwner, const QString & params = QString(), qx::any * ret = NULL) const \
63{ return QxInvokerFct<QString, ! std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); } \
64virtual qx_bool invoke(void * pOwner, const type_any_params & params, qx::any * ret = NULL) const \
65{ return QxInvokerFct<type_any_params, ! std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); } \
66virtual qx_bool invoke(const QString & params = QString(), qx::any * ret = NULL) const \
67{ Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
68virtual qx_bool invoke(const type_any_params & params, qx::any * ret = NULL) const \
69{ Q_UNUSED(params); Q_UNUSED(ret); qAssert(false); return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); } \
70virtual qx_bool isValidFct() const \
71{ return ((! m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_MEMBER_FCT) : qx_bool(true)); }
72
73#define QX_FUNCTION_CATCH_AND_RETURN_INVOKE() \
74catch (const std::exception & e) { bValid = qx_bool(false, 0, e.what()); } \
75catch (...) { bValid = qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
76if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); } \
77return bValid;
78
79#define QX_FUNCTION_INVOKE_START_WITH_OWNER() \
80if (ret) { (* ret) = qx::any(); } \
81qx_bool bValid = pThis->isValid<T, Owner>(pOwner, params, NULL); \
82if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bValid; }
83
84#define QX_FUNCTION_INVOKE_START_WITHOUT_OWNER() \
85if (ret) { (* ret) = qx::any(); } \
86qx_bool bValid = pThis->isValid(params); \
87if (! bValid) { QString sMsgDebug = bValid.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bValid; }
88
89#define QX_FUNCTION_FETCH_PARAM(TYPE, VALUE, FCT) \
90typename std::remove_const< TYPE >::type VALUE; \
91{ qx_bool bTmp = qx::function::detail::FCT(params, VALUE, pThis); \
92if (! bTmp) { QString sMsgDebug = bTmp.getDesc(); qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); qAssert(false); return bTmp; } }
93
94#define QX_FUNCTION_GET_PARAM_TYPE_ANY(PARAMCOUNT) \
95Q_UNUSED(qx_fct); \
96if (params.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
97qx_bool bValid = true; \
98try { p = qx::any_cast<P>(params[PARAMCOUNT - 1]); } \
99catch (...) { bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); } \
100return bValid;
101
102#define QX_FUNCTION_GET_PARAM_TYPE_STRING(PARAMCOUNT) \
103if (! qx_fct) { return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
104QStringList lst = params.split(qx_fct->getSeparator()); \
105if (lst.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
106qx_bool bValid = true; \
107try { bValid = qx::cvt::from_string(lst.at(PARAMCOUNT - 1), p); } \
108catch (...) { bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); } \
109return bValid;
110
111#define QX_FUNCTION_GET_PARAM_TYPE_STRING_TO_QSTRING(PARAMCOUNT) \
112if (! qx_fct) { return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
113QStringList lst = params.split(qx_fct->getSeparator()); \
114if (lst.size() < PARAMCOUNT) { return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); } \
115p = lst.at(PARAMCOUNT - 1); \
116return true;
117
118#endif // _QX_FUNCTION_MACRO_H_
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...