6#ifndef _ZFI_ZFMethodGenericInvoker_h_
7#define _ZFI_ZFMethodGenericInvoker_h_
16#define ZFMETHOD_MAX_PARAM 8
30#define ZFMP_DEF() ((ZFObject * const &)_ZFP_ZFMP_DEF)
44template<
typename T_Dummy,
int n>
47template<
typename T_Dummy>
50 typedef zfindex TypeNotRegisteredBy_ZFTYPEID;
58#define _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(N, ParamType) \
59 typedef ParamType _T##N; \
60 typedef zftTraits<ParamType>::TrNoRef _TR##N; \
61 typedef _ZFP_MtdGICk< \
63 ZFTypeId<_TR##N>::TypeIdRegistered \
64 >::TypeNotRegisteredBy_ZFTYPEID _Ck##N;
65#define _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(N, DefaultExpandOrEmpty, ParamType) \
66 _ZFP_MtdGIParamCheck( \
68 , ZFTypeId<_TR##N>::Value<_T##N>::zfvAccessAvailable(zfargs.paramAt(N)) \
72template<
typename T_Type,
typename T_Access>
75 typedef zfauto (Cb_pDef)(void);
78 explicit _ZFP_MtdGIPA(
ZF_IN const zfauto &obj) : obj(obj) {}
82 T_Access a(
ZF_IN Cb_pDef pDef) {
93#define _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(N, DefaultExpandOrEmpty, ParamType) \
94 _ZFP_MtdGIPA<_TR##N, _T##N>(zfargs.paramAt(N)).a(DefaultExpandOrEmpty(pDef##N))
95#define _ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(N, DefaultExpandOrEmpty, ParamType, DefaultValueFix) \
96 DefaultExpandOrEmpty( \
97 static zfauto pDef##N(void) { \
98 zftValue<zftTraits<ParamType>::TrNoRef> paramDefault; \
100 ZFTypeId<zftTraits<ParamType>::TrNoRef>::ValueStore( \
102 (paramDefault.zfv DefaultValueFix())); \
105 static void pDefGI##N(ZF_IN const ZFArgs &zfargs) { \
106 zfargs.result(pDef##N()); \
111template<
typename T_ReturnType>
120 T_ReturnType retTmp = invoke(zfargs);
129 if(!zfargs.ignoreError()) {
130 zfargs.errorHint(
zfstr(
"unable to convert return value as type \"%s\""
151#define _ZFP_ZFMETHOD_GENERIC_INVOKER_DECLARE( \
153 , ParamExpandOrEmpty0, ParamType0, param0_, DefaultExpandOrEmpty0, DefaultValueFix0 \
154 , ParamExpandOrEmpty1, ParamType1, param1_, DefaultExpandOrEmpty1, DefaultValueFix1 \
155 , ParamExpandOrEmpty2, ParamType2, param2_, DefaultExpandOrEmpty2, DefaultValueFix2 \
156 , ParamExpandOrEmpty3, ParamType3, param3_, DefaultExpandOrEmpty3, DefaultValueFix3 \
157 , ParamExpandOrEmpty4, ParamType4, param4_, DefaultExpandOrEmpty4, DefaultValueFix4 \
158 , ParamExpandOrEmpty5, ParamType5, param5_, DefaultExpandOrEmpty5, DefaultValueFix5 \
159 , ParamExpandOrEmpty6, ParamType6, param6_, DefaultExpandOrEmpty6, DefaultValueFix6 \
160 , ParamExpandOrEmpty7, ParamType7, param7_, DefaultExpandOrEmpty7, DefaultValueFix7 \
163 ParamExpandOrEmpty0(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(0, ParamType0)) \
164 ParamExpandOrEmpty1(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(1, ParamType1)) \
165 ParamExpandOrEmpty2(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(2, ParamType2)) \
166 ParamExpandOrEmpty3(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(3, ParamType3)) \
167 ParamExpandOrEmpty4(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(4, ParamType4)) \
168 ParamExpandOrEmpty5(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(5, ParamType5)) \
169 ParamExpandOrEmpty6(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(6, ParamType6)) \
170 ParamExpandOrEmpty7(_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_DECLARE_EXPAND(7, ParamType7)) \
172 ParamExpandOrEmpty0(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(0, DefaultExpandOrEmpty0, ParamType0, DefaultValueFix0)) \
173 ParamExpandOrEmpty1(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(1, DefaultExpandOrEmpty1, ParamType1, DefaultValueFix1)) \
174 ParamExpandOrEmpty2(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(2, DefaultExpandOrEmpty2, ParamType2, DefaultValueFix2)) \
175 ParamExpandOrEmpty3(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(3, DefaultExpandOrEmpty3, ParamType3, DefaultValueFix3)) \
176 ParamExpandOrEmpty4(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(4, DefaultExpandOrEmpty4, ParamType4, DefaultValueFix4)) \
177 ParamExpandOrEmpty5(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(5, DefaultExpandOrEmpty5, ParamType5, DefaultValueFix5)) \
178 ParamExpandOrEmpty6(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(6, DefaultExpandOrEmpty6, ParamType6, DefaultValueFix6)) \
179 ParamExpandOrEmpty7(_ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS(7, DefaultExpandOrEmpty7, ParamType7, DefaultValueFix7)) \
181 static void GI(ZF_IN_OUT const ZFArgs &zfargs) { \
182 ParamExpandOrEmpty0( \
184 !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(0, DefaultExpandOrEmpty0, ParamType0) \
185 ParamExpandOrEmpty1(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(1, DefaultExpandOrEmpty1, ParamType1)) \
186 ParamExpandOrEmpty2(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(2, DefaultExpandOrEmpty2, ParamType2)) \
187 ParamExpandOrEmpty3(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(3, DefaultExpandOrEmpty3, ParamType3)) \
188 ParamExpandOrEmpty4(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(4, DefaultExpandOrEmpty4, ParamType4)) \
189 ParamExpandOrEmpty5(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(5, DefaultExpandOrEmpty5, ParamType5)) \
190 ParamExpandOrEmpty6(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(6, DefaultExpandOrEmpty6, ParamType6)) \
191 ParamExpandOrEmpty7(|| !_ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_PREPARE_EXPAND(7, DefaultExpandOrEmpty7, ParamType7)) \
196 _ZFP_MtdGIA<ReturnType>::A(I, zfargs); \
199 static ReturnType I(ZF_IN_OUT const ZFArgs &zfargs) { \
200 return zfargs.ownerMethod()->_ZFP_execute<ReturnType \
201 ParamExpandOrEmpty0(ZFM_COMMA() ParamType0) \
202 ParamExpandOrEmpty1(ZFM_COMMA() ParamType1) \
203 ParamExpandOrEmpty2(ZFM_COMMA() ParamType2) \
204 ParamExpandOrEmpty3(ZFM_COMMA() ParamType3) \
205 ParamExpandOrEmpty4(ZFM_COMMA() ParamType4) \
206 ParamExpandOrEmpty5(ZFM_COMMA() ParamType5) \
207 ParamExpandOrEmpty6(ZFM_COMMA() ParamType6) \
208 ParamExpandOrEmpty7(ZFM_COMMA() ParamType7) \
210 ParamExpandOrEmpty0(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(0, DefaultExpandOrEmpty0, ParamType0)) \
211 ParamExpandOrEmpty1(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(1, DefaultExpandOrEmpty1, ParamType1)) \
212 ParamExpandOrEmpty2(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(2, DefaultExpandOrEmpty2, ParamType2)) \
213 ParamExpandOrEmpty3(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(3, DefaultExpandOrEmpty3, ParamType3)) \
214 ParamExpandOrEmpty4(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(4, DefaultExpandOrEmpty4, ParamType4)) \
215 ParamExpandOrEmpty5(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(5, DefaultExpandOrEmpty5, ParamType5)) \
216 ParamExpandOrEmpty6(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(6, DefaultExpandOrEmpty6, ParamType6)) \
217 ParamExpandOrEmpty7(ZFM_COMMA() _ZFP_ZFMETHOD_GENERIC_INVOKER_PARAM_ACCESS_EXPAND(7, DefaultExpandOrEmpty7, ParamType7)) \
221#define _ZFP_ZFMETHOD_GENERIC_INVOKER_ADDR(owner) \
223#define _ZFP_ZFMETHOD_GENERIC_PARAM_DEFAULT_ACCESS_ADDR(owner, DefaultExpandOrEmpty, N) \
224 ZFListener(DefaultExpandOrEmpty(ZFCallbackForFunc(owner::pDefGI##N)))
228extern ZFLIB_ZFCore void _ZFP_ZFMethodGenericInvokeError(
233#define _ZFP_ZFMethodGenericInvoke_REPEAT1(N) \
236 typedef typename zftTraits<Type##N>::TrNoRef _Type##N; \
237 if(!ZFTypeId<_Type##N>::ValueStore(tmp, param##N)) { \
238 _ZFP_ZFMethodGenericInvokeError(N, zfargs); \
241 zfargs.param(N, tmp); \
244#define _ZFP_ZFMethodGenericInvoke_REPEAT2(N) \
245 _ZFP_MtdGII_P<Type##N, zftIsZFObject(typename zftTraits<Type##N>::TrType)>::p(param##N, zfargs.paramAt(N));
247#define _ZFP_ZFMethodGenericInvoke_DECLARE(N) \
248 template<typename T_ReturnType ZFM_REPEAT(N, ZFM_REPEAT_TEMPLATE, ZFM_COMMA, ZFM_COMMA)> \
249 T_ReturnType _ZFP_MtdGII( \
250 ZF_IN const ZFMethod *method \
251 , ZF_IN zfany const &obj \
252 ZFM_REPEAT(N, ZFM_REPEAT_PARAM, ZFM_COMMA, ZFM_COMMA) \
257 .ownerMethod(method) \
260 ZFM_REPEAT(N, _ZFP_ZFMethodGenericInvoke_REPEAT1, ZFM_EMPTY, ZFM_EMPTY) \
261 _ZFP_ZFMethodGenericInvoke(zfargs); \
262 if(!zfargs.success()) { \
263 _ZFP_ZFMethodGenericInvokeError(-1, zfargs); \
265 ZFM_REPEAT(N, _ZFP_ZFMethodGenericInvoke_REPEAT2, ZFM_EMPTY, ZFM_EMPTY) \
266 return _ZFP_MtdGII_R<T_ReturnType>::r(zfargs); \
269template<
typename T_ParamType,
int isZFObject>
271template<
typename T_ParamType>
274 static inline void p(
280template<
typename T_ParamType>
283 static inline void p(
289template<
typename T_ParamType>
292 static inline void p(
298template<
typename T_ParamType>
301 static inline void p(
310 static inline void p(
319 static inline void p(
325template<
typename T_ParamType>
337template<
typename T_ParamType>
352template<
typename T_ReturnType>
355 static T_ReturnType r(
ZF_IN const ZFArgs &zfargs) {
358 _ZFP_ZFMethodGenericInvokeError(-2, zfargs);
370_ZFP_ZFMethodGenericInvoke_DECLARE(0)
371_ZFP_ZFMethodGenericInvoke_DECLARE(1)
372_ZFP_ZFMethodGenericInvoke_DECLARE(2)
373_ZFP_ZFMethodGenericInvoke_DECLARE(3)
374_ZFP_ZFMethodGenericInvoke_DECLARE(4)
375_ZFP_ZFMethodGenericInvoke_DECLARE(5)
376_ZFP_ZFMethodGenericInvoke_DECLARE(6)
377_ZFP_ZFMethodGenericInvoke_DECLARE(7)
378_ZFP_ZFMethodGenericInvoke_DECLARE(8)
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZFCoreMutexLocker()
util method to lock current block
Definition ZFCoreMutex.h:95
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
_ZFT_t_zfint zfint
same as int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:165
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
void(* ZFMethodGenericInvoker)(const ZFArgs &zfargs)
generic invoker for advanced reflection, see ZFMethod::methodGenericInvoker
Definition ZFMethodGenericInvoker.h:24
#define ZFMP_DEF()
mark the object as default param
Definition ZFMethodGenericInvoker.h:30
zfbool ZFMethodGenericInvokerParamsCheck(const ZFArgs &zfargs)
util method for ZFMethodGenericInvoker to check whether all param type match
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
listener data used by ZFListener
Definition ZFArgs.h:20
reflectable method for ZFObject
Definition ZFMethod.h:252
base class of all objects
Definition ZFObjectCore.h:209
type data traits for ZFTYPEID_DECLARE
Definition ZFTypeIdFwd.h:117
static const zfstring & TypeId(void)
get type id, or return ZFTypeId_none if not registered
static zfbool ValueStore(zfauto &obj, T_Type const &v)
store the value to wrapper object
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
T_Type TrNoRef
remove reference
Definition ZFCoreUtilTemplate.h:110
zfstring zfstr(const zfchar *fmt=zft_zfnull)
string format util
Definition zfstr.h:59