diff --git a/cocos2dx/cocoa/NSAutoreleasePool.h b/cocos2dx/cocoa/NSAutoreleasePool.h new file mode 100644 index 0000000000..3f4526ecc6 --- /dev/null +++ b/cocos2dx/cocoa/NSAutoreleasePool.h @@ -0,0 +1,65 @@ +/**************************************************************************** +Copyright (c) 2010 cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __NS_AUTO_RELEASE_POOL_H__ +#define __NS_AUTO_RELEASE_POOL_H__ + +#include "NSObject.h" +#include + +class NSAutoreleasePool : public NSObject +{ +public: + NSAutoreleasePool(void); + + void addObject(NSObject *pObject); + void removeObject(NSObject *pObject); + + void clear(void); +private: + std::vector m_managedObjectArray; +}; + +class NSPoolManager +{ +public: + + ~NSPoolManager(); + + void finalize(void); + void push(void); + void pop(void); + + void removeObject(NSObject *pObject); + void addObject(NSObject *pObject); + +public: + static NSPoolManager* getInstance(); + +private: + NSPoolManager(); + +private: + static NSPoolManager *m_pPoolManager; +} + +#endif //__NS_AUTO_RELEASE_POOL_H__ diff --git a/cocos2dx/cocoa/NSMutableArray.cpp b/cocos2dx/cocoa/NSMutableArray.cpp new file mode 100644 index 0000000000..4f94a8f69e --- /dev/null +++ b/cocos2dx/cocoa/NSMutableArray.cpp @@ -0,0 +1,21 @@ +/**************************************************************************** +Copyright (c) 2010 cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ \ No newline at end of file diff --git a/cocos2dx/cocoa/NSMutableArray.h b/cocos2dx/cocoa/NSMutableArray.h new file mode 100644 index 0000000000..e1ebb26615 --- /dev/null +++ b/cocos2dx/cocoa/NSMutableArray.h @@ -0,0 +1,29 @@ +/**************************************************************************** +Copyright (c) 2010 cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __COCOA_NS_MUTATLE_ARRAY_H__ +#define __COCOA_NS_MUTATLE_ARRAY_H__ + +#include "NSObject.h" +#include + +#endif // __COCOA_NS_MUTATLE_ARRAY_H__ diff --git a/cocos2dx/cocoa/NSObject.cpp b/cocos2dx/cocoa/NSObject.cpp index 91109f0896..750e2d4a25 100644 --- a/cocos2dx/cocoa/NSObject.cpp +++ b/cocos2dx/cocoa/NSObject.cpp @@ -33,8 +33,67 @@ NSObject* CCCopying::copyWithZone(NSZone *pZone) NSObject::NSObject(void) { + static UINT uObjectCount = 0; + + m_uID = ++uObjectCount; + + // when the object is created, the refrence count of it is 1 + m_uRefrence = 1; + m_bManaged = FALSE; } NSObject::~NSObject(void) { + // if the object is managed, we should remove it + // from pool manager + if (m_bManaged) + { + // todo: remove from pool manager + } +} + +NSObject* NSObject::copy() +{ + return copyWithZone(NULL); +} + +void NSObject::release(void) +{ + assert(m_uRefrence > 0); + --m_uRefrence; + + if (m_uRefrence == 0) + { + delete this; + } +} + +void NSObject::retain(void) +{ + assert(m_uRefrence > 0); + + ++m_uRefrence; +} + +NSObject* NSObject::autorelease(void) +{ + // todo add to pool manager + + m_bManaged = TRUE; + return this; +} + +BOOL NSObject::isSingleRefrence(void) +{ + return m_uRefrence == 1; +} + +UINT32 NSObject::retainCount(void) +{ + return m_uRefrence; +} + +BOOL NSObject::isEqual(const NSObject *pObject) +{ + return this == pObject; }