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

based on Chipmunk cpArray. More...

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

Namespaces

 cocos2d
 Add deprecated global functions and variables here.
 

Constant Groups

 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 *  (ssize_t capacity)
 Allocates and initializes a new array with specified capacity. More...
 
var  ( var capacity)
 Allocates and initializes a new array with specified capacity. More...
 
local  ( local capacity)
 Allocates and initializes a new array with specified capacity. More...
 
void  (ccArray *&arr)
 Frees array after removing all remaining objects. More...
 
var  ( var arr)
 Frees array after removing all remaining objects. More...
 
local  ( local arr)
 Frees array after removing all remaining objects. More...
 
void  (ccArray *arr)
 Doubles array capacity. More...
 
void  (ccArray *arr, ssize_t extra)
 Increases array capacity such that max >= num + extra. More...
 
var  ( var arr, var extra)
 Increases array capacity such that max >= num + extra. More...
 
local  ( local arr, local extra)
 Increases array capacity such that max >= num + extra. More...
 
void  (ccArray *arr)
 shrinks the array so the memory footprint corresponds with the number of items More...
 
ssize_t  (ccArray *arr, Ref *object)
 Returns index of first occurrence of object, NSNotFound if object not found. More...
 
var  ( var arr, var object)
 Returns index of first occurrence of object, NSNotFound if object not found. More...
 
local  ( local arr, local object)
 Returns index of first occurrence of object, NSNotFound if object not found. More...
 
bool  (ccArray *arr, Ref *object)
 Returns a Boolean value that indicates whether object is present in array. More...
 
local  ( local arr, local object)
 Returns a Boolean value that indicates whether object is present in array. More...
 
void  (ccArray *arr, Ref *object)
 Appends an object. More...
 
var  ( var arr, var object)
 Appends an object. More...
 
local  ( local arr, local object)
 Appends an object. More...
 
void  (ccArray *arr, Ref *object)
 Appends an object. More...
 
void  (ccArray *arr, ccArray *plusArr)
 Appends objects from plusArr to arr. More...
 
var  ( var arr, var plusArr)
 Appends objects from plusArr to arr. More...
 
local  ( local arr, local plusArr)
 Appends objects from plusArr to arr. More...
 
void  (ccArray *arr, ccArray *plusArr)
 Appends objects from plusArr to arr. More...
 
var  ( var arr, var plusArr)
 Appends objects from plusArr to arr. More...
 
local  ( local arr, local plusArr)
 Appends objects from plusArr to arr. More...
 
void  (ccArray *arr, Ref *object, ssize_t index)
 Inserts an object at index. More...
 
var  ( var arr, var object, var index)
 Inserts an object at index. More...
 
local  ( local arr, local object, local index)
 Inserts an object at index. More...
 
void  (ccArray *arr, ssize_t index1, ssize_t index2)
 Swaps two objects. More...
 
var  ( var arr, var index1, var index2)
 Swaps two objects. More...
 
local  ( local arr, local index1, local index2)
 Swaps two objects. More...
 
void  (ccArray *arr)
 Removes all objects from arr. More...
 
void  (ccArray *arr, ssize_t index, bool releaseObj=true)
 Removes object at specified index and pushes back all subsequent objects. More...
 
var  ( var arr, var index, var true)
 Removes object at specified index and pushes back all subsequent objects. More...
 
local  ( local arr, local index, local true)
 Removes object at specified index and pushes back all subsequent objects. More...
 
void  (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  (ccArray *arr, Ref *object)
void  (ccArray *arr, Ref *object, bool releaseObj=true)
 Searches for the first occurrence of object and removes it. More...
 
var  ( var arr, var object, var true)
 Searches for the first occurrence of object and removes it. More...
 
local  ( local arr, local object, local true)
 Searches for the first occurrence of object and removes it. More...
 
void  (ccArray *arr, ccArray *minusArr)
 Removes from arr all objects in minusArr. More...
 
void  (ccArray *arr, ccArray *minusArr)
 Removes from arr all objects in minusArr. More...
 
ccCArray *  (ssize_t capacity)
 Allocates and initializes a new C array with specified capacity. More...
 
void  (ccCArray *arr)
 Frees C array after removing all remaining values. More...
 
var  ( var arr)
 Frees C array after removing all remaining values. More...
 
local  ( local arr)
 Frees C array after removing all remaining values. More...
 
void  (ccCArray *arr)
 Doubles C array capacity. More...
 
void  (ccCArray *arr, ssize_t extra)
 Increases array capacity such that max >= num + extra. More...
 
var  ( var arr, var extra)
 Increases array capacity such that max >= num + extra. More...
 
local  ( local arr, local extra)
 Increases array capacity such that max >= num + extra. More...
 
ssize_t  (ccCArray *arr, void *value)
 Returns index of first occurrence of value, NSNotFound if value not found. More...
 
bool  (ccCArray *arr, void *value)
 Returns a Boolean value that indicates whether value is present in the C array. More...
 
void  (ccCArray *arr, void *value, ssize_t index)
 Inserts a value at a certain position. More...
 
var  ( var arr, var value, var index)
 Inserts a value at a certain position. More...
 
local  ( local arr, local value, local index)
 Inserts a value at a certain position. More...
 
void  (ccCArray *arr, void *value)
 Appends an value. More...
 
var  ( var arr, var value)
 Appends an value. More...
 
local  ( local arr, local value)
 Appends an value. More...
 
void  (ccCArray *arr, void *value)
 Appends an value. More...
 
var  ( var arr, var value)
 Appends an value. More...
 
local  ( local arr, local value)
 Appends an value. More...
 
void  (ccCArray *arr, ccCArray *plusArr)
 Appends values from plusArr to arr. More...
 
void  (ccCArray *arr, ccCArray *plusArr)
 Appends values from plusArr to arr. More...
 
var  ( var arr, var plusArr)
 Appends values from plusArr to arr. More...
 
local  ( local arr, local plusArr)
 Appends values from plusArr to arr. More...
 
void  (ccCArray *arr)
 Removes all values from arr. More...
 
var  ( var arr)
 Removes all values from arr. More...
 
local  ( local arr)
 Removes all values from arr. More...
 
void  (ccCArray *arr, ssize_t index)
 Removes value at specified index and pushes back all subsequent values. More...
 
var  ( var arr, var index)
 Removes value at specified index and pushes back all subsequent values. More...
 
local  ( local arr, local index)
 Removes value at specified index and pushes back all subsequent values. More...
 
void  (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  (ccCArray *arr, void *value)
 Searches for the first occurrence of value and removes it. More...
 
void  (ccCArray *arr, ccCArray *minusArr)
 Removes from arr all values in minusArr. More...
 
var  ( var arr, var minusArr)
 Removes from arr all values in minusArr. More...
 
local  ( local arr, local minusArr)
 Removes from arr all values in minusArr. More...
 
void  (ccCArray *arr, ccCArray *minusArr)
 Removes from arr all values in minusArr. More...
 
var  ( var arr, var minusArr)
 Removes from arr all values in minusArr. More...
 
local  ( local arr, local 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]) \
var CCARRAYDATA_FOREACH (   var,
  var 
)    __object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
local CCARRAYDATA_FOREACH (   local,
  local 
)    __object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \