Created
November 4, 2011 21:51
-
-
Save slembcke/1340578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __has_feature(objc_arc) | |
typedef __strong id CCARRAY_ID; | |
#define CCARRAY_RETAIN(obj) obj | |
#define CCARRAY_RELEASE(obj) (void)obj | |
#else | |
typedef id CCARRAY_ID; | |
#define CCARRAY_RETAIN(obj) [obj retain] | |
#define CCARRAY_RELEASE(obj) [obj release] | |
#endif | |
typedef struct ccArray { | |
NSUInteger num, max; | |
CCARRAY_ID *arr; | |
} ccArray; | |
/** Allocates and initializes a new array with specified capacity */ | |
static inline ccArray* ccArrayNew(NSUInteger capacity) { | |
if (capacity == 0) | |
capacity = 1; | |
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) ); | |
arr->num = 0; | |
arr->arr = (CCARRAY_ID *) malloc( capacity * sizeof(id) ); | |
arr->max = capacity; | |
return arr; | |
} | |
/** Removes all objects from arr */ | |
static inline void ccArrayRemoveAllObjects(ccArray *arr) | |
{ | |
while( arr->num > 0 ) | |
CCARRAY_RELEASE(arr->arr[--arr->num]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment