Add an al_string type and use it for the device lists
[openal-soft.git] / Alc / vector.h
blob7ff651463bbd0f27999258a3cfbdb4012bfc31d2
1 #ifndef AL_VECTOR_H
2 #define AL_VECTOR_H
4 #include <stdlib.h>
6 #include <AL/al.h>
8 /* "Base" vector type, designed to alias with the actual vector types. */
9 typedef struct vector__s {
10 ALsizei Capacity;
11 ALsizei Size;
12 } *vector_;
14 #define DECL_VECTOR(T) typedef struct vector_##T##_s { \
15 ALsizei Capacity; \
16 ALsizei Size; \
17 T Data[]; \
18 } *vector_##T; \
19 typedef const struct vector_##T##_s *const_vector_##T;
21 #define VECTOR_INIT(_x) do { (_x) = calloc(1, sizeof(*(_x))); } 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 orig_count, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact);
26 #define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), (_x)->Capacity, 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)->Capacity)
33 #define VECTOR_SIZE(_x) ((const ALsizei)(_x)->Size)
35 #define VECTOR_ITER_BEGIN(_x) ((_x)->Data)
36 #define VECTOR_ITER_END(_x) ((_x)->Data + (_x)->Size)
38 #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_x)->Size+1, sizeof((_x)->Data[0]), AL_FALSE) && \
39 (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
40 #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
42 #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
43 #define VECTOR_FRONT(_x) ((_x)->Data[0])
45 #define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
47 #endif /* AL_VECTOR_H */