ZFFramework
Loading...
Searching...
No Matches
ZFProperty.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFProperty_h_
7#define _ZFI_ZFProperty_h_
8
9#include "ZFPropertyFwd.h"
10#include "ZFMethod.h"
11#include "zfany.h"
13
14// ============================================================
16typedef void (*_ZFP_ZFPropertyCallbackEnsureInit)(
17 ZF_IN const ZFProperty *property
18 , ZF_IN zfany const &owner
19 );
20typedef void (*_ZFP_ZFPropertyCallbackDealloc)(
21 ZF_IN const ZFProperty *property
22 , ZF_IN zfany const &owner
23 );
29
30public:
32 void objectInfoT(ZF_IN_OUT zfstring &ret) const;
36 zfstring objectInfo(void) const {
37 zfstring ret;
38 this->objectInfoT(ret);
39 return ret;
40 }
41
42public:
46 inline zfidentity propertyId(void) const {
47 return _propertyId.sigId();
48 }
49
52 inline zfbool isUserRegister(void) const {
53 return ZFBitTest(_stateFlags, _stateFlags_isUserRegister);
54 }
55
58 inline zfbool isDynamicRegister(void) const {
59 return ZFBitTest(_stateFlags, _stateFlags_isDynamicRegister);
60 }
61
64 inline zfany dynamicRegisterUserData(void) const {
65 return _dynamicRegisterUserData;
66 }
67
82 inline const ZFClass *ownerClass(void) const {
83 return _ownerClass;
84 }
85
88 inline const zfstring &propertyName(void) const {
89 return _propertyName;
90 }
91
99 inline const zfstring &propertyTypeName(void) const {
100 return _propertyTypeName ? _propertyTypeName : _propertyTypeId;
101 }
102
110 inline const zfstring &propertyTypeId(void) const {
111 return _propertyTypeId;
112 }
113
116 inline const ZFMethod *setterMethod(void) const {
117 return _setterMethod;
118 }
119
122 inline const ZFMethod *getterMethod(void) const {
123 return _getterMethod;
124 }
125
132 inline zfbool isRetainProperty(void) const {
133 return (_propertyClassOfRetainProperty != zfnull);
134 }
135
140 inline const ZFClass *propertyClassOfRetainProperty(void) const {
141 return _propertyClassOfRetainProperty;
142 }
143
144public:
155 inline zfbool isInternal(void) const {
156 return ZFBitTest(_stateFlags, _stateFlags_isInternal);
157 }
158
168 inline zfbool isInternalPrivate(void) const {
169 return ZFBitTest(_stateFlags, _stateFlags_isInternalPrivate);
170 }
171
172public:
183
184public:
186 ZFProperty(void);
187 ~ZFProperty(void);
189
190public:
191 static ZFProperty *_ZFP_ZFPropertyRegister(
195 , ZF_IN const ZFClass *ownerClass
196 , ZF_IN const zfstring &name
197 , ZF_IN const zfstring &typeName
198 , ZF_IN const zfstring &typeIdName
207 , ZF_IN _ZFP_ZFPropertyCallbackEnsureInit callbackEnsureInit
208 , ZF_IN _ZFP_ZFPropertyCallbackDealloc callbackDealloc
209 );
210 static void _ZFP_ZFPropertyUnregister(ZF_IN const ZFProperty *propertyInfo);
211
212 void _ZFP_ZFPropertyInit(
216 , ZF_IN const ZFClass *ownerClass
217 , ZF_IN const zfstring &name
218 , ZF_IN const zfstring &typeName
219 , ZF_IN const zfstring &typeIdName
223 );
224 ZFProperty *_ZFP_ZFProperty_removeConst(void) const {
225 return const_cast<ZFProperty *>(this);
226 }
227 inline ZFObject *_ZFP_ZFProperty_dynamicRegisterUserDataWrapper(void) const {
228 return _dynamicRegisterUserDataWrapper;
229 }
230 void _ZFP_ZFProperty_dynamicRegisterUserDataWrapper(ZF_IN ZFObject *v) const;
231
232 _ZFP_ZFPropertyCallbackEnsureInit _ZFP_ZFProperty_callbackEnsureInit(void) const {
233 return _callbackEnsureInit;
234 }
235 _ZFP_ZFPropertyCallbackDealloc _ZFP_ZFProperty_callbackDealloc(void) const {
236 return _callbackDealloc;
237 }
238
239private:
240 enum {
241 _stateFlags_isInternal = 1 << 0,
242 _stateFlags_isInternalPrivate = 1 << 1,
243 _stateFlags_isUserRegister = 1 << 2,
244 _stateFlags_isDynamicRegister = 1 << 3,
245 };
246private:
247 zfuint _refCount;
248 zfuint _stateFlags;
249 ZFSigName _propertyId;
250 ZFObject *_dynamicRegisterUserData;
251 ZFObject *_dynamicRegisterUserDataWrapper;
252 const ZFClass *_ownerClass;
253 ZFSigName _propertyName;
254 ZFSigName _propertyTypeName;
255 ZFSigName _propertyTypeId;
256 const ZFMethod *_setterMethod;
257 const ZFMethod *_getterMethod;
258 const ZFClass *_propertyClassOfRetainProperty;
259 _ZFP_ZFPropertyCallbackEnsureInit _callbackEnsureInit;
260 _ZFP_ZFPropertyCallbackDealloc _callbackDealloc;
261public:
262 ZFCoreArray<_ZFP_PropLifeCycleData> _ZFP_ZFPropertyLifeCycle_OnInit; // ordered from parent to child
263 ZFCoreArray<_ZFP_PropLifeCycleData> _ZFP_ZFPropertyLifeCycle_OnUpdate;
264 ZFCoreArray<_ZFP_PropLifeCycleData> _ZFP_ZFPropertyLifeCycle_OnAttach;
265 ZFCoreArray<_ZFP_PropLifeCycleData> _ZFP_ZFPropertyLifeCycle_OnDetach;
266};
267
268// ============================================================
279
280// ============================================================
281zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFPropertyRegisterHolder {
282public:
283 _ZFP_ZFPropertyRegisterHolder(
284 ZF_IN zfbool isUserRegister
285 , ZF_IN zfbool isDynamicRegister
286 , ZF_IN ZFObject *dynamicRegisterUserData
287 , ZF_IN const ZFClass *ownerClass
288 , ZF_IN const zfstring &name
289 , ZF_IN const zfstring &typeName
290 , ZF_IN const zfstring &typeIdName
291 , ZF_IN const ZFMethod *setterMethod
292 , ZF_IN const ZFMethod *getterMethod
293 , ZF_IN const ZFClass *propertyClassOfRetainProperty
294 , ZF_IN ZFPropertyCallbackIsValueAccessed callbackIsValueAccessed
295 , ZF_IN ZFPropertyCallbackIsInitValue callbackIsInitValue
296 , ZF_IN ZFPropertyCallbackValueReset callbackValueReset
297 , ZF_IN ZFPropertyCallbackUserRegisterInitValueSetup callbackUserRegisterInitValueSetup
298 , ZF_IN ZFPropertyCallbackDynamicRegisterInitValueGetter callbackDynamicRegisterInitValueGetter
299 , ZF_IN _ZFP_ZFPropertyCallbackEnsureInit callbackEnsureInit
300 , ZF_IN _ZFP_ZFPropertyCallbackDealloc callbackDealloc
301 )
302 : propertyInfo(ZFProperty::_ZFP_ZFPropertyRegister(
303 isUserRegister
304 , isDynamicRegister
305 , dynamicRegisterUserData
306 , ownerClass
307 , name
308 , typeName
309 , typeIdName
310 , setterMethod
311 , getterMethod
312 , propertyClassOfRetainProperty
313 , callbackIsValueAccessed
314 , callbackIsInitValue
315 , callbackValueReset
316 , callbackUserRegisterInitValueSetup
317 , callbackDynamicRegisterInitValueGetter
318 , callbackEnsureInit
319 , callbackDealloc
320 )) {
321 }
322 ~_ZFP_ZFPropertyRegisterHolder(void) {
323 ZFProperty::_ZFP_ZFPropertyUnregister(this->propertyInfo);
324 }
325public:
326 ZFProperty *propertyInfo;
327};
328
330#endif // #ifndef _ZFI_ZFProperty_h_
331
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:200
#define ZFCLASS_DISALLOW_COPY_CONSTRUCTOR(ClassName)
a macro to show that a class doesn't allow copy constructor
Definition ZFCoreTypeDef_ClassType.h:81
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFBitTest(var, bit)
macro to detect whether bit is set, zftrue if any one of test bit has set
Definition ZFCoreUtilMacro.h:16
reflectable method definination for ZFFramework
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
ZFCoreArray< const ZFProperty * > ZFPropertyGetAll(void)
get all property currently registered, for debug use only
Definition ZFProperty.h:274
void ZFPropertyGetAllT(ZFCoreArray< const ZFProperty * > &ret)
see ZFPropertyGetAll
property for ZFObject type
zfauto(* ZFPropertyCallbackDynamicRegisterInitValueGetter)(const ZFProperty *property)
callback to setup init value for ZFPropertyDynamicRegister
Definition ZFPropertyFwd.h:86
zfbool(* ZFPropertyCallbackIsValueAccessed)(const ZFProperty *property, zfany const &ownerObj)
used to check whether the property has been accessed
Definition ZFPropertyFwd.h:27
void(* ZFPropertyCallbackValueReset)(const ZFProperty *property, zfany const &ownerObj)
used to reset the property to its init state
Definition ZFPropertyFwd.h:63
zfbool(* ZFPropertyCallbackIsInitValue)(const ZFProperty *property, zfany const &ownerObj, zfauto *outInitValue)
used to check whether the property is in init value state
Definition ZFPropertyFwd.h:48
void(* ZFPropertyCallbackUserRegisterInitValueSetup)(const ZFProperty *property, void *v)
for user registered property only, used to setup a property's init value
Definition ZFPropertyFwd.h:77
ZFObject's class info.
Definition ZFClass.h:66
light weight array
Definition ZFCoreArray.h:344
reflectable method for ZFObject
Definition ZFMethod.h:252
base class of all objects
Definition ZFObjectCore.h:196
info for a property for ZFObject, see ZFPROPERTY_RETAIN for more info
Definition ZFProperty.h:27
const ZFMethod * getterMethod(void) const
get the getter method
Definition ZFProperty.h:122
void objectInfoT(zfstring &ret) const
see objectInfo
const ZFMethod * setterMethod(void) const
get the getter method
Definition ZFProperty.h:116
zfstring objectInfo(void) const
get info about this property
Definition ZFProperty.h:36
ZFPropertyCallbackValueReset callbackValueReset
see ZFPropertyCallbackValueReset
Definition ZFProperty.h:178
const zfstring & propertyTypeId(void) const
type id string declared in ZFPROPERTY_XXX
Definition ZFProperty.h:110
ZFPropertyCallbackIsValueAccessed callbackIsValueAccessed
see ZFPropertyCallbackIsValueAccessed
Definition ZFProperty.h:174
zfbool isUserRegister(void) const
true if this property is registered by ZFPropertyUserRegisterRetain
Definition ZFProperty.h:52
zfbool isInternalPrivate(void) const
whether the property is internal private property
Definition ZFProperty.h:168
ZFPropertyCallbackDynamicRegisterInitValueGetter callbackDynamicRegisterInitValueGetter
see ZFPropertyDynamicRegister
Definition ZFProperty.h:182
zfbool isRetainProperty(void) const
true if the property is retain property
Definition ZFProperty.h:132
ZFPropertyCallbackUserRegisterInitValueSetup callbackUserRegisterInitValueSetup
see ZFPropertyUserRegisterAssign
Definition ZFProperty.h:180
const zfstring & propertyTypeName(void) const
type string for the property
Definition ZFProperty.h:99
const ZFClass * ownerClass(void) const
get the property's owner class
Definition ZFProperty.h:82
ZFPropertyCallbackIsInitValue callbackIsInitValue
see ZFPropertyCallbackIsInitValue
Definition ZFProperty.h:176
zfbool propertySerializable(void) const
true if the property is serializable
zfany dynamicRegisterUserData(void) const
see ZFPropertyDynamicRegister
Definition ZFProperty.h:64
const ZFClass * propertyClassOfRetainProperty(void) const
for retain property only, get the retain property's declared class
Definition ZFProperty.h:140
zfbool isInternal(void) const
whether the property is internal property
Definition ZFProperty.h:155
const zfstring & propertyName(void) const
name for the property
Definition ZFProperty.h:88
zfbool isDynamicRegister(void) const
true if this property is registered by ZFPropertyDynamicRegister
Definition ZFProperty.h:58
zfidentity propertyId(void) const
internal property id, for debug use only
Definition ZFProperty.h:46
readonly string container for internal use only
Definition ZFSigName.h:17
util method to cast ZFObject types freely
Definition zfany.h:35
util class to cast ZFObject types freely