]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
Merge branch 'terencehill/menu_hudskin_selector' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / arraylist.qh
1 #ifndef ARRAYLIST_H
2 #define ARRAYLIST_H
3
4 typedef entity ArrayList;
5 .int al_buf;
6 .int al_len;
7
8 #define AL_NEW(this, n, default, T) \
9         MACRO_BEGIN \
10         { \
11                 ArrayList _al = this = new(ArrayList); \
12                 make_pure(_al); \
13                 _al.al_buf = buf_create(); \
14                 for (int i = 0, _n = _al.al_len = n; i < _n; ++i) \
15                 { \
16                         const _AL_type__##T() it = default; \
17                         AL_set##T(this, i, it); \
18                 } \
19         } MACRO_END
20
21 #define AL_DELETE(this) \
22         MACRO_BEGIN \
23         { \
24                 buf_del(this.al_buf); \
25                 remove(this); \
26                 this = NULL; \
27         } MACRO_END
28
29 #define _AL_type__s() string
30 #define AL_gets(this, idx) bufstr_get(this.al_buf, idx)
31 #define AL_sets(this, idx, val) bufstr_set(this.al_buf, idx, val)
32
33 #define _AL_type__f() float
34 #define AL_getf(this, idx) stof(AL_gets(this, idx))
35 #define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val))
36
37 #define _AL_type__e() entity
38 #define AL_gete(this, idx) ftoe(AL_getf(this, idx))
39 #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val))
40
41 #define AL_EACH(this, T, cond, body) \
42         MACRO_BEGIN \
43         { \
44                 const noref ArrayList _al = this; \
45                 for (int i = 0, n = _al.al_len; i < n; ++i) \
46                 { \
47                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
48                         if (cond) { body } \
49                 } \
50         } MACRO_END
51
52 #endif