QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxFunction_0.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_0_H_
33#define _QX_FUNCTION_0_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
48
49namespace qx {
50
55template <class Owner, typename R>
57{
58
59public:
60
61 typedef std::function<R (Owner *)> type_fct;
63
64 virtual int getParamCount() const { return 0; }
65 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; }
66 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; }
67
68private:
69
70 template <class T, bool bReturnValue /* = false */>
72 {
73 static inline qx_bool invoke(void * pOwner, const T & params, qx::any * ret, const QxFunction_0 * pThis)
74 {
76 try { pThis->m_fct(static_cast<Owner *>(pOwner)); }
78 }
79 };
80
81 template <class T>
82 struct QxInvokerFct<T, true>
83 {
84 static inline qx_bool invoke(void * pOwner, const T & params, qx::any * ret, const QxFunction_0 * pThis)
85 {
87 try { R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner)); if (ret) { (* ret) = qx::any(retTmp); } }
89 }
90 };
91
92};
93
94template <typename R>
95class QxFunction_0<void, R> : public IxFunction
96{
97
98public:
99
100 typedef std::function<R ()> type_fct;
102
103 virtual int getParamCount() const { return 0; }
104 virtual qx_bool isValidParams(const QString & params) const { Q_UNUSED(params); return true; }
105 virtual qx_bool isValidParams(const type_any_params & params) const { Q_UNUSED(params); return true; }
106
107private:
108
109 template <class T, bool bReturnValue /* = false */>
111 {
112 static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_0 * pThis)
113 {
115 try { pThis->m_fct(); }
117 }
118 };
119
120 template <class T>
121 struct QxInvokerFct<T, true>
122 {
123 static inline qx_bool invoke(const T & params, qx::any * ret, const QxFunction_0 * pThis)
124 {
126 try { R retTmp = pThis->m_fct(); if (ret) { (* ret) = qx::any(retTmp); } }
128 }
129 };
130
131};
132
133namespace function {
134
135template <class Owner, typename R>
137{
138 typedef std::is_same<Owner, void> qx_verify_owner_tmp;
139 static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
140 IxFunction_ptr ptr = std::make_shared<QxFunction_0<void, R> >(fct);
141 return ptr;
142}
143
144template <class Owner, typename R>
146{
147 typedef std::is_same<Owner, void> qx_verify_owner_tmp;
148 static_assert(! qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
149 IxFunction_ptr ptr = std::make_shared<QxFunction_0<Owner, R> >(fct);
150 return ptr;
151}
152
153} // namespace function
154} // namespace qx
155
156#endif // _QX_FUNCTION_0_H_
Common interface for all functions registered into QxOrm context (used by introspection engine)
#define QX_FUNCTION_INVOKE_START_WITHOUT_OWNER()
#define QX_FUNCTION_INVOKE_START_WITH_OWNER()
#define QX_FUNCTION_CATCH_AND_RETURN_INVOKE()
qx::function::detail::get_param_X() : provide some helper functions to retrieve parameters for all qx...
qx::IxFunction : common interface for all functions registered into QxOrm context (used by introspect...
Definition IxFunction.h:64
std::vector< qx::any > type_any_params
Definition IxFunction.h:74
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
virtual int getParamCount() const
std::function< R()> type_fct
virtual qx_bool isValidParams(const QString &params) const
virtual qx_bool isValidParams(const type_any_params &params) const
QX_FUNCTION_CLASS_FCT(QxFunction_0)
qx::QxFunction_0<Owner, R> : concrete function registered into QxOrm context defined into class Owner...
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_0)
virtual qx_bool isValidParams(const QString &params) const
std::function< R(Owner *)> type_fct
virtual int getParamCount() const
virtual qx_bool isValidParams(const type_any_params &params) const
IxFunction_ptr bind_fct_0(const typename QxFunction_0< Owner, R >::type_fct &fct)
IxFunction_ptr bind_member_fct_0(const typename QxFunction_0< Owner, R >::type_fct &fct)
Root namespace for all QxOrm library features.
std::shared_ptr< IxFunction > IxFunction_ptr
Definition IxFunction.h:131
static qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_0 *pThis)
static qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_0 *pThis)
static qx_bool invoke(const T &params, qx::any *ret, const QxFunction_0 *pThis)
static qx_bool invoke(const T &params, qx::any *ret, const QxFunction_0 *pThis)