6#ifndef _ZFI_ZFCallback_h_
7#define _ZFI_ZFCallback_h_
27#define ZFTOKEN_ZFCallbackTypeDummy "Dummy"
29#define ZFTOKEN_ZFCallbackTypeMethod "Method"
31#define ZFTOKEN_ZFCallbackTypeMemberMethod "MemeberMethod"
33#define ZFTOKEN_ZFCallbackTypeRawFunction "RawFunction"
35#define ZFTOKEN_ZFCallbackTypeLambda "Lambda"
39extern ZFLIB_ZFCore void _ZFP_ZFCallback_executeNullCallback(
void);
43#define _ZFP_ZFCALLBACK_INVOKER(N) \
45 template<typename T_ReturnType ZFM_REPEAT(N, ZFM_REPEAT_TEMPLATE, ZFM_COMMA, ZFM_COMMA)> \
46 T_ReturnType executeExact(ZFM_REPEAT(N, ZFM_REPEAT_PARAM, ZFM_EMPTY, ZFM_COMMA)) const { \
47 switch(this->callbackType()) { \
48 case ZFCallbackTypeMethod: \
49 case ZFCallbackTypeMemberMethod: \
50 return this->callbackMethod()->executeExact<T_ReturnType ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_COMMA, ZFM_COMMA)>( \
51 this->callbackOwnerObject() \
52 ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_COMMA, ZFM_COMMA) \
54 case ZFCallbackTypeRawFunction: \
55 return ((T_ReturnType (*)(ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_EMPTY, ZFM_COMMA)))(this->callbackRawFunction())) \
56 (ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_EMPTY, ZFM_COMMA)); \
57 case ZFCallbackTypeLambda: { \
58 ZFCallback holder_(*this); \
59 return ((T_ReturnType (*)(void * ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_COMMA, ZFM_COMMA)))(this->callbackLambdaInvoker()))( \
60 this->callbackLambdaImpl() \
61 ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_COMMA, ZFM_COMMA) \
64 case ZFCallbackTypeDummy: \
66 _ZFP_ZFCallback_executeNullCallback(); \
67 return ((T_ReturnType (*)(void))(zfnull)) (); \
71typedef void (*_ZFP_ZFCallbackLambdaDeleteCallback)(
void *);
109 operator bool (
void)
const {
return this->
valid();}
111 static ZFCallback _ZFP_ZFCallbackCreateMemberMethod(
116 static ZFCallback _ZFP_ZFCallbackCreateLambda(
118 ,
ZF_IN _ZFP_ZFCallbackLambdaDeleteCallback callbackLambdaImplDestroy
123 _ZFP_ZFCALLBACK_INVOKER(0)
124 _ZFP_ZFCALLBACK_INVOKER(1)
125 _ZFP_ZFCALLBACK_INVOKER(2)
126 _ZFP_ZFCALLBACK_INVOKER(3)
127 _ZFP_ZFCALLBACK_INVOKER(4)
128 _ZFP_ZFCALLBACK_INVOKER(5)
129 _ZFP_ZFCALLBACK_INVOKER(6)
130 _ZFP_ZFCALLBACK_INVOKER(7)
131 _ZFP_ZFCALLBACK_INVOKER(8)
294 if(src.callbackSerializeDisable()) {
351 _ZFP_ZFCallbackPrivate *d;
366 ZFCallback::_ZFP_ZFCallbackCreateMethod(zfmethod)
375#define ZFCallbackForMemberMethod(obj, zfmethod) \
376 ZFCallback::_ZFP_ZFCallbackCreateMemberMethod(obj, zfmethod)
383#define ZFCallbackForFunc(callbackRawFunction) \
384 ZFCallback::_ZFP_ZFCallbackCreateRawFunction( \
385 (ZFFuncAddrType)(void (*)(const ZFArgs &))(callbackRawFunction) \
390#define _ZFP_ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
391 zfclassLikePOD ZFLIB_ CallbackTypeName : zfextend ParentType { \
392 _ZFP_ZFCALLBACK_DECLARE_CONSTRUCTORS(CallbackTypeName, ParentType) \
394#define _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
396 ZFOUTPUT_TYPE(CallbackTypeName, {v.objectInfoT(s);})
397#define _ZFP_ZFCALLBACK_DECLARE_CONSTRUCTORS(CallbackTypeName, ParentType) \
400 CallbackTypeName(void) \
404 CallbackTypeName(ZF_IN const zfnullT &dummy) \
405 : ParentType(dummy) \
408 CallbackTypeName(ZF_IN const ZFCallback &ref) \
412 CallbackTypeName(ZF_IN const CallbackTypeName &ref) \
413 : ParentType((const ZFCallback &)ref) \
416 CallbackTypeName &operator = (ZF_IN const zfnullT &dummy) { \
417 ParentType::operator = (dummy); \
420 CallbackTypeName &operator = (ZF_IN const ZFCallback &ref) { \
421 ParentType::operator = (ref); \
424 CallbackTypeName &operator = (ZF_IN const CallbackTypeName &ref) { \
425 ParentType::operator = ((const ZFCallback &)ref); \
432#define ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
433 _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
434 ZFTYPEID_ALIAS_DECLARE(ZFLIB_, ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName) \
435 ZFTYPEID_ALIAS_REG(ZFLIB_, ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName)
436#define _ZFP_ZFCALLBACK_DECLARE_END_NO_ALIAS(ZFLIB_, CallbackTypeName, ParentType) \
437 _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType)
458#define ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
459 _ZFP_ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType)
463#define ZFCALLBACK_DECLARE(ZFLIB_, CallbackTypeName, ParentType) \
464 ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
465 ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType)
470#define ZFCALLBACK_DEFINE(CallbackTypeName, ParentType) \
471 ZFTYPEID_ALIAS_DEFINE(ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName)
#define ZFCallbackForMethod(zfmethod)
create a callback from ZFMethod
Definition ZFCallback.h:365
ZFCallbackType
callback type of ZFCallback
Definition ZFCallback.h:19
@ ZFCallbackTypeLambda
lambda function that can capture other vars
Definition ZFCallback.h:24
@ ZFCallbackTypeDummy
dummy that must not be executed
Definition ZFCallback.h:20
@ ZFCallbackTypeMemberMethod
class memeber method that need a object instance to execute, described by ZFMethod
Definition ZFCallback.h:22
@ ZFCallbackTypeRawFunction
static function without ZFMethod
Definition ZFCallback.h:23
@ ZFCallbackTypeMethod
class static member method described by ZFMethod
Definition ZFCallback.h:21
#define ZFCOMPARER_DEFAULT_DECLARE(T_Comparable0, T_Comparable1, compareAction)
declare a template specialization for ZFComparerDefault
Definition ZFComparer.h:264
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
zfbool zfstringIsEqual(const zfchar *s1, const zfchar *s2)
util to compare two c strings, while null is regarded as equal to empty string
Definition ZFCoreStringUtil.h:148
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#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
#define zfnullT
type for zfnull, can be used for function overload
Definition ZFCoreTypeDef_CoreType.h:85
_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
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
void(* ZFFuncAddrType)(void)
dummy function address type
Definition ZFCoreTypeDef_OtherType.h:277
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
@ ZFCompareUncomparable
Definition ZFCoreTypeDef_OtherType.h:29
@ ZFCompareEqual
Definition ZFCoreTypeDef_OtherType.h:31
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
reflectable method definination for ZFFramework
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define ZFSerializeDisable
special string to explicit disable serialization for impl
Definition ZFObjectClassTypeFwd.h:194
serializable data for ZFSerializable
callback used by ZFFramework
Definition ZFCallback.h:96
void callbackTagRemove(const zfstring &key)
remove tag, same as set tag to null
Definition ZFCallback.h:218
ZFFuncAddrType callbackLambdaInvoker(void) const
impl for lambda type
zfany callbackTag(const zfstring &key) const
see callbackTag
void callbackId(const zfstring &callbackId)
an unique id for the callback, used for cache logic
void * callbackLambdaImpl(void) const
impl for lambda type
void callbackTagRemoveAll(void)
see callbackTag
zfstring objectInfo(void) const
return object info
Definition ZFCallback.h:143
void callbackSerializeData(const ZFSerializableData &customData)
see ZFTypeId_ZFCallback
void objectInfoT(zfstring &ret) const
see objectInfo
ZFCallbackType callbackType(void) const
get the type of callback
ZFPathInfo pathInfo(void) const
used for impl to store path related info, see ZFPathInfo
zfbool callbackSerializeDisable(void) const
see ZFTypeId_ZFCallback
Definition ZFCallback.h:336
ZFCompareResult objectCompare(const ZFCallback &ref) const
compare with another callback
zfauto callbackTagRemoveAndGet(const zfstring &key)
remove tag, return removed tag or null if not exist
void pathInfo(const ZFPathInfo &pathInfo)
see pathInfo
void callbackOwnerObjectRelease(void) const
manually release the owner, see callbackOwnerObjectRetain
void callbackOwnerObjectRetain(void) const
retain owner object and auto release it after callback's retain count reduced to 0
zfidentity callbackHash(void) const
hash of the callback
zfindex objectRetainCount(void) const
get current retain count
ZFCompareResult objectCompareByInstance(const ZFCallback &ref) const
compare callback by instance only (same callback contents not necessarily to be same instance)
Definition ZFCallback.h:162
ZFSerializableData callbackSerializeData(void) const
see ZFTypeId_ZFCallback
void callbackTag(const zfstring &key, ZFObject *tag)
retain and store a autoreleased object attached to this callback, or set null to remove
void callbackClear(void)
explicitly clear reference of this callback
void callbackSerializeDisable(zfbool disable)
see ZFTypeId_ZFCallback
Definition ZFCallback.h:330
const zfstring & callbackId(void) const
see callbackId
void callbackInfoCopy(const ZFCallback &src)
util method to copy callback info from another callback
Definition ZFCallback.h:292
void callbackSerializeType(const zfstring &customType)
see ZFTypeId_ZFCallback
const zfstring & callbackSerializeType(void) const
see ZFTypeId_ZFCallback
const ZFMethod * callbackMethod(void) const
get the method or null if not declared by ZFMethod
zfbool valid(void) const
return true if callback is valid
Definition ZFCallback.h:238
ZFFuncAddrType callbackRawFunction(void) const
get static function, valid only if type is ZFCallbackTypeRawFunction
zfany callbackOwnerObject(void) const
get the owner object, valid only if type is class member method
void callbackTagGetAllKeyValue(ZFCoreArray< zfstring > &allKey, ZFCoreArray< zfauto > &allValue) const
see callbackTag
light weight array
Definition ZFCoreArray.h:331
reflectable method for ZFObject
Definition ZFMethod.h:252
base class of all objects
Definition ZFObjectCore.h:209
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:35
ZFSerializable's data container, see ZFSerializable.
Definition ZFSerializableData.h:74
util method to cast ZFObject types freely
Definition zfany.h:35
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34