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 zfclassLikePOD ZFLIB_ZFCore _ZFP_zfscopeReleaseContainer {
23public:
24 template<typename T_ZFObject>
25 _ZFP_zfscopeReleaseContainer(ZF_IN T_ZFObject obj)
26 : obj(zfcast(ZFObject *, obj))
27 {
28 }
29 ~_ZFP_zfscopeReleaseContainer(void) {
30 zfRelease(this->obj);
31 }
32private:
33 ZFObject *obj;
34};
35zffinal zfclassLikePOD ZFLIB_ZFCore _ZFP_zfunsafe_zfscopeReleaseContainer {
36public:
37 template<typename T_ZFObject>
38 _ZFP_zfunsafe_zfscopeReleaseContainer(ZF_IN T_ZFObject obj)
39 : obj(zfcast(ZFObject *, obj))
40 {
41 }
42 ~_ZFP_zfunsafe_zfscopeReleaseContainer(void) {
43 zfRelease(this->obj);
44 }
45private:
46 ZFObject *obj;
47};
59#define zfscopeRelease(obj) \
60 _ZFP_zfscopeReleaseContainer ZFUniqueName(zfscopeRelease) (obj)
61
62#define zfunsafe_zfscopeRelease(obj) \
63 _ZFP_zfunsafe_zfscopeReleaseContainer ZFUniqueName(zfscopeRelease) (obj)
64
78template<typename T_ZFObjectBase>
81public:
82 zfobj(void)
84 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
85
86 template<typename P0>
87 zfobj(P0 const &p0)
89 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
90
91 template<typename P0, typename P1>
92 zfobj(P0 const &p0, P1 const &p1)
94 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
95
96 template<typename P0, typename P1, typename P2>
97 zfobj(P0 const &p0, P1 const &p1, P2 const &p2)
99 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
100
101 template<typename P0, typename P1, typename P2, typename P3>
102 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3)
104 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2, p3); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
105
106 template<typename P0, typename P1, typename P2, typename P3, typename P4>
107 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4)
109 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
110
111 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
112 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4, P5 const &p5)
114 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
115
116 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
117 zfobj(P0 const &p0, P1 const &p1, P2 const &p2, P3 const &p3, P4 const &p4, P5 const &p5, P6 const &p6)
119 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5, p6); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
120
121 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
122 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)
124 {T_ZFObjectBase *v = zfunsafe_zfAlloc(T_ZFObjectBase, p0, p1, p2, p3, p4, p5, p6, p7); this->zfunsafe_assign(v); zfunsafe_zfRelease(v);}
125
126public:
127 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfauto const &obj) {
128 zfauto::operator = (obj);
129 return *this;
130 }
131 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfautoT<T_ZFObjectBase> const &obj) {
132 zfauto::operator = ((zfauto const &)obj);
133 return *this;
134 }
135 inline zfobj<T_ZFObjectBase> &operator = (ZF_IN zfobj<T_ZFObjectBase> const &obj) {
136 zfauto::operator = ((zfauto const &)obj);
137 return *this;
138 }
139 template<typename T_ZFObject>
140 inline zfautoT<T_ZFObjectBase> &operator = (ZF_IN T_ZFObject const &obj) {
141 zfauto::operator = (obj);
142 return *this;
143 }
144
145public:
146 template<typename T_ZFObject>
147 inline zfbool operator == (ZF_IN T_ZFObject const &obj) const {
148 return this->toObject() == _ZFP_zfanyCast(obj);
149 }
150 template<typename T_ZFObject>
151 inline zfbool operator != (ZF_IN T_ZFObject const &obj) const {
152 return this->toObject() != _ZFP_zfanyCast(obj);
153 }
154
155public:
156 T_ZFObjectBase *operator -> (void) const {
157 return zfcast(T_ZFObjectBase *, this->toObject());
158 }
159
160public:
161 inline ZFObject *toObject(void) const { // required for _ZFP_zfanyCast to work
163 }
164
165public:
167};
168
170
171#endif // #ifndef _ZFI_ZFObjectAutoPtr_h_
172
#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
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
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 zfunsafe_zfAlloc(T_ZFObject,...)
no lock version of zfAlloc, use with caution
Definition ZFObjectRetain.h:107
#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:205
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:94
type restrict version of zfauto
Definition zfautoFwd.h:113
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:79
smart pointer for ZFObject
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition zfcast.h:28