AEArray.h File Reference
#import <Foundation/Foundation.h>

Go to the source code of this file.

Classes

class  AEArray
 Real-time safe array. More...
 

Macros

#define __AEArrayVar2(x, y)   x ## y
 
#define __AEArrayVar(x, y)   __AEArrayVar2(__ ## x ## _line_, y)
 
#define AEArrayEnumerateObjects(array, type, varname)
 Enumerate object types in the array, for use on audio thread.
 
#define AEArrayEnumeratePointers(array, type, varname)
 Enumerate pointer types in the array, for use on audio thread.
 

Typedefs

typedef const void * AEArrayToken
 Token for real-thread use.
 
typedef void *_Nullable(^ AEArrayCustomMappingBlock )(id _Nonnull item)
 Block for mapping between objects and opaque pointer values.
 
typedef void *_Nullable(^ AEArrayIndexedCustomMappingBlock )(id _Nonnull item, int index)
 Block for mapping between objects and opaque pointer values, for use with AEArray's updateWithContentsOfArray:customMapping: method.
 
typedef void(^ AEArrayReleaseBlock )(id _Nonnull item, void *_Nonnull bytes)
 Block for releasing allocated values.
 

Macro Definition Documentation

#define __AEArrayVar2 (   x,
 
)    x ## y
#define __AEArrayVar (   x,
 
)    __AEArrayVar2(__ ## x ## _line_, y)
#define AEArrayEnumerateObjects (   array,
  type,
  varname 
)
Value:
AEArrayToken __AEArrayVar(token, __LINE__) = AEArrayGetToken(array); \
int __AEArrayVar(count, __LINE__) = AEArrayGetCount(__AEArrayVar(token, __LINE__)); \
int __AEArrayVar(i, __LINE__) = 0; \
for ( __unsafe_unretained type varname = __AEArrayVar(count, __LINE__) > 0 ? (__bridge type)AEArrayGetItem(__AEArrayVar(token, __LINE__), 0) : NULL; \
__AEArrayVar(i, __LINE__) < __AEArrayVar(count, __LINE__); \
__AEArrayVar(i, __LINE__)++, varname = __AEArrayVar(i, __LINE__) < __AEArrayVar(count, __LINE__) ? \
(__bridge type)AEArrayGetItem(__AEArrayVar(token, __LINE__), __AEArrayVar(i, __LINE__)) : NULL )

Enumerate object types in the array, for use on audio thread.

This convenience macro provides the ability to enumerate the objects in the array, in a realtime-thread safe fashion.

Use it like:

AEArrayEnumerateObjects(array, MyObjectType *, myVar) {
    // Do stuff with myVar, which is a MyObjectType *
}

Note: This macro calls AEArrayGetToken to access the array. Consequently, it is not recommended for use when you need to access the array in addition to this enumeration.

Note: Do not use this macro on the main thread

Parameters
arrayThe array
typeThe object type
varnameName of object variable for inner loop
#define AEArrayEnumeratePointers (   array,
  type,
  varname 
)
Value:
AEArrayToken __AEArrayVar(token, __LINE__) = AEArrayGetToken(array); \
int __AEArrayVar(count, __LINE__) = AEArrayGetCount(__AEArrayVar(token, __LINE__)); \
int __AEArrayVar(i, __LINE__) = 0; \
for ( type varname = __AEArrayVar(count, __LINE__) > 0 ? (type)AEArrayGetItem(__AEArrayVar(token, __LINE__), 0) : NULL; \
__AEArrayVar(i, __LINE__) < __AEArrayVar(count, __LINE__); \
__AEArrayVar(i, __LINE__)++, varname = __AEArrayVar(i, __LINE__) < __AEArrayVar(count, __LINE__) ? \
(type)AEArrayGetItem(__AEArrayVar(token, __LINE__), __AEArrayVar(i, __LINE__)) : NULL )

Enumerate pointer types in the array, for use on audio thread.

This convenience macro provides the ability to enumerate the pointers in the array, in a realtime-thread safe fashion. It differs from AEArrayEnumerateObjects in that it is designed for use with pointer types, rather than objects.

Use it like:

AEArrayEnumeratePointers(array, MyCType *, myVar) {
    // Do stuff with myVar, which is a MyCType *
}

Note: This macro calls AEArrayGetToken to access the array. Consequently, it is not recommended for use when you need to access the array in addition to this enumeration.

Note: Do not use this macro on the main thread

Parameters
arrayThe array
typeThe pointer type (e.g. struct myStruct *)
varnameName of pointer variable for inner loop

Typedef Documentation

typedef const void* AEArrayToken

Token for real-thread use.

typedef void* _Nullable(^ AEArrayCustomMappingBlock)(id _Nonnull item)

Block for mapping between objects and opaque pointer values.

Pass a block matching this type to AEArray's initializer in order to map between objects in the array and an arbitrary data block; this can be a pointer to an allocated C structure, for example, or any other collection of bytes.

The block is invoked on the main thread whenever a new item is added to the array during an update. You should allocate the memory you need, set the contents, and return a pointer to this memory. It will be freed automatically once the item is removed from the array, unless you provide a custom releaseBlock .

Parameters
itemThe original object
Returns
Pointer to an allocated memory region
typedef void* _Nullable(^ AEArrayIndexedCustomMappingBlock)(id _Nonnull item, int index)

Block for mapping between objects and opaque pointer values, for use with AEArray's updateWithContentsOfArray:customMapping: method.

See documentation for AEArrayCustomMappingBlock for details.

Parameters
itemThe original object
Returns
Pointer to an allocated memory region
typedef void(^ AEArrayReleaseBlock)(id _Nonnull item, void *_Nonnull bytes)

Block for releasing allocated values.

Assign a block matching this type to AEArray's releaseBlock property to provide a custom release implementation. Use this if you are using a custom mapping block and need to perform extra cleanup tasks beyond simply freeing the returned pointer.

Parameters
itemThe original object
bytesThe bytes originally returned from the custom mapping block