cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ccCArray.h File Reference

based on Chipmunk cpArray. More...

#include "base/ccMacros.h"
#include "base/CCRef.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>

Namespaces

 cocos2d
 Add deprecated global functions and variables here.
 

Macros

#define CCARRAYDATA_FOREACH(__array__, __object__)   __object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
 

Functions

ccArray * ccArrayNew (ssize_t capacity)
 Allocates and initializes a new array with specified capacity. More...
 
void ccArrayFree (ccArray *&arr)
 Frees array after removing all remaining objects. More...
 
void ccArrayDoubleCapacity (ccArray *arr)
 Doubles array capacity. More...
 
void ccArrayEnsureExtraCapacity (ccArray *arr, ssize_t extra)
 Increases array capacity such that max >= num + extra. More...
 
void ccArrayShrink (ccArray *arr)
 shrinks the array so the memory footprint corresponds with the number of items More...
 
ssize_t ccArrayGetIndexOfObject (ccArray *arr, Ref *object)
 Returns index of first occurrence of object, NSNotFound if object not found. More...
 
bool ccArrayContainsObject (ccArray *arr, Ref *object)
 Returns a Boolean value that indicates whether object is present in array. More...
 
void ccArrayAppendObject (ccArray *arr, Ref *object)
 Appends an object. More...
 
void ccArrayAppendObjectWithResize (ccArray *arr, Ref *object)
 Appends an object. More...
 
void ccArrayAppendArray (ccArray *arr, ccArray *plusArr)
 Appends objects from plusArr to arr. More...
 
void ccArrayAppendArrayWithResize (ccArray *arr, ccArray *plusArr)
 Appends objects from plusArr to arr. More...
 
void ccArrayInsertObjectAtIndex (ccArray *arr, Ref *object, ssize_t index)
 Inserts an object at index. More...
 
void ccArraySwapObjectsAtIndexes (ccArray *arr, ssize_t index1, ssize_t index2)
 Swaps two objects. More...
 
void ccArrayRemoveAllObjects (ccArray *arr)
 Removes all objects from arr. More...
 
void ccArrayRemoveObjectAtIndex (ccArray *arr, ssize_t index, bool releaseObj=true)
 Removes object at specified index and pushes back all subsequent objects. More...
 
void ccArrayFastRemoveObjectAtIndex (ccArray *arr, ssize_t index)
 Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. More...
 
void ccArrayFastRemoveObject (ccArray *arr, Ref *object)
 
void ccArrayRemoveObject (ccArray *arr, Ref *object, bool releaseObj=true)
 Searches for the first occurrence of object and removes it. More...
 
void ccArrayRemoveArray (ccArray *arr, ccArray *minusArr)
 Removes from arr all objects in minusArr. More...
 
void ccArrayFullRemoveArray (ccArray *arr, ccArray *minusArr)
 Removes from arr all objects in minusArr. More...
 
ccCArray * ccCArrayNew (ssize_t capacity)
 Allocates and initializes a new C array with specified capacity. More...
 
void ccCArrayFree (ccCArray *arr)
 Frees C array after removing all remaining values. More...
 
void ccCArrayDoubleCapacity (ccCArray *arr)
 Doubles C array capacity. More...
 
void ccCArrayEnsureExtraCapacity (ccCArray *arr, ssize_t extra)
 Increases array capacity such that max >= num + extra. More...
 
ssize_t ccCArrayGetIndexOfValue (ccCArray *arr, void *value)
 Returns index of first occurrence of value, NSNotFound if value not found. More...
 
bool ccCArrayContainsValue (ccCArray *arr, void *value)
 Returns a Boolean value that indicates whether value is present in the C array. More...
 
void ccCArrayInsertValueAtIndex (ccCArray *arr, void *value, ssize_t index)
 Inserts a value at a certain position. More...
 
void ccCArrayAppendValue (ccCArray *arr, void *value)
 Appends an value. More...
 
void ccCArrayAppendValueWithResize (ccCArray *arr, void *value)
 Appends an value. More...
 
void ccCArrayAppendArray (ccCArray *arr, ccCArray *plusArr)
 Appends values from plusArr to arr. More...
 
void ccCArrayAppendArrayWithResize (ccCArray *arr, ccCArray *plusArr)
 Appends values from plusArr to arr. More...
 
void ccCArrayRemoveAllValues (ccCArray *arr)
 Removes all values from arr. More...
 
void ccCArrayRemoveValueAtIndex (ccCArray *arr, ssize_t index)
 Removes value at specified index and pushes back all subsequent values. More...
 
void ccCArrayFastRemoveValueAtIndex (ccCArray *arr, ssize_t index)
 Removes value at specified index and fills the gap with the last value, thereby avoiding the need to push back subsequent values. More...
 
void ccCArrayRemoveValue (ccCArray *arr, void *value)
 Searches for the first occurrence of value and removes it. More...
 
void ccCArrayRemoveArray (ccCArray *arr, ccCArray *minusArr)
 Removes from arr all values in minusArr. More...
 
void ccCArrayFullRemoveArray (ccCArray *arr, ccCArray *minusArr)
 Removes from arr all values in minusArr. More...
 

Detailed Description

based on Chipmunk cpArray.

ccArray is a faster alternative to NSMutableArray, it does pretty much the same thing (stores NSObjects and retains/releases them appropriately). It's faster because:

  • it uses a plain C interface so it doesn't incur Objective-c messaging overhead
  • it assumes you know what you're doing, so it doesn't spend time on safety checks (index out of bounds, required capacity etc.)
  • comparisons are done using pointer equality instead of isEqual

There are 2 kind of functions:

  • ccArray functions that manipulates objective-c objects (retain and release are performed)
  • ccCArray functions that manipulates values like if they were standard C structures (no retain/release is performed)

Macro Definition Documentation

#define CCARRAYDATA_FOREACH (   __array__,
  __object__ 
)    __object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \