25 #ifndef PIPEWIRE_ARRAY_H 26 #define PIPEWIRE_ARRAY_H 55 #define PW_ARRAY_INIT(extend) (struct pw_array) { NULL, 0, 0, extend } 57 #define pw_array_get_len_s(a,s) ((a)->size / (s)) 58 #define pw_array_get_unchecked_s(a,idx,s,t) SPA_PTROFF((a)->data,(idx)*(s),t) 59 #define pw_array_check_index_s(a,idx,s) ((idx) < pw_array_get_len_s(a,s)) 62 #define pw_array_get_len(a,t) pw_array_get_len_s(a,sizeof(t)) 64 #define pw_array_get_unchecked(a,idx,t) pw_array_get_unchecked_s(a,idx,sizeof(t),t) 66 #define pw_array_check_index(a,idx,t) pw_array_check_index_s(a,idx,sizeof(t)) 68 #define pw_array_first(a) ((a)->data) 69 #define pw_array_end(a) SPA_PTROFF((a)->data, (a)->size, void) 70 #define pw_array_check(a,p) (SPA_PTROFF(p,sizeof(*p),void) <= pw_array_end(a)) 72 #define pw_array_for_each(pos, array) \ 73 for (pos = (__typeof__(pos)) pw_array_first(array); \ 74 pw_array_check(array, pos); \ 77 #define pw_array_consume(pos, array) \ 78 for (pos = (__typeof__(pos)) pw_array_first(array); \ 79 pw_array_check(array, pos); \ 80 pos = (__typeof__(pos)) pw_array_first(array)) 82 #define pw_array_remove(a,p) \ 84 (a)->size -= sizeof(*(p)); \ 85 memmove(p, SPA_PTROFF((p), sizeof(*(p)), void), \ 86 SPA_PTRDIFF(pw_array_end(a),(p))); \ 165 #define pw_array_add_ptr(a,p) \ 166 *((void**) pw_array_add(a, sizeof(void*))) = (p) static int pw_array_ensure_size(struct pw_array *arr, size_t size)
Make sure size bytes can be added to the array.
Definition: array.h:116
static void pw_array_reset(struct pw_array *arr)
Reset the array.
Definition: array.h:110
void * data
pointer to array data
Definition: array.h:53
static void pw_array_init(struct pw_array *arr, size_t extend)
Initialize the array with given extend.
Definition: array.h:95
static void * pw_array_add_fixed(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:154
#define SPA_UNLIKELY(x)
Definition: defs.h:315
size_t alloc
number of allocated memory in data
Definition: array.h:55
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:183
static void pw_array_clear(struct pw_array *arr)
Clear the array.
Definition: array.h:103
size_t extend
number of bytes to extend with
Definition: array.h:56
#define spa_assert(expr)
Definition: defs.h:370
#define SPA_MAX(a, b)
Definition: defs.h:152
size_t size
length of array in bytes
Definition: array.h:54
static void * pw_array_add(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:139