ZFFramework
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
ZFClass Class Reference

ZFObject's class info. More...

#include <ZFClass.h>

Public Member Functions

void instanceObserverAdd (const ZFListener &observer, ZFObject *owner=0, 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 classDataChangeAutoRemoveTagAdd (const zfchar *tag) const
 auto remove classTagRemove when class meta data changed
 
void classDataChangeAutoRemoveTagRemove (const zfchar *tag) const
 see classDataChangeAutoRemoveTagAdd
 
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 zfcharclassNamespace (void) const
 class namespace, null or empty string for global scope class
 
const zfcharclassName (void) const
 class name, e.g. "ZFObject"
 
const zfcharclassNameFull (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_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param2=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param3=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param4=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param5=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param6=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef), ZFObject *param7=((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)) const
 for advanced reflection use only
 
zfauto newInstanceDetail (const ZFCoreArray< zfauto > &params, zfbool *success=0, zfstring *errorHint=0) const
 see newInstance
 
void * newInstanceGenericBegin (void) const
 see newInstance
 
zfbool newInstanceGenericCheck (void *&token, const ZFMethod *objectOnInitMethod, zfindex paramCount, zfauto(&paramList)[8], zfstring *errorHint=0) const
 see newInstance
 
zfauto newInstanceGenericEnd (void *&token, zfbool objectOnInitMethodInvokeSuccess) const
 see newInstance
 
zfindex implementedInterfaceCount (void) const
 get implemented interface count
 
const ZFClassimplementedInterfaceAt (zfindex index) const
 get implemented interface
 
zfindex methodCount (void) const
 get the count of method registered to this ZFClass
 
const ZFMethodmethodAt (zfindex index) const
 get the method at index, assert fail if out of bounds
 
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 zfchar *methodName, const zfchar *methodParamTypeId0, const zfchar *methodParamTypeId1=0, const zfchar *methodParamTypeId2=0, const zfchar *methodParamTypeId3=0, const zfchar *methodParamTypeId4=0, const zfchar *methodParamTypeId5=0, const zfchar *methodParamTypeId6=0, const zfchar *methodParamTypeId7=0) const
 get the method by name within this class only, or zfnull if not exists
 
const ZFMethodmethodForNameIgnoreParent (const zfchar *methodName) const
 see methodForNameIgnoreParent
 
void methodForNameIgnoreParentGetAllT (ZFCoreArray< const ZFMethod * > &ret, const zfchar *methodName) const
 see methodForNameIgnoreParent
 
ZFCoreArray< const ZFMethod * > methodForNameIgnoreParentGetAll (const zfchar *methodName) const
 see methodForNameIgnoreParent
 
const ZFMethodmethodForName (const zfchar *methodName, const zfchar *methodParamTypeId0, const zfchar *methodParamTypeId1=0, const zfchar *methodParamTypeId2=0, const zfchar *methodParamTypeId3=0, const zfchar *methodParamTypeId4=0, const zfchar *methodParamTypeId5=0, const zfchar *methodParamTypeId6=0, const zfchar *methodParamTypeId7=0) const
 get the method by name hierarchically from class inherit tree, or zfnull if not exists
 
const ZFMethodmethodForName (const zfchar *methodName) const
 see methodForName
 
void methodForNameGetAllT (ZFCoreArray< const ZFMethod * > &ret, const zfchar *methodName) const
 see methodForNameGetAll
 
ZFCoreArray< const ZFMethod * > methodForNameGetAll (const zfchar *methodName) const
 get all method with name, ignoring method id
 
zfindex propertyCount (void) const
 get ZFProperty count registered to this class
 
const ZFPropertypropertyAt (zfindex index) const
 get ZFProperty at index
 
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 zfchar *propertyName) const
 get the property by name within this class only, or zfnull if not exists
 
const ZFPropertypropertyForName (const zfchar *propertyName) const
 get the property by name hierarchically from class inherit tree, or zfnull if not exists
 
const ZFMethodpropertySetterForNameIgnoreParent (const zfchar *propertyName) const
 try to get property setter method within this class only
 
const ZFMethodpropertySetterForName (const zfchar *propertyName) const
 try to get property setter method
 
const ZFMethodpropertyGetterForNameIgnoreParent (const zfchar *propertyName) const
 try to get property getter method within this class only
 
const ZFMethodpropertyGetterForName (const zfchar *propertyName) const
 try to get property getter method
 
