cocos2d-iphone  2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
ccCArray.h File Reference
#import <Foundation/Foundation.h>
#import <stdlib.h>
#import <string.h>
#import "../ccMacros.h"
+ Include dependency graph for ccCArray.h:

Classes

struct  ccArray

Defines

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

Typedefs

typedef id CCARRAY_ID
typedef int(* cc_comparator )(const void *, const void *)
typedef ccArray ccCArray

Functions

ccArrayccArrayNew (NSUInteger capacity)
void ccArrayFree (ccArray *arr)
void ccArrayDoubleCapacity (ccArray *arr)
void ccArrayEnsureExtraCapacity (ccArray *arr, NSUInteger extra)
void ccArrayShrink (ccArray *arr)
NSUInteger ccArrayGetIndexOfObject (ccArray *arr, id object)
BOOL ccArrayContainsObject (ccArray *arr, id object)
void ccArrayAppendObject (ccArray *arr, id object)
void ccArrayAppendObjectWithResize (ccArray *arr, id object)
void ccArrayAppendArray (ccArray *arr, ccArray *plusArr)
void ccArrayAppendArrayWithResize (ccArray *arr, ccArray *plusArr)
void ccArrayInsertObjectAtIndex (ccArray *arr, id object, NSUInteger index)
void ccArraySwapObjectsAtIndexes (ccArray *arr, NSUInteger index1, NSUInteger index2)
void ccArrayRemoveAllObjects (ccArray *arr)
void ccArrayRemoveObjectAtIndex (ccArray *arr, NSUInteger index)
void ccArrayFastRemoveObjectAtIndex (ccArray *arr, NSUInteger index)
void ccArrayFastRemoveObject (ccArray *arr, id object)
void ccArrayRemoveObject (ccArray *arr, id object)
void ccArrayRemoveArray (ccArray *arr, ccArray *minusArr)
void ccArrayFullRemoveArray (ccArray *arr, ccArray *minusArr)
void ccArrayMakeObjectsPerformSelector (ccArray *arr, SEL sel)
void ccArrayMakeObjectsPerformSelectorWithObject (ccArray *arr, SEL sel, id object)
void ccArrayMakeObjectPerformSelectorWithArrayObjects (ccArray *arr, SEL sel, id object)
ccCArrayccCArrayNew (NSUInteger capacity)
void ccCArrayFree (ccCArray *arr)
void ccCArrayDoubleCapacity (ccCArray *arr)
void ccCArrayEnsureExtraCapacity (ccCArray *arr, NSUInteger extra)
NSUInteger ccCArrayGetIndexOfValue (ccCArray *arr, CCARRAY_ID value)
BOOL ccCArrayContainsValue (ccCArray *arr, CCARRAY_ID value)
void ccCArrayInsertValueAtIndex (ccCArray *arr, CCARRAY_ID value, NSUInteger index)
void ccCArrayAppendValue (ccCArray *arr, CCARRAY_ID value)
void ccCArrayAppendValueWithResize (ccCArray *arr, CCARRAY_ID value)
void ccCArrayAppendArray (ccCArray *arr, ccCArray *plusArr)
void ccCArrayAppendArrayWithResize (ccCArray *arr, ccCArray *plusArr)
void ccCArrayRemoveAllValues (ccCArray *arr)
void ccCArrayRemoveValueAtIndex (ccCArray *arr, NSUInteger index)
void ccCArrayFastRemoveValueAtIndex (ccCArray *arr, NSUInteger index)
void ccCArrayRemoveValue (ccCArray *arr, CCARRAY_ID value)
void ccCArrayRemoveArray (ccCArray *arr, ccCArray *minusArr)
void ccCArrayFullRemoveArray (ccCArray *arr, ccCArray *minusArr)
int cc_mergesortL (ccCArray *array, size_t width, cc_comparator comparator)
void cc_insertionSort (ccCArray *arr, cc_comparator comparator)
void cc_pointerswap (void *a, void *b, size_t width)

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)

Function Documentation

void ccArrayAppendArray ( ccArray arr,
ccArray plusArr 
)

Appends objects from plusArr to arr. Behavior undefined if arr doesn't have enough capacity.

void ccArrayAppendArrayWithResize ( ccArray arr,
ccArray plusArr 
)

Appends objects from plusArr to arr. Capacity of arr is increased if needed.

void ccArrayAppendObject ( ccArray arr,
id  object 
)

Appends an object. Behavior undefined if array doesn't have enough capacity.

void ccArrayAppendObjectWithResize ( ccArray arr,
id  object 
)

