Go to the documentation of this file.
25 #ifndef PIPEWIRE_ARRAY_H
26 #define PIPEWIRE_ARRAY_H
34 #include <spa/utils/defs.h>
50 #define PW_ARRAY_INIT(extend) (struct pw_array) { NULL, 0, 0, extend }
52 #define pw_array_get_len_s(a,s) ((a)->size / (s))
53 #define pw_array_get_unchecked_s(a,idx,s,t) SPA_MEMBER((a)->data,(idx)*(s),t)
54 #define pw_array_check_index_s(a,idx,s) ((idx) < pw_array_get_len_s(a,s))
57 #define pw_array_get_len(a,t) pw_array_get_len_s(a,sizeof(t))
59 #define pw_array_get_unchecked(a,idx,t) pw_array_get_unchecked_s(a,idx,sizeof(t),t)
61 #define pw_array_check_index(a,idx,t) pw_array_check_index_s(a,idx,sizeof(t))
63 #define pw_array_first(a) ((a)->data)
64 #define pw_array_end(a) SPA_MEMBER((a)->data, (a)->size, void)
65 #define pw_array_check(a,p) (SPA_MEMBER(p,sizeof(*p),void) <= pw_array_end(a))
67 #define pw_array_for_each(pos, array) \
68 for (pos = (__typeof__(pos)) pw_array_first(array); \
69 pw_array_check(array, pos); \
72 #define pw_array_consume(pos, array) \
73 for (pos = (__typeof__(pos)) pw_array_first(array); \
74 pw_array_check(array, pos); \
75 pos = (__typeof__(pos)) pw_array_first(array))
77 #define pw_array_remove(a,p) \
79 (a)->size -= sizeof(*(p)); \
80 memmove(p, SPA_MEMBER((p), sizeof(*(p)), void), \
81 SPA_PTRDIFF(pw_array_end(a),(p))); \
93 static inline void pw_array_clear(
struct pw_array *arr)
99 static inline void pw_array_reset(
struct pw_array *arr)
110 need = arr->
size + size;
112 if (SPA_UNLIKELY(alloc < need)) {
114 alloc = SPA_MAX(alloc, arr->
extend);
117 if (SPA_UNLIKELY((
data = realloc(arr->
data, alloc)) == NULL))
134 p = SPA_MEMBER(arr->
data, arr->
size,
void);
146 if (SPA_UNLIKELY(arr->
alloc < arr->
size + size)) {
151 p = SPA_MEMBER(arr->
data, arr->
size,
void);
158 #define pw_array_add_ptr(a,p) \
159 *((void**) pw_array_add(a, sizeof(void*))) = (p)
size_t alloc
number of allocated memory in data
Definition: array.h:46
size_t size
length of array in bytes
Definition: array.h:45
size_t extend
number of bytes to extend with
Definition: array.h:47
An array object.
Definition: array.h:43
static void * pw_array_add_fixed(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:142
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:105
static void * pw_array_add(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:127
void * data
pointer to array data
Definition: array.h:44
static void pw_array_init(struct pw_array *arr, size_t extend)
Initialize the array with given extend.
Definition: array.h:85