zfbool propertyHasOverrideInitStep (void) const
 whether the property has ZFPROPERTY_ON_INIT_DECLARE
 
zfbool propertyHasOverrideInitStep (const ZFProperty *property) const
 whether the property has ZFPROPERTY_ON_INIT_DECLARE
 
void classTag (const zfchar *key, ZFObject *tag) const
 set a classTag for the class, internal use only
 
zfany classTag (const zfchar *key) const
 see classTag
 
void classTagGetAllKeyValue (ZFCoreArray< zfstring > &allKey, ZFCoreArray< zfauto > &allValue) const
 see classTag
 
void classTagRemove (const zfchar *key) const
 remove tag, same as set tag to null
 
zfauto classTagRemoveAndGet (const zfchar *key) const
 remove tag, return removed tag or null if not exist
 
void classTagRemoveAll (void) const
 see classTag
 

Static Public Member Functions

static const ZFClassclassForName (const zfchar *classNameOrFullName)
 get class info by name
 
static const ZFClassclassForName (const zfchar *className, const zfchar *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 zfchar * 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:50
ZFObject's class info.
Definition ZFClass.h:66
zfauto newInstance(void) const
make a new instance of ZFObject dynamically, which is described by ZFClass
static const ZFClass * classForName(const zfchar *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)

◆ 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

◆ classDataChangeAutoRemoveTagAdd()

void ZFClass::classDataChangeAutoRemoveTagAdd ( const zfchar * tag) const

auto remove classTagRemove when class meta data changed

class meta data would change if:

  • method register or unregistered
  • property register or unregistered

this method is useful if you cached some data by classTag according to class's method or property list, and want to update it again if meta data changed
see also ZFClassDataChangeObserver

◆ 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 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 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:96
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_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param2 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param3 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param4 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param5 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param6 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef),
ZFObject * param7 = ((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef) ) 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], paramCount, paramList)) {
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:108
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:62
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:66
light weight array
Definition ZFCoreArray.h:317
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:895
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 ZFMethodGenericInvokerDefaultParam, 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

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

◆ methodAt()

const ZFMethod * ZFClass::methodAt ( zfindex index) const

get the method at index, assert fail if out of bounds

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

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

◆ methodForNameIgnoreParent()

const ZFMethod * ZFClass::methodForNameIgnoreParent ( const zfchar * methodName,
const zfchar * methodParamTypeId0,
const zfchar * methodParamTypeId1 = 0,
const zfchar * methodParamTypeId2 = 0,
const zfchar * methodParamTypeId3 = 0,
const zfchar * methodParamTypeId4 = 0,
const zfchar * methodParamTypeId5 = 0,
const zfchar * methodParamTypeId6 = 0,
const zfchar * methodParamTypeId7 = 0 ) 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
methodAt, methodForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ methodForName()

const ZFMethod * ZFClass::methodForName ( const zfchar * methodName,
const zfchar * methodParamTypeId0,
const zfchar * methodParamTypeId1 = 0,
const zfchar * methodParamTypeId2 = 0,
const zfchar * methodParamTypeId3 = 0,
const zfchar * methodParamTypeId4 = 0,
const zfchar * methodParamTypeId5 = 0,
const zfchar * methodParamTypeId6 = 0,
const zfchar * methodParamTypeId7 = 0 ) 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
methodAt, 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

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

◆ propertyAt()

const ZFProperty * ZFClass::propertyAt ( zfindex index) const

get ZFProperty at index

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

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

◆ propertyForNameIgnoreParent()

const ZFProperty * ZFClass::propertyForNameIgnoreParent ( const zfchar * 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
propertyAt, propertyForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER

◆ propertyForName()

const ZFProperty * ZFClass::propertyForName ( const zfchar * 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
propertyAt, propertyForName
Note
can be found only if it matches the condition described in ZFOBJECT_REGISTER
ensured breadth-first

◆ propertySetterForNameIgnoreParent()

const ZFMethod * ZFClass::propertySetterForNameIgnoreParent ( const zfchar * 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 zfchar * 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 zfchar * 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 zfchar * 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 zfchar * key,
ZFObject * tag ) const

set a classTag for the class, internal use only

Note
this method is not thread-safe
all classTags would be removed during ZFFrameworkCleanup as ZFLevelZFFrameworkHigh and ZFLevelZFFrameworkEssential, you must ensure the classTag is safe to be deleted at this time
usually used to store meta-data for performance use only

◆ 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

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