8 /* "Base" vector type, designed to alias with the actual vector types. */
9 typedef struct vector__s
{
14 #define DECL_VECTOR(T) typedef struct vector_##T##_s { \
19 typedef const struct vector_##T##_s *const_vector_##T;
21 #define VECTOR_INIT(_x) do { (_x) = NULL; } while(0)
22 #define VECTOR_DEINIT(_x) do { free((_x)); (_x) = NULL; } while(0)
24 /* Helper to increase a vector's reserve. Do not call directly. */
25 ALboolean
vector_reserve(void *ptr
, size_t base_size
, size_t obj_count
, size_t obj_size
, ALboolean exact
);
26 #define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0]), AL_TRUE))
28 /* Helper to change a vector's size. Do not call directly. */
29 ALboolean
vector_resize(void *ptr
, size_t base_size
, size_t obj_count
, size_t obj_size
);
30 #define VECTOR_RESIZE(_x, _c) (vector_resize(&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0])))
32 #define VECTOR_CAPACITY(_x) ((const ALsizei)((_x) ? (_x)->Capacity : 0))
33 #define VECTOR_SIZE(_x) ((const ALsizei)((_x) ? (_x)->Size : 0))
35 #define VECTOR_ITER_BEGIN(_x) ((_x)->Data + 0)
36 #define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE(_x))
38 ALboolean
vector_insert(void *ptr
, size_t base_size
, size_t obj_size
, void *ins_pos
, const void *datstart
, const void *datend
);
40 #define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2)
41 #define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \
43 static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_i))), "Incompatible insertion iterator"); \
44 static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_s))), "Incompatible insertion source type"); \
45 static_assert(TYPE_CHECK(__typeof(*(_s)), __typeof(*(_e))), "Incompatible iterator sources"); \
46 _r = vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \
50 #define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
53 #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \
54 (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
55 #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
57 #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
58 #define VECTOR_FRONT(_x) ((_x)->Data[0])
60 #define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
62 #define VECTOR_FOR_EACH(_t, _x, _f) do { \
63 _t *_iter = VECTOR_ITER_BEGIN((_x)); \
64 _t *_end = VECTOR_ITER_END((_x)); \
65 for(;_iter != _end;++_iter) \
69 #endif /* AL_VECTOR_H */