ZFFramework
 
Loading...
Searching...
No Matches
ZFCoreUtilAutoPtr.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFCoreUtilAutoPtr_h_
7#define _ZFI_ZFCoreUtilAutoPtr_h_
8
9#include "ZFCoreTypeDef.h"
10
12
13// ============================================================
14// zfscopeFree
15zfclassLikePOD ZFLIB_ZFCore _ZFP_zfscopeFreeContainer {
16public:
17 _ZFP_zfscopeFreeContainer(ZF_IN void *p) : p(p) {}
18 ~_ZFP_zfscopeFreeContainer(void) {
19 zffree(this->p);
20 }
21private:
22 void *p;
23};
36#define zfscopeFree(obj) \
37 _ZFP_zfscopeFreeContainer ZFUniqueName(zfscopeFree_)(obj)
38
39// ============================================================
40// zfscopeDelete
41typedef void (*_ZFP_zfscopeDeleteCallback)(ZF_IN void *p);
42template<typename T_Object>
43void _ZFP_zfscopeDeleteOnDelete(ZF_IN void *p) {
44 zfdelete((T_Object *)p);
45}
46zfclassLikePOD ZFLIB_ZFCore _ZFP_zfscopeDeleteContainer {
47public:
48 _ZFP_zfscopeDeleteContainer(void) : p(zfnull), deleteCallback(zfnull) {}
49 ~_ZFP_zfscopeDeleteContainer(void) {
50 if(this->p != zfnull) {
51 this->deleteCallback(this->p);
52 }
53 }
54public:
55 void *p;
56 _ZFP_zfscopeDeleteCallback deleteCallback;
57};
58template<typename T_Object>
59void _ZFP_zfscopeDeleteSetup(
60 ZF_IN _ZFP_zfscopeDeleteContainer *container
61 , ZF_IN T_Object * const &p
62 ) {
63 container->p = (void *)p;
64 container->deleteCallback = _ZFP_zfscopeDeleteOnDelete<T_Object>;
65}
78#define zfscopeDelete(obj) \
79 _ZFP_zfscopeDeleteContainer ZFUniqueName(zfscopeDelete_); \
80 _ZFP_zfscopeDeleteSetup(&ZFUniqueName(zfscopeDelete_), obj)
81
82// ============================================================
83// zfscopeCleanup
87#define zfscopeCleanup_1(action \
88 , P0, p0 \
89 ) \
90 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
91 public: \
92 ZFUniqueName(zfscopeCleanup_T)(P0 &p0) \
93 : p0(p0) \
94 {} \
95 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
96 action \
97 } \
98 private: \
99 P0 &p0; \
100 } ZFUniqueName(zfscopeCleanup_)(p0)
102#define zfscopeCleanup_2(action \
103 , P0, p0 \
104 , P1, p1 \
105 ) \
106 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
107 public: \
108 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
109 , P1 &p1 \
110 ) \
111 : p0(p0) \
112 , p1(p1) \
113 {} \
114 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
115 action \
116 } \
117 private: \
118 P0 &p0; \
119 P1 &p1; \
120 } ZFUniqueName(zfscopeCleanup_)(p0 \
121 , p1 \
122 )
124#define zfscopeCleanup_3(action \
125 , P0, p0 \
126 , P1, p1 \
127 , P2, p2 \
128 ) \
129 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
130 public: \
131 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
132 , P1 &p1 \
133 , P2 &p2 \
134 ) \
135 : p0(p0) \
136 , p1(p1) \
137 , p2(p2) \
138 {} \
139 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
140 action \
141 } \
142 private: \
143 P0 &p0; \
144 P1 &p1; \
145 P2 &p2; \
146 } ZFUniqueName(zfscopeCleanup_)(p0 \
147 , p1 \
148 , p2 \
149 )
151#define zfscopeCleanup_4(action \
152 , P0, p0 \
153 , P1, p1 \
154 , P2, p2 \
155 , P3, p3 \
156 ) \
157 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
158 public: \
159 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
160 , P1 &p1 \
161 , P2 &p2 \
162 , P3 &p3 \
163 ) \
164 : p0(p0) \
165 , p1(p1) \
166 , p2(p2) \
167 , p3(p3) \
168 {} \
169 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
170 action \
171 } \
172 private: \
173 P0 &p0; \
174 P1 &p1; \
175 P2 &p2; \
176 P3 &p3; \
177 } ZFUniqueName(zfscopeCleanup_)(p0 \
178 , p1 \
179 , p2 \
180 , p3 \
181 )
183#define zfscopeCleanup_5(action \
184 , P0, p0 \
185 , P1, p1 \
186 , P2, p2 \
187 , P3, p3 \
188 , P4, p4 \
189 ) \
190 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
191 public: \
192 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
193 , P1 &p1 \
194 , P2 &p2 \
195 , P3 &p3 \
196 , P4 &p4 \
197 ) \
198 : p0(p0) \
199 , p1(p1) \
200 , p2(p2) \
201 , p3(p3) \
202 , p4(p4) \
203 {} \
204 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
205 action \
206 } \
207 private: \
208 P0 &p0; \
209 P1 &p1; \
210 P2 &p2; \
211 P3 &p3; \
212 P4 &p4; \
213 } ZFUniqueName(zfscopeCleanup_)(p0 \
214 , p1 \
215 , p2 \
216 , p3 \
217 , p4 \
218 )
220#define zfscopeCleanup_6(action \
221 , P0, p0 \
222 , P1, p1 \
223 , P2, p2 \
224 , P3, p3 \
225 , P4, p4 \
226 , P5, p5 \
227 ) \
228 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
229 public: \
230 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
231 , P1 &p1 \
232 , P2 &p2 \
233 , P3 &p3 \
234 , P4 &p4 \
235 , P5 &p5 \
236 ) \
237 : p0(p0) \
238 , p1(p1) \
239 , p2(p2) \
240 , p3(p3) \
241 , p4(p4) \
242 , p5(p5) \
243 {} \
244 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
245 action \
246 } \
247 private: \
248 P0 &p0; \
249 P1 &p1; \
250 P2 &p2; \
251 P3 &p3; \
252 P4 &p4; \
253 P5 &p5; \
254 } ZFUniqueName(zfscopeCleanup_)(p0 \
255 , p1 \
256 , p2 \
257 , p3 \
258 , p4 \
259 , p5 \
260 )
262#define zfscopeCleanup_7(action \
263 , P0, p0 \
264 , P1, p1 \
265 , P2, p2 \
266 , P3, p3 \
267 , P4, p4 \
268 , P5, p5 \
269 , P6, p6 \
270 ) \
271 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
272 public: \
273 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
274 , P1 &p1 \
275 , P2 &p2 \
276 , P3 &p3 \
277 , P4 &p4 \
278 , P5 &p5 \
279 , P6 &p6 \
280 ) \
281 : p0(p0) \
282 , p1(p1) \
283 , p2(p2) \
284 , p3(p3) \
285 , p4(p4) \
286 , p5(p5) \
287 , p6(p6) \
288 {} \
289 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
290 action \
291 } \
292 private: \
293 P0 &p0; \
294 P1 &p1; \
295 P2 &p2; \
296 P3 &p3; \
297 P4 &p4; \
298 P5 &p5; \
299 P6 &p6; \
300 } ZFUniqueName(zfscopeCleanup_)(p0 \
301 , p1 \
302 , p2 \
303 , p3 \
304 , p4 \
305 , p5 \
306 , p6 \
307 )
309#define zfscopeCleanup_8(action \
310 , P0, p0 \
311 , P1, p1 \
312 , P2, p2 \
313 , P3, p3 \
314 , P4, p4 \
315 , P5, p5 \
316 , P6, p6 \
317 , P7, p7 \
318 ) \
319 zfclassLikePOD ZFUniqueName(zfscopeCleanup_T) { \
320 public: \
321 ZFUniqueName(zfscopeCleanup_T)(P0 &p0 \
322 , P1 &p1 \
323 , P2 &p2 \
324 , P3 &p3 \
325 , P4 &p4 \
326 , P5 &p5 \
327 , P6 &p6 \
328 , P7 &p7 \
329 ) \
330 : p0(p0) \
331 , p1(p1) \
332 , p2(p2) \
333 , p3(p3) \
334 , p4(p4) \
335 , p5(p5) \
336 , p6(p6) \
337 , p7(p7) \
338 {} \
339 ~ZFUniqueName(zfscopeCleanup_T)(void) { \
340 action \
341 } \
342 private: \
343 P0 &p0; \
344 P1 &p1; \
345 P2 &p2; \
346 P3 &p3; \
347 P4 &p4; \
348 P5 &p5; \
349 P6 &p6; \
350 P7 &p7; \
351 } ZFUniqueName(zfscopeCleanup_)(p0 \
352 , p1 \
353 , p2 \
354 , p3 \
355 , p4 \
356 , p5 \
357 , p6 \
358 , p7 \
359 )
360
362
363#endif // #ifndef _ZFI_ZFCoreUtilAutoPtr_h_
364
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
types for ZFFramework
#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 zfdelete(instance)
same as delete defined for future use
Definition ZFCoreTypeDef_ClassType.h:91
#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 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