ZFFramework
Loading...
Searching...
No Matches
ZFAutoReleasePool.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFAutoReleasePool_h_
7#define _ZFI_ZFAutoReleasePool_h_
8
9#include "ZFObject.h"
11
18zfclass ZFLIB_ZFCore ZFAutoReleasePool : zfextend ZFObject {
19 ZFOBJECT_DECLARE(ZFAutoReleasePool, ZFObject)
20
21
30
31protected:
33 virtual void objectOnDeallocPrepare(void);
34
37
38public:
42 void poolAdd(ZF_IN ZFObject *obj) {
43 if(obj != zfnull) {
45 ZFCoreAssertWithMessage(obj != this, "add autorelease pool to itself isn't allowed");
46 d.add(obj);
47 }
48 }
49
54 void poolDrain() {
55 if(!d.isEmpty()) {
58 tmp.swap(d);
60
61 for(zfindex i = 0; i < tmp.count(); ++i) {
62 zfobjRelease(tmp[i]);
63 }
64 }
65 }
66
71 void poolDrain(ZF_IN zfindex count) {
72 if(d.count() > count) {
75 tmp.addFrom(d.arrayBuf(), d.count() - count);
76 d.remove(0, d.count() - count);
78
79 for(zfindex i = 0; i < tmp.count(); ++i) {
80 zfobjRelease(tmp[i]);
81 }
82 }
83 }
84
88 return d.count();
89 }
90
91private:
93};
94
96#endif // #ifndef _ZFI_ZFAutoReleasePool_h_
97
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZFCoreAssertWithMessage(exp, fmt,...)
ZFCoreAssert with custom message
Definition ZFCoreLog_CommonLog.h:70
#define ZFCoreMutexLocker()
util method to lock current block
Definition ZFCoreMutex.h:95
#define ZFCoreMutexUnlock()
see ZFCoreMutexLock
Definition ZFCoreMutex.h:58
#define ZFCoreMutexLock()
internal use only
Definition ZFCoreMutex.h:51
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:198
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:214
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
ZFObject related include.
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:122
#define ZFOBJECT_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
util macro to declare a singleton instance access for ZFObject type
Definition ZFObjectGlobalInstance.h:243
#define zfobjRelease(obj)
release an object, see ZFObject
Definition ZFObjectRetain.h:145
void poolDrain(zfindex count)
manually drain a pool, all object in the pool would be released immediately
Definition ZFAutoReleasePool.h:71
void poolDrain()
manually drain a pool, all object in the pool would be released immediately
Definition ZFAutoReleasePool.h:54
void poolAdd(ZFObject *obj)
add an object which would be auto released upon pool's drain or delete
Definition ZFAutoReleasePool.h:42
zfindex poolCount(void)
current object count
Definition ZFAutoReleasePool.h:87
static ZFAutoReleasePool * instance()
global memory pool, you should drain it manually and you take full responsibility to keep it safe to ...
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
light weight array
Definition ZFCoreArray.h:297
void swap(ZFCoreArray< T_Element > &ref)
swap internal data
Definition ZFCoreArray.h:381
void addFrom(const T_Element *src, zfindex count)
add elements, src can be part of this array's buffer
Definition ZFCoreArray.h:556
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:903