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 { \
20 #define VECTOR_INIT(_x) (((_x) = calloc(1, sizeof(*(_x)))) != NULL)
21 #define VECTOR_DEINIT(_x) do { free(_x); _x = NULL; } while(0)
23 /* Helper to increase a vector's reserve. Do not call directly. */
24 ALboolean
vector_reserve(void *ptr
, size_t orig_count
, size_t base_size
, size_t obj_count
, size_t obj_size
, ALboolean exact
);
25 #define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_c), sizeof((_x)->Data[0]), AL_TRUE))
27 #define VECTOR_CAPACITY(_x) ((const ALsizei)(_x)->Capacity)
28 #define VECTOR_SIZE(_x) ((const ALsizei)(_x)->Size)
30 #define VECTOR_ITER_BEGIN(_x) ((_x)->Data)
31 #define VECTOR_ITER_END(_x) ((_x)->Data + (_x)->Size)
33 #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_x)->Size+1, sizeof((_x)->Data[0]), AL_FALSE) && \
34 (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
35 #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
37 #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
38 #define VECTOR_FRONT(_x) ((_x)->Data[0])
40 #define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
42 #endif /* AL_VECTOR_H */