Change the backend getLatency method to return the clock time too
[openal-soft.git] / Alc / vector.h
blob5a0219c08166d42ea638400dd6c35ff1fda85a96
1 #ifndef AL_VECTOR_H
2 #define AL_VECTOR_H
4 #include <stdlib.h>
6 #include <AL/al.h>
8 #include "almalloc.h"
10 /* "Base" vector type, designed to alias with the actual vector types. */
11 typedef struct vector__s {
12 size_t Capacity;
13 size_t Size;
14 } *vector_;
16 #define TYPEDEF_VECTOR(T, N) typedef struct { \
17 size_t Capacity; \
18 size_t Size; \
19 T Data[]; \
20 } _##N; \
21 typedef _##N* N; \
22 typedef const _##N* const_##N;
24 #define VECTOR(T) struct { \
25 size_t Capacity; \
26 size_t Size; \
27 T Data[]; \
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);
48 #ifdef __GNUC__
49 #define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2)
50 #define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \
51 ALboolean _r; \
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)); \
56 _r; \
58 #else
59 #define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
60 #endif
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) \
75 _f(_iter); \
76 } while(0)
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); \
83 } while(0)
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) \
89 { \
90 if(_f(_iter)) \
91 break; \
92 } \
93 (_i) = _iter; \
94 } while(0)
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)) \
102 break; \
104 (_i) = _iter; \
105 } while(0)
107 #endif /* AL_VECTOR_H */