mirror of https://github.com/axmolengine/axmol.git
API compliant with cocos2d-x best practices
Uses `int` instead of `unsigned int` as described in the cocos2d-x best practices Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
parent
b3b3583583
commit
62c578667b
|
@ -46,7 +46,7 @@ Array* Array::create()
|
|||
{
|
||||
Array* array = new Array();
|
||||
|
||||
if (array && array->init())
|
||||
if (array && array->initWithCapacity(7))
|
||||
{
|
||||
array->autorelease();
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ Array* Array::createWithArray(Array* otherArray)
|
|||
return otherArray->clone();
|
||||
}
|
||||
|
||||
Array* Array::createWithCapacity(unsigned int capacity)
|
||||
Array* Array::createWithCapacity(int capacity)
|
||||
{
|
||||
Array* array = new Array();
|
||||
|
||||
|
@ -138,12 +138,12 @@ Array* Array::createWithContentsOfFileThreadSafe(const char* fileName)
|
|||
|
||||
bool Array::init()
|
||||
{
|
||||
return initWithCapacity(10);
|
||||
return initWithCapacity(7);
|
||||
}
|
||||
|
||||
bool Array::initWithObject(Object* object)
|
||||
{
|
||||
bool ret = initWithCapacity(1);
|
||||
bool ret = initWithCapacity(7);
|
||||
if (ret)
|
||||
{
|
||||
addObject(object);
|
||||
|
@ -180,7 +180,7 @@ bool Array::initWithObjects(Object* object, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Array::initWithCapacity(unsigned int capacity)
|
||||
bool Array::initWithCapacity(int capacity)
|
||||
{
|
||||
data.reserve(capacity);
|
||||
return true;
|
||||
|
@ -234,7 +234,7 @@ bool Array::containsObject(Object* object) const
|
|||
|
||||
bool Array::isEqualToArray(Array* otherArray)
|
||||
{
|
||||
for (unsigned int i = 0; i< this->count(); i++)
|
||||
for (int i = 0; i< this->count(); i++)
|
||||
{
|
||||
if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i)))
|
||||
{
|
||||
|
@ -272,18 +272,10 @@ void Array::removeLastObject(bool releaseObj)
|
|||
|
||||
void Array::removeObject(Object* object, bool releaseObj /* ignored */)
|
||||
{
|
||||
auto it = data.begin();
|
||||
for (; it != data.end(); ++it)
|
||||
{
|
||||
if (it->get() == object)
|
||||
{
|
||||
data.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
data.erase( std::remove( data.begin(), data.end(), object ) );
|
||||
}
|
||||
|
||||
void Array::removeObjectAtIndex(unsigned int index, bool releaseObj /* ignored */)
|
||||
void Array::removeObjectAtIndex(int index, bool releaseObj /* ignored */)
|
||||
{
|
||||
auto obj = data[index];
|
||||
data.erase( data.begin() + index );
|
||||
|
@ -299,7 +291,7 @@ void Array::removeAllObjects()
|
|||
data.erase(std::begin(data), std::end(data));
|
||||
}
|
||||
|
||||
void Array::fastRemoveObjectAtIndex(unsigned int index)
|
||||
void Array::fastRemoveObjectAtIndex(int index)
|
||||
{
|
||||
removeObjectAtIndex(index);
|
||||
}
|
||||
|
@ -319,12 +311,12 @@ void Array::exchangeObject(Object* object1, Object* object2)
|
|||
std::swap( data[idx1], data[idx2] );
|
||||
}
|
||||
|
||||
void Array::exchangeObjectAtIndex(unsigned int index1, unsigned int index2)
|
||||
void Array::exchangeObjectAtIndex(int index1, int index2)
|
||||
{
|
||||
std::swap( data[index1], data[index2] );
|
||||
}
|
||||
|
||||
void Array::replaceObjectAtIndex(unsigned int index, Object* object, bool releaseObject /* ignored */)
|
||||
void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject /* ignored */)
|
||||
{
|
||||
data[index] = object;
|
||||
}
|
||||
|
@ -393,7 +385,7 @@ Array* Array::create()
|
|||
{
|
||||
Array* array = new Array();
|
||||
|
||||
if (array && array->init())
|
||||
if (array && array->initWithCapacity(7))
|
||||
{
|
||||
array->autorelease();
|
||||
}
|
||||
|
@ -452,7 +444,7 @@ Array* Array::createWithArray(Array* otherArray)
|
|||
return otherArray->clone();
|
||||
}
|
||||
|
||||
Array* Array::createWithCapacity(unsigned int capacity)
|
||||
Array* Array::createWithCapacity(int capacity)
|
||||
{
|
||||
Array* array = new Array();
|
||||
|
||||
|
@ -487,14 +479,14 @@ bool Array::init()
|
|||
{
|
||||
CCASSERT(!data, "Array cannot be re-initialized");
|
||||
|
||||
return initWithCapacity(1);
|
||||
return initWithCapacity(7);
|
||||
}
|
||||
|
||||
bool Array::initWithObject(Object* object)
|
||||
{
|
||||
CCASSERT(!data, "Array cannot be re-initialized");
|
||||
|
||||
bool ret = initWithCapacity(1);
|
||||
bool ret = initWithCapacity(7);
|
||||
if (ret)
|
||||
{
|
||||
addObject(object);
|
||||
|
@ -533,7 +525,7 @@ bool Array::initWithObjects(Object* object, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Array::initWithCapacity(unsigned int capacity)
|
||||
bool Array::initWithCapacity(int capacity)
|
||||
{
|
||||
CCASSERT(!data, "Array cannot be re-initialized");
|
||||
|
||||
|
@ -586,7 +578,7 @@ bool Array::containsObject(Object* object) const
|
|||
|
||||
bool Array::isEqualToArray(Array* otherArray)
|
||||
{
|
||||
for (unsigned int i = 0; i< this->count(); i++)
|
||||
for (int i = 0; i< this->count(); i++)
|
||||
{
|
||||
if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i)))
|
||||
{
|
||||
|
@ -637,7 +629,7 @@ void Array::removeObject(Object* object, bool releaseObj/* = true*/)
|
|||
ccArrayRemoveObject(data, object, releaseObj);
|
||||
}
|
||||
|
||||
void Array::removeObjectAtIndex(unsigned int index, bool releaseObj)
|
||||
void Array::removeObjectAtIndex(int index, bool releaseObj)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(data, index, releaseObj);
|
||||
}
|
||||
|
@ -652,7 +644,7 @@ void Array::removeAllObjects()
|
|||
ccArrayRemoveAllObjects(data);
|
||||
}
|
||||
|
||||
void Array::fastRemoveObjectAtIndex(unsigned int index)
|
||||
void Array::fastRemoveObjectAtIndex(int index)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(data, index);
|
||||
}
|
||||
|
@ -664,13 +656,13 @@ void Array::fastRemoveObject(Object* object)
|
|||
|
||||
void Array::exchangeObject(Object* object1, Object* object2)
|
||||
{
|
||||
unsigned int index1 = ccArrayGetIndexOfObject(data, object1);
|
||||
int index1 = ccArrayGetIndexOfObject(data, object1);
|
||||
if (index1 == UINT_MAX)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int index2 = ccArrayGetIndexOfObject(data, object2);
|
||||
int index2 = ccArrayGetIndexOfObject(data, object2);
|
||||
if (index2 == UINT_MAX)
|
||||
{
|
||||
return;
|
||||
|
@ -679,12 +671,12 @@ void Array::exchangeObject(Object* object1, Object* object2)
|
|||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
void Array::exchangeObjectAtIndex(unsigned int index1, unsigned int index2)
|
||||
void Array::exchangeObjectAtIndex(int index1, int index2)
|
||||
{
|
||||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
void Array::replaceObjectAtIndex(unsigned int index, Object* object, bool releaseObject/* = true*/)
|
||||
void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/)
|
||||
{
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
ccArrayRemoveObjectAtIndex(data, index+1);
|
||||
|
@ -696,7 +688,7 @@ void Array::reverseObjects()
|
|||
{
|
||||
// floorf(), since in the case of an even number, the number of swaps stays the same
|
||||
int count = (int) floorf(data->num/2.f);
|
||||
unsigned int maxIndex = data->num - 1;
|
||||
int maxIndex = data->num - 1;
|
||||
|
||||
for (int i = 0; i < count ; i++)
|
||||
{
|
||||
|
|
|
@ -241,7 +241,7 @@ public:
|
|||
/** Create an array with one object */
|
||||
static Array* createWithObject(Object* object);
|
||||
/** Create an array with a default capacity */
|
||||
static Array* createWithCapacity(unsigned int capacity);
|
||||
static Array* createWithCapacity(int capacity);
|
||||
/** Create an array with from an existing array */
|
||||
static Array* createWithArray(Array* otherArray);
|
||||
/**
|
||||
|
@ -266,14 +266,14 @@ public:
|
|||
/** Initializes an array with some objects */
|
||||
bool initWithObjects(Object* object, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
/** Initializes an array with capacity */
|
||||
bool initWithCapacity(unsigned int capacity);
|
||||
bool initWithCapacity(int capacity);
|
||||
/** Initializes an array with an existing array */
|
||||
bool initWithArray(Array* otherArray);
|
||||
|
||||
// Querying an Array
|
||||
|
||||
/** Returns element count of the array */
|
||||
unsigned int count() const
|
||||
int count() const
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
return data.size();
|
||||
|
@ -282,7 +282,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
/** Returns capacity of the array */
|
||||
unsigned int capacity() const
|
||||
int capacity() const
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
return data.capacity();
|
||||
|
@ -363,7 +363,7 @@ public:
|
|||
/** Remove a certain object */
|
||||
void removeObject(Object* object, bool releaseObj = true);
|
||||
/** Remove an element with a certain index */
|
||||
void removeObjectAtIndex(unsigned int index, bool releaseObj = true);
|
||||
void removeObjectAtIndex(int index, bool releaseObj = true);
|
||||
/** Remove all elements */
|
||||
void removeObjectsInArray(Array* otherArray);
|
||||
/** Remove all objects */
|
||||
|
@ -371,17 +371,17 @@ public:
|
|||
/** Fast way to remove a certain object */
|
||||
void fastRemoveObject(Object* object);
|
||||
/** Fast way to remove an element with a certain index */
|
||||
void fastRemoveObjectAtIndex(unsigned int index);
|
||||
void fastRemoveObjectAtIndex(int index);
|
||||
|
||||
// Rearranging Content
|
||||
|
||||
/** Swap two elements */
|
||||
void exchangeObject(Object* object1, Object* object2);
|
||||
/** Swap two elements with certain indexes */
|
||||
void exchangeObjectAtIndex(unsigned int index1, unsigned int index2);
|
||||
void exchangeObjectAtIndex(int index1, int index2);
|
||||
|
||||
/** Replace object at index with another object. */
|
||||
void replaceObjectAtIndex(unsigned int index, Object* object, bool releaseObject = true);
|
||||
void replaceObjectAtIndex(int index, Object* object, bool releaseObject = true);
|
||||
|
||||
/** Revers the array */
|
||||
void reverseObjects();
|
||||
|
|
|
@ -654,17 +654,17 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
// Cleanup sprite. It might be reused (issue #569)
|
||||
sprite->setBatchNode(NULL);
|
||||
|
||||
unsigned int uIndex = _descendants->getIndexOfObject(sprite);
|
||||
if (uIndex != UINT_MAX)
|
||||
int index = _descendants->getIndexOfObject(sprite);
|
||||
if (index != UINT_MAX)
|
||||
{
|
||||
_descendants->removeObjectAtIndex(uIndex);
|
||||
_descendants->removeObjectAtIndex(index);
|
||||
|
||||
// update all sprites beyond this one
|
||||
unsigned int count = _descendants->count();
|
||||
int count = _descendants->count();
|
||||
|
||||
for(; uIndex < count; ++uIndex)
|
||||
for(; index < count; ++index)
|
||||
{
|
||||
Sprite* s = (Sprite*)(_descendants->getObjectAtIndex(uIndex));
|
||||
Sprite* s = static_cast<Sprite*>(_descendants->getObjectAtIndex(index));
|
||||
s->setAtlasIndex( s->getAtlasIndex() - 1 );
|
||||
}
|
||||
}
|
||||
|
@ -673,10 +673,10 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
Array *children = sprite->getChildren();
|
||||
if (children && children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(children, pObject)
|
||||
Object* object = NULL;
|
||||
CCARRAY_FOREACH(children, object)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(pObject);
|
||||
Sprite* child = static_cast<Sprite*>(object);
|
||||
if (child)
|
||||
{
|
||||
removeSpriteFromAtlas(child);
|
||||
|
|
|
@ -28,11 +28,13 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int CC_INVALID_INDEX = -1;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
ccArray* ccArrayNew(unsigned int capacity)
|
||||
ccArray* ccArrayNew(int capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
capacity = 1;
|
||||
capacity = 7;
|
||||
|
||||
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
|
||||
arr->num = 0;
|
||||
|
@ -66,17 +68,21 @@ void ccArrayDoubleCapacity(ccArray *arr)
|
|||
arr->arr = newArr;
|
||||
}
|
||||
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra)
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
|
||||
{
|
||||
while (arr->max < arr->num + extra)
|
||||
{
|
||||
// CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%lu] to [%lu].",
|
||||
// (long) arr->max,
|
||||
// (long) arr->max*2);
|
||||
|
||||
ccArrayDoubleCapacity(arr);
|
||||
}
|
||||
}
|
||||
|
||||
void ccArrayShrink(ccArray *arr)
|
||||
{
|
||||
unsigned int newSize = 0;
|
||||
int newSize = 0;
|
||||
|
||||
//only resize when necessary
|
||||
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
||||
|
@ -98,13 +104,14 @@ void ccArrayShrink(ccArray *arr)
|
|||
}
|
||||
|
||||
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
|
||||
unsigned int ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||
int ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||
{
|
||||
const unsigned int arrNum = arr->num;
|
||||
const int arrNum = arr->num;
|
||||
Object** ptr = arr->arr;
|
||||
for(unsigned int i = 0; i < arrNum; ++i, ++ptr)
|
||||
for(int i = 0; i < arrNum; ++i, ++ptr)
|
||||
{
|
||||
if( *ptr == object ) return i;
|
||||
if( *ptr == object )
|
||||
return i;
|
||||
}
|
||||
|
||||
return CC_INVALID_INDEX;
|
||||
|
@ -136,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
|
|||
enough capacity. */
|
||||
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
||||
{
|
||||
for(unsigned int i = 0; i < plusArr->num; i++)
|
||||
for(int i = 0; i < plusArr->num; i++)
|
||||
{
|
||||
ccArrayAppendObject(arr, plusArr->arr[i]);
|
||||
}
|
||||
|
@ -150,14 +157,14 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
|||
}
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, unsigned int index)
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index)
|
||||
{
|
||||
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
|
||||
CCASSERT(object != NULL, "Invalid parameter!");
|
||||
|
||||
ccArrayEnsureExtraCapacity(arr, 1);
|
||||
|
||||
unsigned int remaining = arr->num - index;
|
||||
int remaining = arr->num - index;
|
||||
if( remaining > 0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
|
||||
|
@ -169,10 +176,10 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, unsigned int index
|
|||
}
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, unsigned int index1, unsigned int index2)
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2)
|
||||
{
|
||||
CCASSERT(index1 < arr->num, "(1) Invalid index. Out of bounds");
|
||||
CCASSERT(index2 < arr->num, "(2) Invalid index. Out of bounds");
|
||||
CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds");
|
||||
CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds");
|
||||
|
||||
Object* object1 = arr->arr[index1];
|
||||
|
||||
|
@ -191,9 +198,9 @@ void ccArrayRemoveAllObjects(ccArray *arr)
|
|||
|
||||
/** Removes object at specified index and pushes back all subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj/* = true*/)
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
CCASSERT(arr && arr->num > 0 && index < arr->num, "Invalid index. Out of bounds");
|
||||
CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds");
|
||||
if (bReleaseObj)
|
||||
{
|
||||
CC_SAFE_RELEASE(arr->arr[index]);
|
||||
|
@ -201,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseO
|
|||
|
||||
arr->num--;
|
||||
|
||||
unsigned int remaining = arr->num - index;
|
||||
int remaining = arr->num - index;
|
||||
if(remaining>0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
|
||||
|
@ -211,16 +218,16 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseO
|
|||
/** Removes object at specified index and fills the gap with the last object,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int index)
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index)
|
||||
{
|
||||
CC_SAFE_RELEASE(arr->arr[index]);
|
||||
unsigned int last = --arr->num;
|
||||
int last = --arr->num;
|
||||
arr->arr[index] = arr->arr[last];
|
||||
}
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
||||
{
|
||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||
int index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||
|
@ -231,7 +238,7 @@ void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
|||
found the function has no effect. */
|
||||
void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||
int index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj);
|
||||
|
@ -242,7 +249,7 @@ void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true
|
|||
first matching instance in arr will be removed. */
|
||||
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||
{
|
||||
for(unsigned int i = 0; i < minusArr->num; i++)
|
||||
for(int i = 0; i < minusArr->num; i++)
|
||||
{
|
||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
||||
}
|
||||
|
@ -252,8 +259,8 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
matching instances in arr will be removed. */
|
||||
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||
{
|
||||
unsigned int back = 0;
|
||||
unsigned int i = 0;
|
||||
int back = 0;
|
||||
int i = 0;
|
||||
|
||||
for( i = 0; i < arr->num; i++)
|
||||
{
|
||||
|
@ -275,11 +282,11 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
/** Allocates and initializes a new C array with specified capacity */
|
||||
ccCArray* ccCArrayNew(unsigned int capacity)
|
||||
ccCArray* ccCArrayNew(int capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
{
|
||||
capacity = 1;
|
||||
capacity = 7;
|
||||
}
|
||||
|
||||
ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) );
|
||||
|
@ -310,19 +317,18 @@ void ccCArrayDoubleCapacity(ccCArray *arr)
|
|||
}
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra)
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra)
|
||||
{
|
||||
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
||||
}
|
||||
|
||||
/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */
|
||||
unsigned int ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
||||
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for( i = 0; i < arr->num; i++)
|
||||
for( int i = 0; i < arr->num; i++)
|
||||
{
|
||||
if( arr->arr[i] == value ) return i;
|
||||
if( arr->arr[i] == value )
|
||||
return i;
|
||||
}
|
||||
return CC_INVALID_INDEX;
|
||||
}
|
||||
|
@ -334,11 +340,11 @@ bool ccCArrayContainsValue(ccCArray *arr, void* value)
|
|||
}
|
||||
|
||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index)
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index)
|
||||
{
|
||||
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
||||
|
||||
unsigned int remaining = arr->num - index;
|
||||
int remaining = arr->num - index;
|
||||
// make sure it has enough capacity
|
||||
if (arr->num + 1 == arr->max)
|
||||
{
|
||||
|
@ -379,9 +385,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value)
|
|||
enough capacity. */
|
||||
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for( i = 0; i < plusArr->num; i++)
|
||||
for( int i = 0; i < plusArr->num; i++)
|
||||
{
|
||||
ccCArrayAppendValue(arr, plusArr->arr[i]);
|
||||
}
|
||||
|
@ -404,11 +408,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index)
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
|
||||
{
|
||||
unsigned int last;
|
||||
|
||||
for( last = --arr->num; index < last; index++)
|
||||
for( int last = --arr->num; index < last; index++)
|
||||
{
|
||||
arr->arr[index] = arr->arr[index + 1];
|
||||
}
|
||||
|
@ -419,9 +421,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index)
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index)
|
||||
{
|
||||
unsigned int last = --arr->num;
|
||||
int last = --arr->num;
|
||||
arr->arr[index] = arr->arr[last];
|
||||
}
|
||||
|
||||
|
@ -430,7 +432,7 @@ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index)
|
|||
*/
|
||||
void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
||||
{
|
||||
unsigned int index = ccCArrayGetIndexOfValue(arr, value);
|
||||
int index = ccCArrayGetIndexOfValue(arr, value);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
ccCArrayRemoveValueAtIndex(arr, index);
|
||||
|
@ -442,7 +444,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
|||
*/
|
||||
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||
{
|
||||
for(unsigned int i = 0; i < minusArr->num; i++)
|
||||
for(int i = 0; i < minusArr->num; i++)
|
||||
{
|
||||
ccCArrayRemoveValue(arr, minusArr->arr[i]);
|
||||
}
|
||||
|
@ -453,9 +455,9 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
|||
*/
|
||||
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||
{
|
||||
unsigned int back = 0;
|
||||
int back = 0;
|
||||
|
||||
for(unsigned int i = 0; i < arr->num; i++)
|
||||
for(int i = 0; i < arr->num; i++)
|
||||
{
|
||||
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
|
||||
{
|
||||
|
|
|
@ -51,20 +51,20 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define CC_INVALID_INDEX 0xffffffff
|
||||
extern const int CC_INVALID_INDEX;
|
||||
|
||||
// Easy integration
|
||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||
__object__=__array__->arr[0]; for(unsigned int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
||||
__object__=__array__->arr[0]; for(int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
||||
|
||||
|
||||
typedef struct _ccArray {
|
||||
unsigned int num, max;
|
||||
int num, max;
|
||||
Object** arr;
|
||||
} ccArray;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
ccArray* ccArrayNew(unsigned int capacity);
|
||||
ccArray* ccArrayNew(int capacity);
|
||||
|
||||
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
|
||||
void ccArrayFree(ccArray*& arr);
|
||||
|
@ -73,13 +73,13 @@ void ccArrayFree(ccArray*& arr);
|
|||
void ccArrayDoubleCapacity(ccArray *arr);
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra);
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra);
|
||||
|
||||
/** shrinks the array so the memory footprint corresponds with the number of items */
|
||||
void ccArrayShrink(ccArray *arr);
|
||||
|
||||
/** Returns index of first occurrence of object, NSNotFound if object not found. */
|
||||
unsigned int ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||
int ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
||||
|
@ -98,22 +98,22 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
|
|||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, unsigned int index);
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index);
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, unsigned int index1, unsigned int index2);
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2);
|
||||
|
||||
/** Removes all objects from arr */
|
||||
void ccArrayRemoveAllObjects(ccArray *arr);
|
||||
|
||||
/** Removes object at specified index and pushes back all subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj = true);
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj = true);
|
||||
|
||||
/** Removes object at specified index and fills the gap with the last object,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int index);
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index);
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object);
|
||||
|
||||
|
@ -133,12 +133,12 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
typedef struct _ccCArray {
|
||||
unsigned int num, max;
|
||||
int num, max;
|
||||
void** arr;
|
||||
} ccCArray;
|
||||
|
||||
/** Allocates and initializes a new C array with specified capacity */
|
||||
ccCArray* ccCArrayNew(unsigned int capacity);
|
||||
ccCArray* ccCArrayNew(int capacity);
|
||||
|
||||
/** Frees C array after removing all remaining values. Silently ignores nil arr. */
|
||||
void ccCArrayFree(ccCArray *arr);
|
||||
|
@ -147,16 +147,16 @@ void ccCArrayFree(ccCArray *arr);
|
|||
void ccCArrayDoubleCapacity(ccCArray *arr);
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra);
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra);
|
||||
|
||||
/** Returns index of first occurrence of value, NSNotFound if value not found. */
|
||||
unsigned int ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
||||
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
||||
|
||||
/** Returns a Boolean value that indicates whether value is present in the C array. */
|
||||
bool ccCArrayContainsValue(ccCArray *arr, void* value);
|
||||
|
||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index);
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index);
|
||||
|
||||
/** Appends an value. Behavior undefined if array doesn't have enough capacity. */
|
||||
void ccCArrayAppendValue(ccCArray *arr, void* value);
|
||||
|
@ -178,14 +178,14 @@ void ccCArrayRemoveAllValues(ccCArray *arr);
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index);
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index);
|
||||
|
||||
/** Removes value at specified index and fills the gap with the last value,
|
||||
thereby avoiding the need to push back subsequent values.
|
||||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index);
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index);
|
||||
|
||||
/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect.
|
||||
@since v0.99.4
|
||||
|
|
Loading…
Reference in New Issue