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

ZFObject's class info. More...

#include <ZFClass.h>

Public Member Functions

void instanceObserverAdd (const ZFListener &observer, ZFObject *owner=zft_zfnull, ZFLevel observerLevel=ZFLevelAppNormal, zfbool observeAllChildType=_ZFT_t_zftrue) const
 add an observer which would be called if any of this class's instance created
 
void instanceObserverAdd (const ZFClassInstanceObserverAddParam &param) const
 see instanceObserverAdd
 
void instanceObserverRemove (const ZFListener &observer) const
 see instanceObserverAdd
 
void instanceObserverRemoveByOwner (ZFObject *owner) const
 see instanceObserverAdd
 
void instanceObserverRemoveAll (void) const
 see instanceObserverAdd
 
void objectInfoT (zfstring &ret) const
 see objectInfo
 
zfstring objectInfo (void) const
 return object info
 
void objectInfoOfInheritTreeT (zfstring &ret) const
 see objectInfoOfInheritTree
 
zfstring objectInfoOfInheritTree (void) const
 return a string describe the class inherit tree, debug use only
 
zfbool classIsTypeOf (const ZFClass *cls) const
 true if class is subclass of cls, or implement cls
 
const ZFCoreArray< zfstring > & classAliasTo (void) const
 see ZFClassAlias
 
const zfstringclassNamespace (void) const
 class namespace, null or empty string for global scope class
 
const zfstringclassName (void) const
 class name, e.g. "ZFObject"
 
const zfstringclassNameFull (void) const
 class full name, e.g. "NS0.NS1.YourObject"
 
const ZFClassclassParent (void) const
 class's parent, zfnull if none
 
zfbool classIsDynamicRegister (void) const
 true if class is registered by ZFClassDynamicRegister
 
zfany classDynamicRegisterUserData (void) const
 see ZFClassDynamicRegister
 
zfbool classIsAbstract (void) const
 true if the class is abstract class
 
zfbool classIsInterface (void) const
 true if the class is an interface
 
zfbool classIsInternal (void) const
 whether the class is internal class
 
zfbool classIsInternalPrivate (void) const
 whether the class is internal private class
 
zfbool classCanAllocPublic (void) const
 whether the class can alloc directly, see ZFOBJECT_PRIVATE_ALLOC
 
zfauto newInstance (void) const
 make a new instance of ZFObject dynamically, which is described by ZFClass
 
zfauto newInstance (ZFObject *param0, ZFObject *param1=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param2=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param3=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param4=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param5=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param6=((ZFObject *const &) _ZFP_ZFMP_DEF), ZFObject *param7=((ZFObject *const &) _ZFP_ZFMP_DEF)) const
 for advanced reflection use only
 
zfauto newInstanceDetail (const ZFCoreArray< zfauto > &params, zfbool *success=zft_zfnull, zfstring *errorHint=zft_zfnull) const
 see newInstance
 
void * newInstanceGenericBegin (void) const
 see newInstance
 
zfbool newInstanceGenericCheck (void *&token, const ZFMethod *objectOnInitMethod, const ZFArgs &zfargs) const
 see newInstance
 
zfauto newInstanceGenericEnd (void *&token, zfbool objectOnInitMethodInvokeSuccess) const
 see newInstance
 
zfindex implementedInterfaceCount (void) const
 get implemented interface count, see dynamicInterfaceAt
 
const ZFClassimplementedInterfaceAt (zfindex index) const
 get implemented interface, see dynamicInterfaceAt
 
zfindex dynamicInterfaceCount (void) const
 get dynamic interface registered by ZFImplementDynamicRegister, see implementedInterfaceAt
 
const ZFClassdynamicInterfaceAt (zfindex index) const
 get dynamic interface registered by ZFImplementDynamicRegister, see implementedInterfaceAt
 
zfbool dynamicImplementOf (const ZFClass *parent) const
 true if this class dynamic implement specified parent by ZFImplementDynamicRegister
 
ZFCoreArray< const ZFClass * > childGetAll (void) const
 get all child excluding self, for debug use only
 
