ZFFramework
 
Loading...
Searching...
No Matches
ZFValueHolder.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFValueHolder_h_
7#define _ZFI_ZFValueHolder_h_
8
9#include "ZFObjectCore.h"
10#include "ZFObjectRetain.h"
12
13// ============================================================
14// ZFValueHolder
25typedef void (*ZFValueHolderType)(ZF_IN void *holdedData);
29zffinal zfclass ZFLIB_ZFCore ZFValueHolder : zfextend ZFObject {
30 // ============================================================
31public:
32 ZFOBJECT_DECLARE_WITH_CUSTOM_CTOR(ZFValueHolder, ZFObject)
33
34protected:
35 ZFValueHolder(void) : holdedData(zfnull), holderType(zfnull) {}
36
38 cache->_cleanup();
39 })
40private:
41 void _cleanup(void) {
42 if(this->holdedData && this->holderType) {
43 void *holdedData = this->holdedData;
44 ZFValueHolderType holderType = this->holderType;
45 this->holdedData = zfnull;
46 this->holderType = zfnull;
47 holderType(holdedData);
48 }
49 else {
50 this->holdedData = zfnull;
51 this->holderType = zfnull;
52 }
53 }
54
55protected:
59 virtual void objectOnInit(
60 ZF_IN void *holdedData
62 ) {
63 this->holdedData = holdedData;
64 this->holderType = holderType;
65 }
67 virtual void objectOnInit(void) {
69 }
71 virtual void objectOnDeallocPrepare(void) {
72 this->_cleanup();
74 }
75
76public:
88
89public:
91 template<typename T_RawType>
92 inline T_RawType holdedDataPointer(void) {
93 return (T_RawType)this->holdedData;
94 }
95
96 template<typename T_RawType>
97 inline T_RawType holdedDataRef(void) {
98 typedef typename zftTraits<T_RawType>::TrPtr T_RawTypePointer;
99 return *(T_RawTypePointer)this->holdedData;
100 }
101
102protected:
105public:
107 virtual ZFCompareResult objectCompareValueImpl(ZF_IN ZFObject *anotherObj);
108};
109zfclassNotPOD ZFLIB_ZFCore _ZFP_ZFValueHolderType {
110public:
111 static void TypePointerRef(ZF_IN void *holdedData) {
112 }
113 static void TypePOD(ZF_IN void *holdedData) {
114 zffree(holdedData);
115 }
116 template<typename T_Object>
117 static void TypeObject(ZF_IN void *holdedData) {
118 zfdelete((T_Object)holdedData);
119 }
120 template<typename T_Object>
121 static void TypePoolObject(ZF_IN void *holdedData) {
122 zfpoolDelete((T_Object)holdedData);
123 }
124};
126#define ZFValueHolderTypePointerRef() _ZFP_ZFValueHolderType::TypePointerRef
128#define ZFValueHolderTypePOD() _ZFP_ZFValueHolderType::TypePOD
130#define ZFValueHolderTypeObject(T_Object) _ZFP_ZFValueHolderType::TypeObject<T_Object>
132#define ZFValueHolderTypePoolObject(T_Object) _ZFP_ZFValueHolderType::TypePoolObject<T_Object>
133
135#endif // #ifndef _ZFI_ZFValueHolder_h_
136
#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 zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfdelete(instance)
same as delete defined for future use
Definition ZFCoreTypeDef_ClassType.h:91
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define zffree(ptr)
same as free defined for future use, do nothing if ptr is NULL
Definition ZFCoreTypeDef_ClassType.h:112
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#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:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define zfpoolDelete(obj)
see zfpoolNew
Definition ZFMemPool.h:38
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
base class of all objects
#define ZFOBJECT_DECLARE_WITH_CUSTOM_CTOR(ChildClass, SuperClass,...)
declare object which allow custom constructor
Definition ZFObjectDeclare.h:142
retain count logic for ZFFramework
#define ZFALLOC_CACHE_RELEASE(action)
mark class that it should apply cache logic when alloc
Definition ZFObjectRetain.h:186
void(* ZFValueHolderType)(void *holdedData)
type for ZFValueHolder
Definition ZFValueHolder.h:25
virtual void objectOnInit(void)
override this to init your object
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFObjectCore.h:758
used to hold a non ZFObject type for performance
Definition ZFValueHolder.h:29
virtual void objectOnInit(void)
override this to init your object
Definition ZFValueHolder.h:67
virtual void objectOnInit(void *holdedData, ZFValueHolderType holderType)
init with object
Definition ZFValueHolder.h:59
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
ZFValueHolderType holderType
delete callback to clear the holdedData
Definition ZFValueHolder.h:87
void * holdedData
used to hold the raw pointer
Definition ZFValueHolder.h:83
T_RawType holdedDataRef(void)
util method to cast holdedData
Definition ZFValueHolder.h:97
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFValueHolder.h:71
T_RawType holdedDataPointer(void)
util method to cast holdedData
Definition ZFValueHolder.h:92
virtual ZFCompareResult objectCompareValueImpl(ZFObject *anotherObj)
see objectCompareValue
T_Type * TrPtr
pointer type
Definition ZFCoreUtilTemplate.h:108