Appends an object. Capacity of arr is increased if needed.

BOOL ccArrayContainsObject ( ccArray arr,
id  object 
)

Returns a Boolean value that indicates whether object is present in array.

void ccArrayDoubleCapacity ( ccArray arr)

Doubles array capacity

void ccArrayEnsureExtraCapacity ( ccArray arr,
NSUInteger  extra 
)

Increases array capacity such that max >= num + extra.

void ccArrayFastRemoveObjectAtIndex ( ccArray arr,
NSUInteger  index 
)

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 ccArrayFree ( ccArray arr)

Frees array after removing all remaining objects. Silently ignores nil arr.

void ccArrayFullRemoveArray ( ccArray arr,
ccArray minusArr 
)

Removes from arr all objects in minusArr. For each object in minusArr, all matching instances in arr will be removed.

NSUInteger ccArrayGetIndexOfObject ( ccArray arr,
id  object 
)

Returns index of first occurrence of object, NSNotFound if object not found.

void ccArrayInsertObjectAtIndex ( ccArray arr,
id  object,
NSUInteger  index 
)

Inserts an object at index

void ccArrayMakeObjectsPerformSelector ( ccArray arr,
SEL  sel 
)

Sends to each object in arr the message identified by given selector.

ccArray* ccArrayNew ( NSUInteger  capacity)

Allocates and initializes a new array with specified capacity

Removes all objects from arr

void ccArrayRemoveArray ( ccArray arr,
ccArray minusArr 
)

Removes from arr all objects in minusArr. For each object in minusArr, the first matching instance in arr will be removed.

void ccArrayRemoveObject ( ccArray arr,
id  object 
)

Searches for the first occurrence of object and removes it. If object is not found the function has no effect.

void ccArrayRemoveObjectAtIndex ( ccArray arr,
NSUInteger  index 
)

Removes object at specified index and pushes back all subsequent objects. Behavior undefined if index outside [0, num-1].

void ccArrayShrink ( ccArray arr)

shrinks the array so the memory footprint corresponds with the number of items

void ccArraySwapObjectsAtIndexes ( ccArray arr,
NSUInteger  index1,
NSUInteger  index2 
)

Swaps two objects

void ccCArrayAppendArray ( ccCArray arr,
ccCArray plusArr 
)

Appends values from plusArr to arr. Behavior undefined if arr doesn't have enough capacity.

void ccCArrayAppendArrayWithResize ( ccCArray arr,
ccCArray plusArr 
)

Appends values from plusArr to arr. Capacity of arr is increased if needed.

void ccCArrayAppendValue ( ccCArray arr,
CCARRAY_ID  value 
)

Appends an value. Behavior undefined if array doesn't have enough capacity.

void ccCArrayAppendValueWithResize ( ccCArray arr,
CCARRAY_ID  value 
)

Appends an value. Capacity of arr is increased if needed.

BOOL ccCArrayContainsValue ( ccCArray arr,
CCARRAY_ID  value 
)

Returns a Boolean value that indicates whether value is present in the C array.

Doubles C array capacity

void ccCArrayEnsureExtraCapacity ( ccCArray arr,
NSUInteger  extra 
)

Increases array capacity such that max >= num + extra.

void ccCArrayFastRemoveValueAtIndex ( ccCArray arr,
NSUInteger  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 ccCArrayFree ( ccCArray arr)

Frees C array after removing all remaining values. Silently ignores nil arr.

void ccCArrayFullRemoveArray ( ccCArray arr,
ccCArray minusArr 
)

Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed.

Since:
v0.99.4
NSUInteger ccCArrayGetIndexOfValue ( ccCArray arr,
CCARRAY_ID  value 
)

Returns index of first occurrence of value, NSNotFound if value not found.

void ccCArrayInsertValueAtIndex ( ccCArray arr,
CCARRAY_ID  value,
NSUInteger  index 
)

Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity

ccCArray* ccCArrayNew ( NSUInteger  capacity)

Allocates and initializes a new C array with specified capacity

Removes all values from arr

void ccCArrayRemoveArray ( ccCArray arr,
ccCArray minusArr 
)

Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed.

Since:
v0.99.4
void ccCArrayRemoveValue ( ccCArray arr,
CCARRAY_ID  value 
)

Searches for the first occurrence of value and removes it. If value is not found the function has no effect.

Since:
v0.99.4
void ccCArrayRemoveValueAtIndex ( ccCArray arr,
NSUInteger  index 
)

Removes value at specified index and pushes back all subsequent values. Behavior undefined if index outside [0, num-1].

Since:
v0.99.4