ZFCoreArray< const ZFClass * > parentGetAll (void) const
 get all parent (parent/interface/dynamicInterface) excluding self, for debug use only
 
zfindex methodCount (void) const
 get the count of method registered to this ZFClass
 
zfiter methodIter (void) const
 see zfiter
 
const ZFMethodmethodIterValue (const zfiter &it) const
 see zfiter
 
void methodGetAllIgnoreParentT (ZFCoreArray< const ZFMethod * > &ret) const
 see methodGetAllIgnoreParent
 
ZFCoreArray< const ZFMethod * > methodGetAllIgnoreParent (void) const
 get all method, excluding methods inherited from parent
 
void methodGetAllT (ZFCoreArray< const ZFMethod * > &ret) const
 see methodGetAll
 
ZFCoreArray< const ZFMethod * > methodGetAll (void) const
 get all method, including methods inherited from parent
 
const ZFMethodmethodForNameIgnoreParent (const zfstring &methodName, const zfchar *paramTypeId0, const zfchar *paramTypeId1=zft_zfnull, const zfchar *paramTypeId2=zft_zfnull, const zfchar *paramTypeId3=zft_zfnull, const zfchar *paramTypeId4=zft_zfnull, const zfchar *paramTypeId5=zft_zfnull, const zfchar *paramTypeId6=zft_zfnull, const zfchar *paramTypeId7=zft_zfnull) const
 get the method by name within this class only, or zfnull if not exists
 
const ZFMethodmethodForNameIgnoreParent (const zfstring &methodName) const
 see methodForNameIgnoreParent
 
void methodForNameGetAllIgnoreParentT (ZFCoreArray< const ZFMethod * > &ret, const zfstring &methodName) const
 see methodForNameIgnoreParent
 
ZFCoreArray< const ZFMethod * > methodForNameGetAllIgnoreParent (const zfstring &methodName) const
 see methodForNameIgnoreParent
 
const ZFMethodmethodForName (const zfstring &methodName, const zfchar *paramTypeId0, const zfchar *paramTypeId1=zft_zfnull, const zfchar *paramTypeId2=zft_zfnull, const zfchar *paramTypeId3=zft_zfnull, const zfchar *paramTypeId4=zft_zfnull, const zfchar *paramTypeId5=zft_zfnull, const zfchar *paramTypeId6=zft_zfnull, const zfchar *paramTypeId7=zft_zfnull) const
 get the method by name hierarchically from class inherit tree, or zfnull if not exists
 
const ZFMethodmethodForName (const zfstring &methodName) const
 see methodForName
 
void methodForNameGetAllT (ZFCoreArray< const ZFMethod * > &ret, const zfstring &methodName) const
 see methodForNameGetAll
 
ZFCoreArray< const ZFMethod * > methodForNameGetAll (const zfstring &methodName) const
 get all method with name, ignoring method id
 
zfindex propertyCount (void) const
 get ZFProperty count registered to this class
 
zfiter propertyIter (void) const
 see zfiter
 
const ZFPropertypropertyIterValue (const zfiter &it) const
 see zfiter
 
void propertyGetAllIgnoreParentT (ZFCoreArray< const ZFProperty * > &ret) const
 see propertyGetAllIgnoreParent
 
ZFCoreArray< const ZFProperty * > propertyGetAllIgnoreParent (void) const
 get all property, including properties inherited from parent
 
void propertyGetAllT (ZFCoreArray< const ZFProperty * > &ret) const
 see propertyGetAll
 
ZFCoreArray< const ZFProperty * > propertyGetAll (void) const
 get all property, including properties inherited from parent
 
const ZFPropertypropertyForNameIgnoreParent (const zfstring &propertyName) const
 get the property by name within this class only, or zfnull if not exists
 
const ZFPropertypropertyForName (const zfstring &propertyName) const
 get the property by name hierarchically from class inherit tree, or zfnull if not exists
 
const ZFMethodpropertySetterForNameIgnoreParent (const zfstring &propertyName) const
 try to get property setter method within this class only
 
