ZFFramework
Loading...
Searching...
No Matches
Callback

reflectable method is not powerful enough to write high level code, so we introduced ZFCallback to supply more powerful abstract callback logic:

ZFMETHOD_INLINE_1(zfstring, myMemberMethod
, ZFMP_IN(zfindex, param0)
) {
return zfstr("called myMemberMethod, param: %s", param0);
}
};
static zfstring myStaticFunc(ZF_IN zfindex param0) {
return zfstr("called myStaticFunc, param: %s", param0);
}
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_INLINE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:920
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:124
base class of all objects
Definition ZFObjectCore.h:214
const zfchar * zfstr(const zfchar *fmt=0)
string format util
Definition zfstr.h:59
// prepare an object and a method
const ZFMethod *method = ZFMethodForName("MyObject", "myMemberMethod");
// create callback from an object's member method
ZFCallback callback1 = ZFCallbackForMemberMethod(obj, method);
// create callback from normal function
ZFCallback callback2 = ZFCallbackForFunc(myStaticFunc);
// safe to assign new value to the callback,
// even if method's proto type is not the same
ZFCallback callbackTmp = callback1;
// now you can invoke the callback,
// without knowing who owns it
callback1.executeExact<zfstring, zfindex>(1);
callback2.executeExact<zfstring, zfindex>(2);
#define ZFCallbackForMemberMethod(obj, zfmethod)
create a callback from ZFMethod of an object
Definition ZFCallback.h:380
#define ZFCallbackForFunc(callbackRawFunction)
create a callback from static function
Definition ZFCallback.h:388
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
const ZFMethod * ZFMethodForName(const zfchar *classNameOrNamespace, const zfchar *methodName)
util method to find method
callback used by ZFFramework
Definition ZFCallback.h:105
T_ReturnType executeExact() const
see ZFCallback, you must assign the exact return type and param types for safe
Definition ZFCallback.h:132
reflectable method for ZFObject
Definition ZFMethod.h:237
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:163

ZFCallback can hold:

  • anything that was declared as ZFMethod, including class member method (static or not), static functions
  • normal function

with ZFCallback, you may invoke a class member method without knowing its class type, and now we are free to play with delegate/protocol/listener/observer or whatever-it-called mechanisms