6#ifndef _ZFI_ZFCallback_h_
7#define _ZFI_ZFCallback_h_
29#define ZFTOKEN_ZFCallbackTypeDummy "Dummy"
31#define ZFTOKEN_ZFCallbackTypeMethod "Method"
33#define ZFTOKEN_ZFCallbackTypeMemberMethod "MemeberMethod"
35#define ZFTOKEN_ZFCallbackTypeRawFunction "RawFunction"
37#define ZFTOKEN_ZFCallbackTypeLambda "Lambda"
41extern ZFLIB_ZFCore void _ZFP_ZFCallback_executeNullCallback(
void);
45#define _ZFP_ZFCALLBACK_INVOKER(N) \
47 template<typename T_ReturnType ZFM_REPEAT(N, ZFM_REPEAT_TEMPLATE, ZFM_COMMA, ZFM_COMMA)> \
48 T_ReturnType executeExact(ZFM_REPEAT(N, ZFM_REPEAT_PARAM, ZFM_EMPTY, ZFM_COMMA)) const { \
49 switch(this->callbackType()) { \
50 case ZFCallbackTypeMethod: \
51 case ZFCallbackTypeMemberMethod: \
52 return this->callbackMethod()->executeExact<T_ReturnType ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_COMMA, ZFM_COMMA)>( \
53 this->callbackOwnerObject() \
54 ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_COMMA, ZFM_COMMA) \
56 case ZFCallbackTypeRawFunction: \
57 return ((T_ReturnType (*)(ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_EMPTY, ZFM_COMMA)))(this->callbackRawFunction())) \
58 (ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_EMPTY, ZFM_COMMA)); \
59 case ZFCallbackTypeLambda: { \
60 ZFCallback holder_(*this); \
61 return ((T_ReturnType (*)(void * ZFM_REPEAT(N, ZFM_REPEAT_TYPE, ZFM_COMMA, ZFM_COMMA)))(this->callbackLambdaInvoker()))( \
62 this->callbackLambdaImpl() \
63 ZFM_REPEAT(N, ZFM_REPEAT_NAME, ZFM_COMMA, ZFM_COMMA) \
66 case ZFCallbackTypeDummy: \
68 _ZFP_ZFCallback_executeNullCallback(); \
69 return ((T_ReturnType (*)(void))(zfnull)) (); \
73typedef void (*_ZFP_ZFCallbackLambdaDeleteCallback)(
void *);
111 operator bool (
void)
const {
return this->
valid();}
112 inline void _ZFP_ZFCallback_d(
ZF_IN _ZFP_ZFCallbackPrivate *d) {
115 inline _ZFP_ZFCallbackPrivate *_ZFP_ZFCallback_d(
void)
const {
119 static ZFCallback _ZFP_ZFCallbackCreateMemberMethod(
124 static ZFCallback _ZFP_ZFCallbackCreateLambda(
126 ,
ZF_IN _ZFP_ZFCallbackLambdaDeleteCallback callbackLambdaImplDestroy
131 _ZFP_ZFCALLBACK_INVOKER(0)
132 _ZFP_ZFCALLBACK_INVOKER(1)
133 _ZFP_ZFCALLBACK_INVOKER(2)
134 _ZFP_ZFCALLBACK_INVOKER(3)
135 _ZFP_ZFCALLBACK_INVOKER(4)
136 _ZFP_ZFCALLBACK_INVOKER(5)
137 _ZFP_ZFCALLBACK_INVOKER(6)
138 _ZFP_ZFCALLBACK_INVOKER(7)
139 _ZFP_ZFCALLBACK_INVOKER(8)
315 if(src.callbackSerializeDisable()) {
372 _ZFP_ZFCallbackPrivate *d;
387 ZFCallback::_ZFP_ZFCallbackCreateMethod(zfmethod)
396#define ZFCallbackForMemberMethod(obj, zfmethod) \
397 ZFCallback::_ZFP_ZFCallbackCreateMemberMethod(obj, zfmethod)
404#define ZFCallbackForFunc(callbackRawFunction) \
405 ZFCallback::_ZFP_ZFCallbackCreateRawFunction( \
406 (ZFFuncAddrType)(void (*)(const ZFArgs &))(callbackRawFunction) \
411#define _ZFP_ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
412 zfclassLikePOD ZFLIB_ CallbackTypeName : zfextend ParentType { \
413 _ZFP_ZFCALLBACK_DECLARE_CONSTRUCTORS(CallbackTypeName, ParentType) \
415#define _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
417 ZFOUTPUT_TYPE(CallbackTypeName, {v.objectInfoT(s);})
418#define _ZFP_ZFCALLBACK_DECLARE_CONSTRUCTORS(CallbackTypeName, ParentType) \
421 CallbackTypeName(void) \
425 CallbackTypeName(ZF_IN const zfnullT &dummy) \
426 : ParentType(dummy) \
429 CallbackTypeName(ZF_IN const ZFCallback &ref) \
433 CallbackTypeName(ZF_IN const CallbackTypeName &ref) \
434 : ParentType((const ZFCallback &)ref) \
437 CallbackTypeName &operator = (ZF_IN const zfnullT &dummy) { \
438 ParentType::operator = (dummy); \
441 CallbackTypeName &operator = (ZF_IN const ZFCallback &ref) { \
442 ParentType::operator = (ref); \
445 CallbackTypeName &operator = (ZF_IN const CallbackTypeName &ref) { \
446 ParentType::operator = ((const ZFCallback &)ref); \
453#define ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
454 _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType) \
455 ZFTYPEID_ALIAS_DECLARE(ZFLIB_, ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName) \
456 ZFTYPEID_ALIAS_REG(ZFLIB_, ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName)
457#define _ZFP_ZFCALLBACK_DECLARE_END_NO_ALIAS(ZFLIB_, CallbackTypeName, ParentType) \
458 _ZFP_ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType)
479#define ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
480 _ZFP_ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType)
484#define ZFCALLBACK_DECLARE(ZFLIB_, CallbackTypeName, ParentType) \
485 ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType) \
486 ZFCALLBACK_DECLARE_END(ZFLIB_, CallbackTypeName, ParentType)
491#define ZFCALLBACK_DEFINE(CallbackTypeName, ParentType) \
492 ZFTYPEID_ALIAS_DEFINE(ZFCallback, ZFCallback, CallbackTypeName, CallbackTypeName)
#define ZFCallbackForMethod(zfmethod)
create a callback from ZFMethod
Definition ZFCallback.h:386
ZFCallbackType
callback type of ZFCallback
Definition ZFCallback.h:21
@ ZFCallbackTypeLambda
lambda function that can capture other vars
Definition ZFCallback.h:26
@ ZFCallbackTypeDummy
dummy that must not be executed
Definition ZFCallback.h:22
@ ZFCallbackTypeMemberMethod
class memeber method that need a object instance to execute, described by ZFMethod
Definition ZFCallback.h:24
@ ZFCallbackTypeRawFunction
static function without ZFMethod
Definition ZFCallback.h:25
@ ZFCallbackTypeMethod
class static member method described by ZFMethod
Definition ZFCallback.h:23
#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_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#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
ZFLevel
level for logic which depends on order
Definition ZFLevel.h:17
@ ZFLevelAppNormal
app
Definition ZFLevel.h:26
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:98
void callbackTagRemove(const zfstring &key)
remove tag, same as set tag to null
Definition ZFCallback.h:239
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:151
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:357
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:170
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 all reference of this callback
void callbackSerializeDisable(zfbool disable)
see ZFTypeId_ZFCallback
Definition ZFCallback.h:351
const zfstring & callbackId(void) const
see callbackId
void callbackInfoCopy(const ZFCallback &src)
util method to copy callback info from another callback
Definition ZFCallback.h:313
void callbackClearPrepareRemove(const ZFListener &observer) const
see callbackClear
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:259
ZFFuncAddrType callbackRawFunction(void) const
get static function, valid only if type is ZFCallbackTypeRawFunction
void callbackClearPrepareAdd(const ZFListener &observer, ZFLevel observerLevel=ZFLevelAppNormal) const
see callbackClear
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
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
reflectable method for ZFObject
Definition ZFMethod.h:252
base class of all objects
Definition ZFObjectCore.h:205
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:34
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