const ZFMethodpropertySetterForName (const zfstring &propertyName) const
 try to get property setter method
 
const ZFMethodpropertyGetterForNameIgnoreParent (const zfstring &propertyName) const
 try to get property getter method within this class only
 
const ZFMethodpropertyGetterForName (const zfstring &propertyName) const
 try to get property getter method
 
zfbool propertyInitStepExist (void) const
 whether the property has ZFPROPERTY_ON_INIT_DECLARE
 
zfbool propertyInitStepExist (const ZFProperty *property) const
 whether the property has ZFPROPERTY_ON_INIT_DECLARE
 
zfbool propertyInitStepIsEqual (const ZFProperty *property, const ZFClass *refClass) const
 whether two class has same property init step
 
void classTag (const zfstring &key, ZFObject *tag) const
 set a classTag for the class, internal use only
 
zfany classTag (const zfstring &key) const
 see classTag
 
void classTagGetAllKeyValue (ZFCoreArray< zfstring > &allKey, ZFCoreArray< zfauto > &allValue) const
 see classTag
 
void classTagRemove (const zfstring &key) const
 see classTag
 
zfauto classTagRemoveAndGet (const zfstring &key) const
 see classTag
 
void classTagRemoveAll (void) const
 see classTag
 
void dataCache (const zfstring &key, ZFObject *tag) const
 store class meta data cache, internal use only
 
zfany dataCache (const zfstring &key) const
 see dataCache
 
void dataCacheGetAllKeyValue (ZFCoreArray< zfstring > &allKey, ZFCoreArray< zfauto > &allValue) const
 see dataCache
 
void dataCacheRemove (const zfstring &key) const
 see dataCache
 
zfauto dataCacheRemoveAndGet (const zfstring &key) const
 see dataCache
 
void dataCacheRemoveAll (void) const
 see dataCache
 
zfidentity classId (void) const
 a unique id that represents the class
 

Static Public Member Functions

static const ZFClassclassForName (const zfstring &classNameOrFullName)
 get class info by name
 
static const ZFClassclassForName (const zfstring &className, const zfstring &classNamespace)
 find class with explicit namespace, see classForName
 

Detailed Description

ZFObject's class info.

See also
ZFObject

Member Function Documentation

◆ classForName()

static const ZFClass * ZFClass::classForName ( const zfstring & classNameOrFullName)
static

get class info by name

Returns
class info or zfnull if not found

typical usage:

const ZFClass *cls = ZFClass::classForName("MyObject");
zfauto objTmp = ((cls != zfnull) ? cls->newInstance() : zfauto());
MyObject *obj = objTmp;
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zfauto newInstance(void) const
make a new instance of ZFObject dynamically, which is described by ZFClass
static const ZFClass * classForName(const zfstring &classNameOrFullName)
get class info by name
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
Note
the class to find must:
See also
ZFOBJECT_DECLARE, ZFOBJECT_REGISTER
Note
the className may be simple format ("MyObject") or full format ("Scope0.Scope1.MyObject"), while in simple format, the class must be placed in global scope (ZF_NAMESPACE_GLOBAL)
for ZFTypeIdWrapper, the class name would be "YourType" instead of "v_YourType"

◆ instanceObserverRemoveAll()

void ZFClass::instanceObserverRemoveAll ( void ) const

see instanceObserverAdd

Note
it's unsafe to remove all observer manually, which may break unrelated modules' observer logic, remove only if necessary
typically, you should remove exactly the one you have added

◆ classIsAbstract()

zfbool ZFClass::classIsAbstract ( void ) const
inline

true if the class is abstract class

newInstance would return zfnull if the class is abstract

◆ classIsInternal()

zfbool ZFClass::classIsInternal ( void ) const
inline

whether the class is internal class

all class that have "_ZFP_" as prefix (or parent scope prefix) would be treated as internal class
internal class should not be used publicly, however, you may still apply alloc observer or reflection, see classIsInternalPrivate

◆ classIsInternalPrivate()

