ZFFramework
 
Loading...
Searching...
No Matches
ZFObjectGlobalInstance.h File Reference

global instance holder More...

#include "ZFTypeId.h"
#include "ZFMethodDeclare.h"

Go to the source code of this file.

Macros

#define ZFCLASS_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
 util macro to declare a singleton instance access for normal object type
 
#define ZFCLASS_SINGLETON_DECLARE_DETAIL(SetterAccessType, GetterAccessType, AccessTypeName, accessMethodName)
 see ZFCLASS_SINGLETON_DECLARE
 
#define ZFCLASS_SINGLETON_DEFINE(OwnerClass, accessMethodName)
 see ZFCLASS_SINGLETON_DECLARE
 
#define ZFCLASS_SINGLETON_DEFINE_WITH_LEVEL(OwnerClass, accessMethodName, ZFLevel_)
 see ZFCLASS_SINGLETON_DECLARE
 
#define ZFCLASS_SINGLETON_DEFINE_DETAIL(OwnerClass, AccessTypeName, ObjectTypeName, accessMethodName, ZFLevel_)
 see ZFCLASS_SINGLETON_DECLARE
 
#define ZFOBJECT_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
 util macro to declare a singleton instance access for ZFObject type
 
#define ZFOBJECT_SINGLETON_DECLARE_DETAIL(SetterAccessType, GetterAccessType, AccessTypeName, accessMethodName)
 see ZFOBJECT_SINGLETON_DECLARE
 
#define ZFOBJECT_SINGLETON_DEFINE(OwnerClass, accessMethodName)
 see ZFOBJECT_SINGLETON_DECLARE
 
#define ZFOBJECT_SINGLETON_DEFINE_WITH_LEVEL(OwnerClass, accessMethodName, ZFLevel_)
 see ZFOBJECT_SINGLETON_DECLARE
 
#define ZFOBJECT_SINGLETON_DEFINE_DETAIL(OwnerClass, AccessTypeName, ObjectTypeName, accessMethodName, ZFLevel_)
 see ZFOBJECT_SINGLETON_DECLARE
 

Functions

const ZFCorePointerZFObjectGlobalInstanceAdd (const ZFCorePointer &sp, ZFLevel level=ZFLevelAppNormal)
 add a global instance that would be auto deleted while ZFFrameworkCleanup
 
const ZFCorePointerZFObjectGlobalInstanceAdd (ZFObject *obj, ZFLevel level=ZFLevelAppNormal)
 see ZFObjectGlobalInstanceAdd
 
void ZFObjectGlobalInstanceRemove (const ZFCorePointer *sp, ZFLevel level)
 see ZFObjectGlobalInstanceAdd
 

Detailed Description

global instance holder

Macro Definition Documentation

◆ ZFCLASS_SINGLETON_DECLARE

#define ZFCLASS_SINGLETON_DECLARE ( AccessTypeName,
accessMethodName )

util macro to declare a singleton instance access for normal object type

usage:

// in *.h file
zfclass YourObject {
/ **
* comment here
* /
ZFCLASS_SINGLETON_DECLARE(YourObject, instance)
};
// in *.cpp file
ZFCLASS_SINGLETON_DEFINE(YourObject, instance)
// then you can access the instance by
YourObject::instance();
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFCLASS_SINGLETON_DEFINE(OwnerClass, accessMethodName)
see ZFCLASS_SINGLETON_DECLARE
Definition ZFObjectGlobalInstance.h:170
#define ZFCLASS_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
util macro to declare a singleton instance access for normal object type
Definition ZFObjectGlobalInstance.h:160

you may change the internal singleton instance by:

newInstance = zfnew(YourType); // must be created by zfnew
YourObject::instance(newInstance); // set
newInstance = YourObject::instance(); // must re-check new pointer value
#define zfnew(Type,...)
same as new defined for future use
Definition ZFCoreTypeDef_ClassType.h:89

◆ ZFOBJECT_SINGLETON_DECLARE

#define ZFOBJECT_SINGLETON_DECLARE ( AccessTypeName,
accessMethodName )

util macro to declare a singleton instance access for ZFObject type

usage:

// in *.h file
zfclass YourObject : zfextend ZFObject {
/ **
* comment here (optional)
* /
ZFOBJECT_SINGLETON_DECLARE(YourObject, instance)
};
// in *.cpp file
ZFOBJECT_SINGLETON_DEFINE(YourObject, instance)
// then you can access the instance by
YourObject::instance();
// or manually change the instance by
YourObject::instance(yourInstance);
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define ZFOBJECT_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
util macro to declare a singleton instance access for ZFObject type
Definition ZFObjectGlobalInstance.h:256
#define ZFOBJECT_SINGLETON_DEFINE(OwnerClass, accessMethodName)
see ZFOBJECT_SINGLETON_DECLARE
Definition ZFObjectGlobalInstance.h:266
base class of all objects
Definition ZFObjectCore.h:209
Note
this macro would generate these reflectable ZFMethod for you, with this proto type:
  • YourObject *instance(void);
  • void instance(ZF_IN YourObject *);

Function Documentation

◆ ZFObjectGlobalInstanceAdd()

const ZFCorePointer * ZFObjectGlobalInstanceAdd ( const ZFCorePointer & sp,
ZFLevel level = ZFLevelAppNormal )
extern

add a global instance that would be auto deleted while ZFFrameworkCleanup

you must ensure the smart pointer is safe to be cleanup during the assigned level, if necessary, use ZFObjectGlobalInstanceRemove to remove manually before ZFFrameworkCleanup