10 /* "Base" vector type, designed to alias with the actual vector types. */
11 typedef struct vector__s
{
16 #define TYPEDEF_VECTOR(T, N) typedef struct { \
22 typedef const _##N* const_##N;
24 #define VECTOR(T) struct { \
30 #define VECTOR_INIT(_x) do { (_x) = NULL; } while(0)
31 #define VECTOR_INIT_STATIC() NULL
32 #define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0)
34 /* Helper to increase a vector's reserve. Do not call directly. */
35 ALboolean
vector_reserve(char *ptr
, size_t base_size
, size_t obj_size
, size_t obj_count
, ALboolean exact
);
36 #define VECTOR_RESERVE(_x, _c) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c), AL_TRUE))
38 ALboolean
vector_resize(char *ptr
, size_t base_size
, size_t obj_size
, size_t obj_count
);
39 #define VECTOR_RESIZE(_x, _c) (vector_resize((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c)))
41 #define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
42 #define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
44 #define VECTOR_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
45 #define VECTOR_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
47 ALboolean
vector_insert(char *ptr
, size_t base_size
, size_t obj_size
, void *ins_pos
, const void *datstart
, const void *datend
);
49 #define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2)
50 #define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \
52 static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_i))), "Incompatible insertion iterator"); \
53 static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_s))), "Incompatible insertion source type"); \
54 static_assert(TYPE_CHECK(__typeof(*(_s)), __typeof(*(_e))), "Incompatible iterator sources"); \
55 _r = vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \
59 #define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
62 #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), VECTOR_SIZE(_x)+1, AL_FALSE) && \
63 (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
64 #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
66 #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
67 #define VECTOR_FRONT(_x) ((_x)->Data[0])
69 #define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
71 #define VECTOR_FOR_EACH(_t, _x, _f) do { \
72 _t *_iter = VECTOR_BEGIN((_x)); \
73 _t *_end = VECTOR_END((_x)); \
74 for(;_iter != _end;++_iter) \
78 #define VECTOR_FOR_EACH_PARAMS(_t, _x, _f, ...) do { \
79 _t *_iter = VECTOR_BEGIN((_x)); \
80 _t *_end = VECTOR_END((_x)); \
81 for(;_iter != _end;++_iter) \
82 _f(__VA_ARGS__, _iter); \
85 #define VECTOR_FIND_IF(_i, _t, _x, _f) do { \
86 _t *_iter = VECTOR_BEGIN((_x)); \
87 _t *_end = VECTOR_END((_x)); \
88 for(;_iter != _end;++_iter) \
96 #define VECTOR_FIND_IF_PARMS(_i, _t, _x, _f, ...) do { \
97 _t *_iter = VECTOR_BEGIN((_x)); \
98 _t *_end = VECTOR_END((_x)); \
99 for(;_iter != _end;++_iter) \
101 if(_f(__VA_ARGS__, _iter)) \
107 #endif /* AL_VECTOR_H */