zfbool ZFClass::classIsInternalPrivate ( void ) const
inline

whether the class is internal private class

all class that have "_ZFP_I_" as prefix (or parent scope prefix) would be treated as internal private class
internal private class should not be used publicly, also, it would be ignored from alloc observer and reflection, see classIsInternal

◆ classCanAllocPublic()

zfbool ZFClass::classCanAllocPublic ( void ) const
inline

whether the class can alloc directly, see ZFOBJECT_PRIVATE_ALLOC

when marked by ZFOBJECT_PRIVATE_ALLOC, the class can not be created normally (zfAlloc or ZFDI_alloc), typically it's protected by impl to prevent internal class from being allocated accidently, but you can still create by reflection, i.e. newInstance series

◆ newInstance() [1/2]

zfauto ZFClass::newInstance ( void ) const

make a new instance of ZFObject dynamically, which is described by ZFClass

typical usage:

ZFObject *myObj = zfAlloc(MyObject);
...
// OK, newObj is a new instance of MyObject
zfauto newObjTmp = myObj->classData()->newInstance();
ZFObject *newObj = newObjTmp;
#define zfAlloc(T_ZFObject,...)
alloc an object, see ZFObject
Definition ZFObjectRetain.h:104
base class of all objects
Definition ZFObjectCore.h:209
virtual const ZFClass * classData(void)
get instance's class info
Definition ZFObjectCore.h:210
Note
object's no param version of objectOnInit would be called, if you want to construct with params, use newInstanceGenericBegin instead

◆ newInstance() [2/2]

zfauto ZFClass::newInstance ( ZFObject * param0,
ZFObject * param1 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param2 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param3 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param4 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param5 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param6 = ((ZFObject *const &) _ZFP_ZFMP_DEF),
ZFObject * param7 = ((ZFObject *const &) _ZFP_ZFMP_DEF) ) const

for advanced reflection use only

create object by specified params, the object must have proper ZFObject::objectOnInit declared as ZFOBJECT_ON_INIT_DECLARE_1 series, and params are passed according to ZFMethodGenericInvoker

Note
this method do much reflection steps to find proper objectOnInit, which may cause performance issue, use with caution, or use newInstanceGenericBegin if available:
zfauto result;
ZFCoreArray<const ZFMethod *> objectOnInitMethodList;
cls->methodForNameGetAllT(objectOnInitMethodList, "objectOnInit");
// you may do your extra method filters before actual alloc the object
void *token = cls->newInstanceGenericBegin();
if(token != zfnull) {
for(zfindex i = 0; i < objectOnInitMethodList.count(); ++i) {
if(cls->newInstanceGenericCheck(token, objectOnInitMethodList[i], zfargs)) {
result = cls->newInstanceGenericEnd(token, zftrue);
break;
}
}
if(result == zfnull) {
cls->newInstanceGenericEnd(token, zffalse);
}
}
_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
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
light weight array
Definition ZFCoreArray.h:331
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:920
if the objectOnInit is declared by ZFOBJECT_ON_INIT_DECLARE_1 series, it's called as is, if it's user registered (ZFMETHOD_USER_REGISTER_1 series), ZFObject::objectOnInit would be called before invoke the method to prevent logic error
if all params are ZFMP_DEF, this method would call original ZFObject::objectOnInit instead (same as newInstance)

see also ZFObjectTagKeyword_newInstanceGenericFailed

◆ methodCount()

zfindex ZFClass::methodCount ( void ) const

get the count of method registered to this ZFClass

note that parent class's method won't be included
the order is ensured to be the same as ZFMethod declared

Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ methodForNameIgnoreParent()

const ZFMethod * ZFClass::methodForNameIgnoreParent ( const zfstring & methodName,
const zfchar * paramTypeId0,
const zfchar * paramTypeId1 = zft_zfnull,
const zfchar * paramTypeId2 = zft_zfnull,
const zfchar * paramTypeId3 = zft_zfnull,
const zfchar * paramTypeId4 = zft_zfnull,
const zfchar * paramTypeId5 = zft_zfnull,
const zfchar * paramTypeId6 = zft_zfnull,
const zfchar * paramTypeId7 = zft_zfnull ) const

