dynarray: Add PA_DYNARRAY_FOREACH

The PA_DYNARRAY_FOREACH macro requires that pa_dynarray_get() returns
NULL if the index is out of bounds.
This commit is contained in:
Tanu Kaskinen 2015-01-07 16:56:50 +02:00 committed by David Henningsson
parent 7d3879c07f
commit 360cb6550e
3 changed files with 8 additions and 4 deletions

View file

@ -43,6 +43,8 @@ pa_dynarray* pa_dynarray_new(pa_free_cb_t free_cb);
void pa_dynarray_free(pa_dynarray *array);
void pa_dynarray_append(pa_dynarray *array, void *p);
/* Returns the element at index i, or NULL if i is out of bounds. */
void *pa_dynarray_get(pa_dynarray *array, unsigned i);
/* Returns the last element, or NULL if the array is empty. */
@ -61,4 +63,7 @@ void *pa_dynarray_steal_last(pa_dynarray *array);
unsigned pa_dynarray_size(pa_dynarray *array);
#define PA_DYNARRAY_FOREACH(elem, array, idx) \
for ((idx) = 0; ((elem) = pa_dynarray_get(array, idx)); (idx)++)
#endif