ZFFramework
Loading...
Searching...
No Matches
ZFObserver Class Reference

holder object for observer logic, see ZFObject::observerNotify More...

#include <ZFObjectObserver.h>

Public Member Functions

void observerAdd (zfidentity eventId, const ZFListener &observer, ZFLevel observerLevel=ZFLevelAppNormal)
 see ZFObject::observerNotify
void observerAddForOnce (zfidentity eventId, const ZFListener &observer, ZFLevel observerLevel=ZFLevelAppNormal)
 see ZFObject::observerNotify
void observerRemove (zfidentity eventId, const ZFListener &callback)
 see ZFObject::observerNotify
void observerRemoveAll (zfidentity eventId)
 see ZFObject::observerNotify
void observerRemoveAll (void)
 see ZFObject::observerNotify
zfbool observerHasAdd (void) const
 see ZFObject::observerNotify
zfbool observerHasAdd (zfidentity eventId) const
 see ZFObject::observerNotify
void observerNotify (zfidentity eventId, const ZFArgs &zfargs=ZFArgs()) const
 see ZFObject::observerNotify
void observerNotifyWithSender (ZFObject *customSender, zfidentity eventId, const ZFArgs &zfargs=ZFArgs()) const
 see ZFObject::observerNotify
void observerNotifyReversely (zfidentity eventId, const ZFArgs &zfargs=ZFArgs()) const
 see ZFObject::observerNotify
void observerNotifyReverselyWithSender (ZFObject *customSender, zfidentity eventId, const ZFArgs &zfargs=ZFArgs()) const
 see ZFObject::observerNotify
void on (const zfstring &eventName, const ZFListener &observer, ZFLevel observerLevel=ZFLevelAppNormal)
 util to observerAdd
void on (zfidentity eventId, const ZFListener &observer, ZFLevel observerLevel=ZFLevelAppNormal)
 util to observerAdd
void observerHasAddStateAttach (zfidentity eventId, zfuint *flag, zfuint flagBit)
 attach a state that indicate whether the observer has add, for performance usage
void observerHasAddStateDetach (zfidentity eventId, zfuint *flag, zfuint flagBit)
 see observerHasAddStateAttach
void objectInfoT (zfstring &ret) const
 see objectInfo
zfstring objectInfo (void) const
 return a short string describe the object
zfany observerOwner (void) const
 owner object of this observer holder, or null if none

Static Public Member Functions

static void forwardOnAdd (ZFObject *owner, zfidentity eventId)
 explicitly forward ZFObject::observerOnAdd to specified owner
static void forwardOnRemove (ZFObject *owner, zfidentity eventId)
 see forwardOnAdd
static void forwardOnEvent (ZFObject *owner, const ZFArgs &zfargs)
 see forwardOnAdd

Detailed Description

holder object for observer logic, see ZFObject::observerNotify

Member Function Documentation

◆ observerHasAddStateAttach()

void ZFObserver::observerHasAddStateAttach ( zfidentity eventId,
zfuint * flag,
zfuint flagBit )

attach a state that indicate whether the observer has add, for performance usage

notifying an observer requires much CPU to check and execute, even if no observer has ever added
to optimize this, you may attach a flag to indicate whether any observer has ever added
usage:

enum {
Flag_MyEvent0,
Flag_MyEvent1,
};
zfuint myFlag = 0;
observer.observerHasAddStateAttach(E_XXX, &myFlag, Flag_MyEvent0);
observer.observerHasAddStateAttach(E_XXX, &myFlag, Flag_MyEvent1);
if(ZFBitTest(myFlag, Flag_MyEvent0)) {
observer.observerNotify(...);
}
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
#define ZFBitTest(var, bit)
macro to detect whether bit is set, zftrue if any one of test bit has set
Definition ZFCoreUtilMacro.h:16

◆ forwardOnAdd()

void ZFObserver::forwardOnAdd ( ZFObject * owner,
zfidentity eventId )
static

explicitly forward ZFObject::observerOnAdd to specified owner

ZFObject::observerOnAdd won't be called for ZFCLASS_EXTEND, you may use this method to explicitly forward event dispatch


The documentation for this class was generated from the following file: