mirror of https://github.com/axmolengine/axmol.git
Merge pull request #832 from dumganhar/gles20
fixed #1136: Fixed some bugs as follows: 1. Using std::string parameter as the key of CCDictionary 2. Deep copy for CCDictionary and CCArray, the classes of elements's type must implement copyWithZone. 3. Added toBool() function to CCString. 4. Retina support for all platforms. 5. Include "CCString.h" and "cocoa/CCNS.h" in cocos2d.h. 6. Added a new constructor(CCArray::CCArray(unsigned int capacity)) for CCArray. And fixed a bug in CCArray. 7. Fixed a memory leak in CCLabelBMFont.cpp. 8. Fixed an error in strings.xml.
This commit is contained in:
commit
429e0bcb46
|
@ -2,6 +2,8 @@
|
|||
#include "CCString.h"
|
||||
#include "CCInteger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCDictionary::CCDictionary()
|
||||
|
@ -86,14 +88,14 @@ CCArray* CCDictionary::allKeysForObject(CCObject* object)
|
|||
return pArray;
|
||||
}
|
||||
|
||||
CCObject* CCDictionary::objectForKey(const char* key)
|
||||
CCObject* CCDictionary::objectForKey(const string& key)
|
||||
{
|
||||
if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL;
|
||||
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as key.");
|
||||
|
||||
CCObject* pRetObject = NULL;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements,key, pElement);
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements,key.c_str(), pElement);
|
||||
if (pElement != NULL)
|
||||
{
|
||||
pRetObject = pElement->m_pObject;
|
||||
|
@ -107,7 +109,7 @@ CCObject* CCDictionary::objectForKey(int key)
|
|||
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as key.");
|
||||
|
||||
CCObject* pRetObject = NULL;
|
||||
CCDictElement *pElement = NULL;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||
if (pElement != NULL)
|
||||
{
|
||||
|
@ -116,9 +118,9 @@ CCObject* CCDictionary::objectForKey(int key)
|
|||
return pRetObject;
|
||||
}
|
||||
|
||||
bool CCDictionary::setObject(CCObject* pObject, const char* key)
|
||||
bool CCDictionary::setObject(CCObject* pObject, const string& key)
|
||||
{
|
||||
CCAssert(key != NULL && strlen(key) > 0 && pObject != NULL, "Invalid Argument!");
|
||||
CCAssert(key.length() > 0 && pObject != NULL, "Invalid Argument!");
|
||||
if (m_eOldDictType == kCCDictUnknown)
|
||||
{
|
||||
m_eOldDictType = kCCDictStr;
|
||||
|
@ -127,14 +129,14 @@ bool CCDictionary::setObject(CCObject* pObject, const char* key)
|
|||
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use string as key.");
|
||||
|
||||
bool bRet = false;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements, key, pElement);
|
||||
if (pElement == NULL)
|
||||
{
|
||||
pObject->retain();
|
||||
pElement = new CCDictElement(key, pObject);
|
||||
HASH_ADD_STR(m_pElements, m_szKey, pElement);
|
||||
bRet = true;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements, key.c_str(), pElement);
|
||||
if (pElement == NULL)
|
||||
{
|
||||
pObject->retain();
|
||||
pElement = new CCDictElement(key.c_str(), pObject);
|
||||
HASH_ADD_STR(m_pElements, m_szKey, pElement);
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -159,14 +161,14 @@ bool CCDictionary::setObject(CCObject* pObject, int key)
|
|||
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use integer as key.");
|
||||
|
||||
bool bRet = false;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||
if (pElement == NULL)
|
||||
{
|
||||
pObject->retain();
|
||||
pElement = new CCDictElement(key, pObject);
|
||||
HASH_ADD_INT(m_pElements, m_iKey, pElement);
|
||||
bRet = true;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||
if (pElement == NULL)
|
||||
{
|
||||
pObject->retain();
|
||||
pElement = new CCDictElement(key, pObject);
|
||||
HASH_ADD_INT(m_pElements, m_iKey, pElement);
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -180,12 +182,12 @@ bool CCDictionary::setObject(CCObject* pObject, int key)
|
|||
return bRet;
|
||||
}
|
||||
|
||||
void CCDictionary::removeObjectForKey(const char* key)
|
||||
void CCDictionary::removeObjectForKey(const string& key)
|
||||
{
|
||||
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as its key");
|
||||
CCAssert(key != NULL && strlen(key) > 0, "Invalid Argument!");
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements, key, pElement);
|
||||
CCAssert(key.length() > 0, "Invalid Argument!");
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_STR(m_pElements, key.c_str(), pElement);
|
||||
if (pElement)
|
||||
{
|
||||
HASH_DEL(m_pElements, pElement);
|
||||
|
@ -197,7 +199,7 @@ void CCDictionary::removeObjectForKey(const char* key)
|
|||
void CCDictionary::removeObjectForKey(int key)
|
||||
{
|
||||
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as its key");
|
||||
CCDictElement *pElement = NULL;
|
||||
CCDictElement *pElement = NULL;
|
||||
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||
if (pElement != NULL)
|
||||
{
|
||||
|
@ -228,14 +230,14 @@ CCObject* CCDictionary::copyWithZone(CCZone* pZone)
|
|||
{
|
||||
CCDICT_FOREACH(this, pElement)
|
||||
{
|
||||
pNewDict->setObject(pElement->getObject()->copy(), pElement->getIntKey());
|
||||
pNewDict->setObject(pElement->getObject()->copy()->autorelease(), pElement->getIntKey());
|
||||
}
|
||||
}
|
||||
else if (m_eDictType == kCCDictStr)
|
||||
{
|
||||
CCDICT_FOREACH(this, pElement)
|
||||
{
|
||||
pNewDict->setObject(pElement->getObject()->copy(), pElement->getStrKey());
|
||||
pNewDict->setObject(pElement->getObject()->copy()->autorelease(), pElement->getStrKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,26 +27,26 @@ THE SOFTWARE.
|
|||
|
||||
#include "support/data_support/ccCArray.h"
|
||||
|
||||
/** @def CCARRAY_FOREACH
|
||||
A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
|
||||
@since v0.99.4
|
||||
*/
|
||||
|
||||
/*
|
||||
In cocos2d-iphone 1.0.0, This macro have been update to like this:
|
||||
|
||||
/** @def CCARRAY_FOREACH
|
||||
A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
|
||||
@since v0.99.4
|
||||
*/
|
||||
|
||||
/*
|
||||
In cocos2d-iphone 1.0.0, This macro have been update to like this:
|
||||
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if (__array__ && __array__->data->num > 0) \
|
||||
for(id *__arr__ = __array__->data->arr, *end = __array__->data->arr + __array__->data->num-1; \
|
||||
__arr__ <= end && ((__object__ = *__arr__) != nil || true); \
|
||||
__arr__++)
|
||||
|
||||
I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
|
||||
*/
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||
arr <= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||
__arr__++)
|
||||
|
||||
I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
|
||||
*/
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||
arr <= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||
arr++)
|
||||
|
||||
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||
|
@ -58,7 +58,7 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
|||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||
do { \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(CCObject** arr = (__array__)->data->arr, \
|
||||
**end = (__array__)->data->arr + (__array__)->data->num-1; arr <= end; arr++) \
|
||||
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
|
||||
|
@ -75,69 +75,69 @@ class CC_DLL CCArray : public CCObject
|
|||
public:
|
||||
~CCArray();
|
||||
/** Create an array */
|
||||
static CCArray* array();
|
||||
/** Create an array with one object */
|
||||
static CCArray* arrayWithObject(CCObject* pObject);
|
||||
/** Create an array with some objects */
|
||||
static CCArray* arrayWithObjects(CCObject* pObject, ...);
|
||||
/** Create an array with capacity */
|
||||
static CCArray* arrayWithCapacity(unsigned int capacity);
|
||||
/** Create an array with an existing array */
|
||||
static CCArray* array();
|
||||
/** Create an array with one object */
|
||||
static CCArray* arrayWithObject(CCObject* pObject);
|
||||
/** Create an array with some objects */
|
||||
static CCArray* arrayWithObjects(CCObject* pObject, ...);
|
||||
/** Create an array with capacity */
|
||||
static CCArray* arrayWithCapacity(unsigned int capacity);
|
||||
/** Create an array with an existing array */
|
||||
static CCArray* arrayWithArray(CCArray* otherArray);
|
||||
|
||||
/** Initializes an array */
|
||||
bool init();
|
||||
/** Initializes an array with one object */
|
||||
bool initWithObject(CCObject* pObject);
|
||||
/** Initializes an array with some objects */
|
||||
/** Initializes an array with some objects */
|
||||
bool initWithObjects(CCObject* pObject, ...);
|
||||
/** Initializes an array with capacity */
|
||||
bool initWithCapacity(unsigned int capacity);
|
||||
/** Initializes an array with an existing array */
|
||||
bool initWithCapacity(unsigned int capacity);
|
||||
/** Initializes an array with an existing array */
|
||||
bool initWithArray(CCArray* otherArray);
|
||||
|
||||
// Querying an Array
|
||||
|
||||
/** Returns element count of the array */
|
||||
unsigned int count();
|
||||
/** Returns capacity of the array */
|
||||
unsigned int capacity();
|
||||
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
|
||||
unsigned int indexOfObject(CCObject* object);
|
||||
/** Returns an element with a certain index */
|
||||
CCObject* objectAtIndex(unsigned int index);
|
||||
/** Returns last element */
|
||||
CCObject* lastObject();
|
||||
/** Returns a random element */
|
||||
CCObject* randomObject();
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
unsigned int count();
|
||||
/** Returns capacity of the array */
|
||||
unsigned int capacity();
|
||||
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
|
||||
unsigned int indexOfObject(CCObject* object);
|
||||
/** Returns an element with a certain index */
|
||||
CCObject* objectAtIndex(unsigned int index);
|
||||
/** Returns last element */
|
||||
CCObject* lastObject();
|
||||
/** Returns a random element */
|
||||
CCObject* randomObject();
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
bool containsObject(CCObject* object);
|
||||
|
||||
// Adding Objects
|
||||
|
||||
/** Add a certain object */
|
||||
void addObject(CCObject* object);
|
||||
/** Add all elements of an existing array */
|
||||
void addObjectsFromArray(CCArray* otherArray);
|
||||
/** Insert a certain object at a certain index */
|
||||
void insertObject(CCObject* object, unsigned int index);
|
||||
|
||||
// Removing Objects
|
||||
|
||||
/** Remove last object */
|
||||
void removeLastObject(bool bReleaseObj = true);
|
||||
/** Remove a certain object */
|
||||
void removeObject(CCObject* object, bool bReleaseObj = true);
|
||||
/** Remove an element with a certain index */
|
||||
void removeObjectAtIndex(unsigned int index, bool bReleaseObj = true);
|
||||
/** Remove all elements */
|
||||
void removeObjectsInArray(CCArray* otherArray);
|
||||
/** Remove all objects */
|
||||
void removeAllObjects();
|
||||
/** Fast way to remove a certain object */
|
||||
void fastRemoveObject(CCObject* object);
|
||||
/** Fast way to remove an element with a certain index */
|
||||
void fastRemoveObjectAtIndex(unsigned int index);
|
||||
void addObject(CCObject* object);
|
||||
/** Add all elements of an existing array */
|
||||
void addObjectsFromArray(CCArray* otherArray);
|
||||
/** Insert a certain object at a certain index */
|
||||
void insertObject(CCObject* object, unsigned int index);
|
||||
|
||||
// Removing Objects
|
||||
|
||||
/** Remove last object */
|
||||
void removeLastObject(bool bReleaseObj = true);
|
||||
/** Remove a certain object */
|
||||
void removeObject(CCObject* object, bool bReleaseObj = true);
|
||||
/** Remove an element with a certain index */
|
||||
void removeObjectAtIndex(unsigned int index, bool bReleaseObj = true);
|
||||
/** Remove all elements */
|
||||
void removeObjectsInArray(CCArray* otherArray);
|
||||
/** Remove all objects */
|
||||
void removeAllObjects();
|
||||
/** Fast way to remove a certain object */
|
||||
void fastRemoveObject(CCObject* object);
|
||||
/** Fast way to remove an element with a certain index */
|
||||
void fastRemoveObjectAtIndex(unsigned int index);
|
||||
|
||||
// Rearranging Content
|
||||
|
||||
|
@ -152,11 +152,11 @@ public:
|
|||
|
||||
void replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject = true);
|
||||
|
||||
/** TODO: deep copy array. */
|
||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||
public:
|
||||
ccArray* data;
|
||||
CCArray() : data(NULL) {};
|
||||
CCArray();
|
||||
CCArray(unsigned int capacity);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
#include "support/data_support/uthash.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCArray.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -106,13 +107,13 @@ public:
|
|||
/** @warning : We use '==' to compare two objects*/
|
||||
CCArray* allKeysForObject(CCObject* object);
|
||||
|
||||
CCObject* objectForKey(const char* key);
|
||||
CCObject* objectForKey(const std::string& key);
|
||||
CCObject* objectForKey(int key);
|
||||
|
||||
bool setObject(CCObject* pObject, const char* key);
|
||||
bool setObject(CCObject* pObject, const std::string& key);
|
||||
bool setObject(CCObject* pObject, int key);
|
||||
|
||||
void removeObjectForKey(const char* key);
|
||||
void removeObjectForKey(const std::string& key);
|
||||
void removeObjectForKey(int key);
|
||||
|
||||
void removeAllObjects();
|
||||
|
|
|
@ -65,6 +65,15 @@ public:
|
|||
return (float)atof(m_sString.c_str());
|
||||
}
|
||||
|
||||
bool toBool()
|
||||
{
|
||||
if (0 == strcmp(m_sString.c_str(), "0") || 0 == strcmp(m_sString.c_str(), "false"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string toStdString()
|
||||
{
|
||||
return m_sString;
|
||||
|
|
|
@ -110,8 +110,6 @@ On Mac it returns 1;
|
|||
On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
|
||||
*/
|
||||
#define CC_CONTENT_SCALE_FACTOR() CCDirector::sharedDirector()->getContentScaleFactor()
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
/****************************/
|
||||
/** RETINA DISPLAY ENABLED **/
|
||||
|
@ -154,23 +152,6 @@ CCSizeMake( (__size_in_pixels__).width / CC_CONTENT_SCALE_FACTOR(), (__size_in_p
|
|||
*/
|
||||
#define CC_SIZE_POINTS_TO_PIXELS(__size_in_points__) \
|
||||
CCSizeMake( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_points__).height * CC_CONTENT_SCALE_FACTOR())
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/*****************************/
|
||||
/** RETINA DISPLAY DISABLED **/
|
||||
/*****************************/
|
||||
|
||||
#define CC_RECT_PIXELS_TO_POINTS(__pixels__) __pixels__
|
||||
#define CC_RECT_POINTS_TO_PIXELS(__points__) __points__
|
||||
#define CC_SIZE_PIXELS_TO_POINTS(__pixels__) __pixels__
|
||||
#define CC_SIZE_POINTS_TO_PIXELS(__points__) __points__
|
||||
#define CC_POINT_PIXELS_TO_POINTS(__pixels__) __pixels__
|
||||
#define CC_POINT_POINTS_TO_PIXELS(__points__) __points__
|
||||
|
||||
|
||||
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
|
|
|
@ -107,7 +107,8 @@ THE SOFTWARE.
|
|||
#include "CCAffineTransform.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
||||
#include "CCString.h"
|
||||
#include "cocoa/CCNS.h"
|
||||
//
|
||||
// platform specific
|
||||
//
|
||||
|
|
|
@ -42,6 +42,9 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
|||
#include "support/data_support/uthash.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
typedef struct _FontDefHashElement
|
||||
|
@ -788,6 +791,7 @@ bool CCLabelBMFont::initWithString(const char *theString, const char *fntFile, f
|
|||
m_pAlignment = alignment;
|
||||
m_tImageOffset = imageOffset;
|
||||
m_fWidth = width;
|
||||
CC_SAFE_DELETE_ARRAY(m_sString);
|
||||
m_sString = cc_utf8_from_cstr(theString);
|
||||
m_cOpacity = 255;
|
||||
m_tColor = ccWHITE;
|
||||
|
@ -804,6 +808,7 @@ CCLabelBMFont::CCLabelBMFont()
|
|||
: m_cOpacity(0)
|
||||
, m_bIsOpacityModifyRGB(false)
|
||||
, m_pConfiguration(NULL)
|
||||
, m_sString(NULL)
|
||||
, m_bLineBreakWithoutSpaces(false)
|
||||
, m_tImageOffset(CCPointZero)
|
||||
{
|
||||
|
@ -953,11 +958,12 @@ void CCLabelBMFont::setString(const char *newString, bool fromUpdate)
|
|||
{
|
||||
if (fromUpdate)
|
||||
{
|
||||
CC_SAFE_DELETE_ARRAY(m_sString);
|
||||
m_sString = cc_utf8_from_cstr(newString);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sString_initial = std::string(newString);
|
||||
m_sString_initial = newString;
|
||||
}
|
||||
|
||||
updateString(fromUpdate);
|
||||
|
@ -1078,8 +1084,6 @@ void CCLabelBMFont::setAnchorPoint(const CCPoint& point)
|
|||
// LabelBMFont - Alignment
|
||||
void CCLabelBMFont::updateLabel()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
this->setString(m_sString_initial.c_str(), true);
|
||||
|
||||
if (m_fWidth > 0)
|
||||
|
@ -1240,7 +1244,7 @@ void CCLabelBMFont::updateLabel()
|
|||
|
||||
str_new[size] = 0;
|
||||
|
||||
delete[] m_sString;
|
||||
CC_SAFE_DELETE_ARRAY(m_sString);
|
||||
m_sString = str_new;
|
||||
updateString(true);
|
||||
}
|
||||
|
|
|
@ -425,7 +425,8 @@ namespace cocos2d {
|
|||
|
||||
CCDictionary *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||
{
|
||||
NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
||||
const char* pszFullPath = fullPathFromRelativePath(pFileName);
|
||||
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
|
||||
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
||||
|
||||
CCDictionary* pRet = new CCDictionary();
|
||||
|
|
|
@ -27,10 +27,23 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCArray* CCArray::array()
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
|
||||
CCArray::CCArray()
|
||||
: data(NULL)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
CCArray::CCArray(unsigned int capacity)
|
||||
: data(NULL)
|
||||
{
|
||||
initWithCapacity(capacity);
|
||||
}
|
||||
|
||||
CCArray* CCArray::array()
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
if (pArray && pArray->init())
|
||||
{
|
||||
pArray->autorelease();
|
||||
|
@ -39,14 +52,14 @@ CCArray* CCArray::array()
|
|||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithObject(CCObject* pObject)
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithObject(CCObject* pObject)
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
if (pArray && pArray->initWithObject(pObject))
|
||||
{
|
||||
pArray->autorelease();
|
||||
|
@ -55,40 +68,40 @@ CCArray* CCArray::arrayWithObject(CCObject* pObject)
|
|||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithObjects(CCObject* pObject, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,pObject);
|
||||
|
||||
CCArray* pArray = array();
|
||||
if (pArray && pObject)
|
||||
{
|
||||
pArray->addObject(pObject);
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithObjects(CCObject* pObject, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,pObject);
|
||||
|
||||
CCArray* pArray = array();
|
||||
if (pArray && pObject)
|
||||
{
|
||||
pArray->addObject(pObject);
|
||||
CCObject *i = va_arg(args, CCObject*);
|
||||
while(i)
|
||||
{
|
||||
pArray->addObject(i);
|
||||
i = va_arg(args, CCObject*);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithCapacity(unsigned int capacity)
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithCapacity(unsigned int capacity)
|
||||
{
|
||||
CCArray* pArray = new CCArray();
|
||||
|
||||
if (pArray && pArray->initWithCapacity(capacity))
|
||||
{
|
||||
pArray->autorelease();
|
||||
|
@ -97,75 +110,79 @@ CCArray* CCArray::arrayWithCapacity(unsigned int capacity)
|
|||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithArray(CCArray* otherArray)
|
||||
{
|
||||
|
||||
return pArray;
|
||||
}
|
||||
|
||||
CCArray* CCArray::arrayWithArray(CCArray* otherArray)
|
||||
{
|
||||
CCArray* pArray = (CCArray*)otherArray->copyWithZone(NULL);
|
||||
pArray->autorelease();
|
||||
return pArray;
|
||||
}
|
||||
|
||||
bool CCArray::init()
|
||||
{
|
||||
return initWithCapacity(1);
|
||||
}
|
||||
|
||||
bool CCArray::initWithObject(CCObject* pObject)
|
||||
{
|
||||
bool bRet = initWithCapacity(1);
|
||||
if (bRet)
|
||||
{
|
||||
addObject(pObject);
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
/** Initializes an array with some objects */
|
||||
bool CCArray::initWithObjects(CCObject* pObject, ...)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(pObject != NULL);
|
||||
|
||||
va_list args;
|
||||
va_start(args, pObject);
|
||||
|
||||
CCArray* pArray = new CCArray();
|
||||
if (pArray && pObject)
|
||||
{
|
||||
pArray->addObject(pObject);
|
||||
pArray->autorelease();
|
||||
return pArray;
|
||||
}
|
||||
|
||||
bool CCArray::init()
|
||||
{
|
||||
return initWithCapacity(1);
|
||||
}
|
||||
|
||||
bool CCArray::initWithObject(CCObject* pObject)
|
||||
{
|
||||
ccArrayFree(data);
|
||||
bool bRet = initWithCapacity(1);
|
||||
if (bRet)
|
||||
{
|
||||
addObject(pObject);
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
/** Initializes an array with some objects */
|
||||
bool CCArray::initWithObjects(CCObject* pObject, ...)
|
||||
{
|
||||
ccArrayFree(data);
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(pObject != NULL);
|
||||
|
||||
va_list args;
|
||||
va_start(args, pObject);
|
||||
|
||||
CCArray* pArray = new CCArray();
|
||||
if (pArray && pObject)
|
||||
{
|
||||
pArray->addObject(pObject);
|
||||
CCObject* i = va_arg(args, CCObject*);
|
||||
while(i)
|
||||
{
|
||||
pArray->addObject(i);
|
||||
i = va_arg(args, CCObject*);
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
} while (false);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCArray::initWithCapacity(unsigned int capacity)
|
||||
{
|
||||
data = ccArrayNew(capacity);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCArray::initWithArray(CCArray* otherArray)
|
||||
{
|
||||
bool bRet = false;
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pArray);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
} while (false);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCArray::initWithCapacity(unsigned int capacity)
|
||||
{
|
||||
ccArrayFree(data);
|
||||
data = ccArrayNew(capacity);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCArray::initWithArray(CCArray* otherArray)
|
||||
{
|
||||
ccArrayFree(data);
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! initWithCapacity(otherArray->data->num));
|
||||
|
@ -173,103 +190,103 @@ bool CCArray::initWithArray(CCArray* otherArray)
|
|||
addObjectsFromArray(otherArray);
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
unsigned int CCArray::count()
|
||||
{
|
||||
return data->num;
|
||||
}
|
||||
|
||||
unsigned int CCArray::capacity()
|
||||
{
|
||||
return data->max;
|
||||
}
|
||||
|
||||
unsigned int CCArray::indexOfObject(CCObject* object)
|
||||
{
|
||||
return ccArrayGetIndexOfObject(data, object);
|
||||
}
|
||||
|
||||
CCObject* CCArray::objectAtIndex(unsigned int index)
|
||||
{
|
||||
CCAssert(index < data->num, "index out of range in objectAtIndex()");
|
||||
|
||||
return data->arr[index];
|
||||
}
|
||||
|
||||
CCObject* CCArray::lastObject()
|
||||
{
|
||||
if( data->num > 0 )
|
||||
return data->arr[data->num-1];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CCObject* CCArray::randomObject()
|
||||
{
|
||||
if(data->num==0) return NULL;
|
||||
|
||||
return data->arr[(int)(data->num*CCRANDOM_0_1())];
|
||||
}
|
||||
|
||||
bool CCArray::containsObject(CCObject* object)
|
||||
{
|
||||
return ccArrayContainsObject(data, object);
|
||||
}
|
||||
|
||||
void CCArray::addObject(CCObject* object)
|
||||
{
|
||||
ccArrayAppendObjectWithResize(data, object);
|
||||
}
|
||||
|
||||
void CCArray::addObjectsFromArray(CCArray* otherArray)
|
||||
{
|
||||
ccArrayAppendArrayWithResize(data, otherArray->data);
|
||||
}
|
||||
|
||||
void CCArray::insertObject(CCObject* object, unsigned int index)
|
||||
{
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
}
|
||||
|
||||
void CCArray::removeLastObject(bool bReleaseObj)
|
||||
{
|
||||
CCAssert(data->num, "no objects added");
|
||||
ccArrayRemoveObjectAtIndex(data, data->num-1, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObject(CCObject* object, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
ccArrayRemoveObject(data, object, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObjectAtIndex(unsigned int index, bool bReleaseObj)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(data, index, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
||||
{
|
||||
ccArrayRemoveArray(data, otherArray->data);
|
||||
}
|
||||
|
||||
void CCArray::removeAllObjects()
|
||||
{
|
||||
ccArrayRemoveAllObjects(data);
|
||||
}
|
||||
|
||||
void CCArray::fastRemoveObjectAtIndex(unsigned int index)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(data, index);
|
||||
}
|
||||
|
||||
void CCArray::fastRemoveObject(CCObject* object)
|
||||
{
|
||||
ccArrayFastRemoveObject(data, object);
|
||||
}
|
||||
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
unsigned int CCArray::count()
|
||||
{
|
||||
return data->num;
|
||||
}
|
||||
|
||||
unsigned int CCArray::capacity()
|
||||
{
|
||||
return data->max;
|
||||
}
|
||||
|
||||
unsigned int CCArray::indexOfObject(CCObject* object)
|
||||
{
|
||||
return ccArrayGetIndexOfObject(data, object);
|
||||
}
|
||||
|
||||
CCObject* CCArray::objectAtIndex(unsigned int index)
|
||||
{
|
||||
CCAssert(index < data->num, "index out of range in objectAtIndex()");
|
||||
|
||||
return data->arr[index];
|
||||
}
|
||||
|
||||
CCObject* CCArray::lastObject()
|
||||
{
|
||||
if( data->num > 0 )
|
||||
return data->arr[data->num-1];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CCObject* CCArray::randomObject()
|
||||
{
|
||||
if(data->num==0) return NULL;
|
||||
|
||||
return data->arr[(int)(data->num*CCRANDOM_0_1())];
|
||||
}
|
||||
|
||||
bool CCArray::containsObject(CCObject* object)
|
||||
{
|
||||
return ccArrayContainsObject(data, object);
|
||||
}
|
||||
|
||||
void CCArray::addObject(CCObject* object)
|
||||
{
|
||||
ccArrayAppendObjectWithResize(data, object);
|
||||
}
|
||||
|
||||
void CCArray::addObjectsFromArray(CCArray* otherArray)
|
||||
{
|
||||
ccArrayAppendArrayWithResize(data, otherArray->data);
|
||||
}
|
||||
|
||||
void CCArray::insertObject(CCObject* object, unsigned int index)
|
||||
{
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
}
|
||||
|
||||
void CCArray::removeLastObject(bool bReleaseObj)
|
||||
{
|
||||
CCAssert(data->num, "no objects added");
|
||||
ccArrayRemoveObjectAtIndex(data, data->num-1, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObject(CCObject* object, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
ccArrayRemoveObject(data, object, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObjectAtIndex(unsigned int index, bool bReleaseObj)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(data, index, bReleaseObj);
|
||||
}
|
||||
|
||||
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
||||
{
|
||||
ccArrayRemoveArray(data, otherArray->data);
|
||||
}
|
||||
|
||||
void CCArray::removeAllObjects()
|
||||
{
|
||||
ccArrayRemoveAllObjects(data);
|
||||
}
|
||||
|
||||
void CCArray::fastRemoveObjectAtIndex(unsigned int index)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(data, index);
|
||||
}
|
||||
|
||||
void CCArray::fastRemoveObject(CCObject* object)
|
||||
{
|
||||
ccArrayFastRemoveObject(data, object);
|
||||
}
|
||||
|
||||
void CCArray::exchangeObject(CCObject* object1, CCObject* object2)
|
||||
{
|
||||
unsigned int index1 = ccArrayGetIndexOfObject(data, object1);
|
||||
|
@ -290,8 +307,8 @@ void CCArray::exchangeObject(CCObject* object1, CCObject* object2)
|
|||
void CCArray::exchangeObjectAtIndex(unsigned int index1, unsigned int index2)
|
||||
{
|
||||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CCArray::reverseObjects()
|
||||
{
|
||||
if (data->num > 1)
|
||||
|
@ -311,12 +328,12 @@ void CCArray::reverseObjects()
|
|||
void CCArray::reduceMemoryFootprint()
|
||||
{
|
||||
ccArrayShrink(data);
|
||||
}
|
||||
|
||||
CCArray::~CCArray()
|
||||
{
|
||||
ccArrayFree(data);
|
||||
}
|
||||
}
|
||||
|
||||
CCArray::~CCArray()
|
||||
{
|
||||
ccArrayFree(data);
|
||||
}
|
||||
|
||||
void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject/* = true*/)
|
||||
{
|
||||
|
@ -337,13 +354,13 @@ void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool
|
|||
CCObject* CCArray::copyWithZone(CCZone* pZone)
|
||||
{
|
||||
CCAssert(pZone == NULL, "CCArray should not be inherited.");
|
||||
CCArray* pArray = new CCArray();
|
||||
pArray->initWithCapacity(this->data->num > 0 ? this->data->num : 1);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(this, pObj)
|
||||
{
|
||||
pArray->addObject(pObj->copy());
|
||||
CCArray* pArray = new CCArray();
|
||||
pArray->initWithCapacity(this->data->num > 0 ? this->data->num : 1);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(this, pObj)
|
||||
{
|
||||
pArray->addObject(pObj->copy()->autorelease());
|
||||
}
|
||||
return pArray;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ static inline ccArray* ccArrayNew(unsigned int capacity)
|
|||
static inline void ccArrayRemoveAllObjects(ccArray *arr);
|
||||
|
||||
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
|
||||
static inline void ccArrayFree(ccArray *arr)
|
||||
static inline void ccArrayFree(ccArray*& arr)
|
||||
{
|
||||
if( arr == NULL )
|
||||
{
|
||||
|
@ -88,6 +88,7 @@ static inline void ccArrayFree(ccArray *arr)
|
|||
|
||||
free(arr->arr);
|
||||
free(arr);
|
||||
arr = NULL;
|
||||
}
|
||||
|
||||
/** Doubles array capacity */
|
||||
|
|
|
@ -8,4 +8,5 @@
|
|||
<string>良い一日を</string>
|
||||
<key>spanish</key>
|
||||
<string>Buen día</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
Loading…
Reference in New Issue