Check for the upsampler to determine if HRTF uses HOA
[openal-soft.git] / Alc / vector.h
blobed0780e3c4cf73bda9ac07d6c098d07cb2d9bbd0
1 #ifndef AL_VECTOR_H
2 #define AL_VECTOR_H
4 #include <stdlib.h>
6 #include <AL/al.h>
8 #include "almalloc.h"
11 #define TYPEDEF_VECTOR(T, N) typedef struct { \
12 size_t Capacity; \
13 size_t Size; \
14 T Data[]; \
15 } _##N; \
16 typedef _##N* N; \
17 typedef const _##N* const_##N;
19 #define VECTOR(T) struct { \
20 size_t Capacity; \
21 size_t Size; \
22 T Data[]; \
25 #define VECTOR_INIT(_x) do { (_x) = NULL; } while(0)
26 #define VECTOR_INIT_STATIC() NULL
27 #define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0)
29 #define VECTOR_RESIZE(_x, _s, _c) do { \
30 size_t _size = (_s); \
31 size_t _cap = (_c); \
32 if(_size > _cap) \
33 _cap = _size; \
35 if(!(_x) && _cap == 0) \
36 break; \
38 if(((_x) ? (_x)->Capacity : 0) < _cap) \
39 { \
40 ptrdiff_t data_offset = (char*)((_x)->Data) - (char*)(_x); \
41 size_t old_size = ((_x) ? (_x)->Size : 0); \
42 void *temp; \
44 temp = al_calloc(16, data_offset + sizeof((_x)->Data[0])*_cap); \
45 assert(temp != NULL); \
46 if((_x)) \
47 memcpy(((char*)temp)+data_offset, (_x)->Data, \
48 sizeof((_x)->Data[0])*old_size); \
50 al_free((_x)); \
51 (_x) = temp; \
52 (_x)->Capacity = _cap; \
53 } \
54 (_x)->Size = _size; \
55 } while(0) \
57 #define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
58 #define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
60 #define VECTOR_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
61 #define VECTOR_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
63 #define VECTOR_PUSH_BACK(_x, _obj) do { \
64 size_t _pbsize = VECTOR_SIZE(_x)+1; \
65 VECTOR_RESIZE(_x, _pbsize, _pbsize); \
66 (_x)->Data[(_x)->Size-1] = (_obj); \
67 } while(0)
68 #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
70 #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
71 #define VECTOR_FRONT(_x) ((_x)->Data[0])
73 #define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
75 #define VECTOR_FOR_EACH(_t, _x, _f) do { \
76 _t *_iter = VECTOR_BEGIN((_x)); \
77 _t *_end = VECTOR_END((_x)); \
78 for(;_iter != _end;++_iter) \
79 _f(_iter); \
80 } while(0)
82 #define VECTOR_FIND_IF(_i, _t, _x, _f) do { \
83 _t *_iter = VECTOR_BEGIN((_x)); \
84 _t *_end = VECTOR_END((_x)); \
85 for(;_iter != _end;++_iter) \
86 { \
87 if(_f(_iter)) \
88 break; \
89 } \
90 (_i) = _iter; \
91 } while(0)
93 #endif /* AL_VECTOR_H */