ZFFramework
 
Loading...
Searching...
No Matches
ZFObjectAutoPtr.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFObjectAutoPtr_h_
7#define _ZFI_ZFObjectAutoPtr_h_
8
9#include "ZFObjectRetain.h"
10#include "zfauto.h"
11
13
14// ============================================================
16 zfRetain(p);
17 }, {
18 zfRelease(p);
19 })
20
21// ============================================================
22zffinal zfclassNotPOD ZFLIB_ZFCore _ZFP_zflineRelease {
23public:
24 template<typename T_ZFObject>
25 T_ZFObject set(T_ZFObject obj) {
26 this->obj = zfcast(ZFObject *, obj);
27 return obj;
28 }
29public:
30 _ZFP_zflineRelease(void)
31 : obj(zfnull)
32 {
33 }
34 ~_ZFP_zflineRelease(void) {
35 zfRelease(obj);
36 }
37public:
38 ZFObject *obj;
39};
40zffinal zfclassNotPOD ZFLIB_ZFCore _ZFP_zfunsafe_zflineRelease {
41public:
42 template<typename T_ZFObject>
43 T_ZFObject set(T_ZFObject obj) {
44 this->obj = zfcast(ZFObject *, obj);
45 return obj;
46 }
47public:
48 _ZFP_zfunsafe_zflineRelease(void)
49 : obj(zfnull)
50 {
51 }
52 ~_ZFP_zfunsafe_zflineRelease(void) {
54 }
55public:
56 ZFObject *obj;
57};
82#define zflineRelease(obj) (_ZFP_zflineRelease().set(obj))
84#define zfunsafe_zflineRelease(obj) (_ZFP_zfunsafe_zflineRelease().set(obj))
85
86// ============================================================
90#define zflineAlloc(T_ZFObject, ...) \
91 zflineRelease(zfAlloc(T_ZFObject, ##__VA_ARGS__))
92
93#define zfunsafe_zflineAlloc(T_ZFObject, ...) \
94 zfunsafe_zflineRelease(zfunsafe_zfAlloc(T_ZFObject, ##__VA_ARGS__))
95
96// ============================================================
97zffinal zfclassLikePOD ZFLIB_ZFCore _ZFP_zfblockedReleaseContainer {
98public:
99 template<typename T_ZFObject>
100 _ZFP_zfblockedReleaseContainer(ZF_IN T_ZFObject obj)
101 : obj(zfcast(ZFObject *, obj))
102 {
103 }
104 ~_ZFP_zfblockedReleaseContainer(void) {
105 zfRelease(this->obj);
106 }
107private:
108 ZFObject *obj;
109};
110zffinal zfclassLikePOD ZFLIB_ZFCore _ZFP_zfunsafe_zfblockedReleaseContainer {
111public:
112 template<typename T_ZFObject>
113 _ZFP_zfunsafe_zfblockedReleaseContainer(ZF_IN T_ZFObject obj)
114 : obj(zfcast(ZFObject *, obj))
115 {
116 }
117 ~_ZFP_zfunsafe_zfblockedReleaseContainer(void) {
118 zfRelease(this->obj);
119 }
120private:
121 ZFObject *obj;
122};
134#define zfblockedRelease(obj) \
135 _ZFP_zfblockedReleaseContainer ZFUniqueName(zfblockedRelease) (obj)
136
137#define zfunsafe_zfblockedRelease(obj) \
138 _ZFP_zfunsafe_zfblockedReleaseContainer ZFUniqueName(zfblockedRelease) (obj)
139
156template<typename T_ZFObjectBase>
159public:
160 zfobj(void)
162 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase));}
163
164 template<typename P0>
165 zfobj(P0 const &p0)
167 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0));}
168
169 template<typename P0, typename P1>
170 zfobj(P0 const &p0, P1 const &p1)
172 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1));}
173
174 template<typename P0, typename P1, typename P2>
175 zfobj(P0 const &p0, P1 const &p1, P2 const &p2)
177 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2));}
178
179 template<typename P0, typename P1, typename P2, typename P3>
180 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3)
182 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2, p3));}
183
184 template<typename P0, typename P1, typename P2, typename P3, typename P4>
185 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4)
187 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4));}
188
189 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
190 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4, P5 const &p5)
192 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5));}
193
194 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
195 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4, P5 const &p5, P6 const &p6)
197 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5, p6));}
198
199 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
200 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4, P5 const &p5, P6 const &p6, P7 const &p7)
202 {this->zfunsafe_assign(zfunsafe_zflineAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5, p6, p7));}
203
204public:
205 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfauto const &obj) {
206 zfauto::operator = (obj);
207 return *this;
208 }
209 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfautoT<T_ZFObjectBase> const &obj) {
210 zfauto::operator = ((zfauto const &)obj);
211 return *this;
212 }
213 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfobj<T_ZFObjectBase> const &obj) {
214 zfauto::operator = ((zfauto const &)obj);
215 return *this;
216 }
217 template<typename T_ZFObject>
218 inline zfautoT<T_ZFObjectBase> &operator = (ZF_IN T_ZFObject const &obj) {
219 zfauto::operator = (obj);
220 return *this;
221 }
222
223public:
224 template<typename T_ZFObject>
225 inline zfbool operator == (ZF_IN T_ZFObject const &obj) const {
226 return this->toObject() == _ZFP_zfanyCast(obj);
227 }
228 template<typename T_ZFObject>
229 inline zfbool operator != (ZF_IN T_ZFObject const &obj) const {
230 return this->toObject() != _ZFP_zfanyCast(obj);
231 }
232
233public:
234 T_ZFObjectBase *operator -> (void) const {
235 return zfcast(T_ZFObjectBase *, this->toObject());
236 }
237
238public:
239 inline ZFObject *toObject(void) const { // required for _ZFP_zfanyCast to work
241 }
242
243public:
245};
246
248
249#endif // #ifndef _ZFI_ZFObjectAutoPtr_h_
250
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZFCOREPOINTER_DECLARE(T_ZFCorePointer, pointerRetainAction, pointerDeleteAction)
declare your custom ZFCorePointerT type
Definition ZFCorePointer.h:347
#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 zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#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
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#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 zfunsafe_zflineAlloc(T_ZFObject,...)
no lock version of zflineAlloc, use with caution
Definition ZFObjectAutoPtr.h:93
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
retain count logic for ZFFramework
#define zfRelease(obj)
release an object, see ZFObject
Definition ZFObjectRetain.h:148
#define zfunsafe_zfRelease(obj)
no lock version of zfRelease, use with caution
Definition ZFObjectRetain.h:151
#define zfRetain(obj)
retain an object, see ZFObject
Definition ZFObjectRetain.h:128
see ZFCorePointerT
Definition ZFObjectAutoPtr.h:19
base class of all objects
Definition ZFObjectCore.h:209
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
void zfunsafe_assign(ZFObject *obj)
no lock version of object assign, for low level impl only
ZFObject * toObject(void) const
get the holded object
Definition zfautoFwd.h:91
type restrict version of zfauto
Definition zfautoFwd.h:110
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:157
smart pointer for ZFObject