get the method by name within this class only, or zfnull if not exists

the following optional params are, type id of each param type described by ZFTypeId::TypeId, if more than one method with same name (and or param type id) were found, the first one would be returned

See also
methodForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ methodForName()

const ZFMethod * ZFClass::methodForName ( const zfstring & methodName,
const zfchar * paramTypeId0,
const zfchar * paramTypeId1 = zft_zfnull,
const zfchar * paramTypeId2 = zft_zfnull,
const zfchar * paramTypeId3 = zft_zfnull,
const zfchar * paramTypeId4 = zft_zfnull,
const zfchar * paramTypeId5 = zft_zfnull,
const zfchar * paramTypeId6 = zft_zfnull,
const zfchar * paramTypeId7 = zft_zfnull ) const

get the method by name hierarchically from class inherit tree, or zfnull if not exists

searching from subclass to parent class, return the first matched

See also
methodForNameIgnoreParent
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER
ensured breadth-first

◆ propertyCount()

zfindex ZFClass::propertyCount ( void ) const

get ZFProperty count registered to this class

note that parent class's property won't be included
the order is ensured to be the same as property declared

Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ propertyForNameIgnoreParent()

const ZFProperty * ZFClass::propertyForNameIgnoreParent ( const zfstring & propertyName) const

get the property by name within this class only, or zfnull if not exists

propertyName should be "Property" without "set" or "get"
note that parent class's property won't be included

See also
propertyForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ propertyForName()

const ZFProperty * ZFClass::propertyForName ( const zfstring & propertyName) const

get the property by name hierarchically from class inherit tree, or zfnull if not exists

propertyName should be "Property" without "set" or "get"
searching from subclass to parent class, return the first matched

See also
propertyForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER
ensured breadth-first

◆ propertySetterForNameIgnoreParent()

const ZFMethod * ZFClass::propertySetterForNameIgnoreParent ( const zfstring & propertyName) const

try to get property setter method within this class only

note, the property has no need to exist, we only search method with proper name and param and return type

◆ propertySetterForName()

const ZFMethod * ZFClass::propertySetterForName ( const zfstring & propertyName) const

try to get property setter method

note, the property has no need to exist, we only search method with proper name and param and return type

◆ propertyGetterForNameIgnoreParent()

const ZFMethod * ZFClass::propertyGetterForNameIgnoreParent ( const zfstring & propertyName) const

try to get property getter method within this class only

note, the property has no need to exist, we only search method with proper name and param and return type

◆ propertyGetterForName()

const ZFMethod * ZFClass::propertyGetterForName ( const zfstring & propertyName) const

try to get property getter method

note, the property has no need to exist, we only search method with proper name and param and return type

◆ classTag()

void ZFClass::classTag ( const zfstring & key,
ZFObject * tag ) const

set a classTag for the class, internal use only

Note
all classTags would be removed during ZFFrameworkCleanup as ZFLevelZFFrameworkHigh and ZFLevelZFFrameworkEssential, you must ensure the classTag is safe to be deleted at this time

◆ classTagRemoveAll()

void ZFClass::classTagRemoveAll ( void ) const

see classTag

Note
it's unsafe to remove all tag manually, which may break unrelated modules' additional logic, remove only if necessary
typically, you should remove exactly the one you have added

◆ dataCache()

void ZFClass::dataCache ( const zfstring & key,
ZFObject * tag ) const

store class meta data cache, internal use only

Note
all dataCaches would be removed during ZFFrameworkCleanup as ZFLevelZFFrameworkHigh and ZFLevelZFFrameworkEssential, you must ensure the dataCache is safe to be deleted at this time
usually used to store meta-data for performance use only
all dataCaches would be cleared during ZFGlobalEvent::E_ClassDataUpdate

◆ classId()

zfidentity ZFClass::classId ( void ) const
inline

a unique id that represents the class

Note
the id may be reused if owner class unloaded

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