]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
Merge branch 'master' into terencehill/menu_hudskin_selector
[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         do \
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         } \
20         while (0)
21
22 #define AL_DELETE(this) \
23         do \
24         { \
25                 buf_del(this.al_buf); \
26                 remove(this); \
27                 this = NULL; \
28         } \
29         while (0)
30
31 #define _AL_type__s() string
32 #define AL_gets(this, idx) bufstr_get(this.al_buf, idx)
33 #define AL_sets(this, idx, val) bufstr_set(this.al_buf, idx, val)
34
35 #define _AL_type__f() float
36 #define AL_getf(this, idx) stof(AL_gets(this, idx))
37 #define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val))
38
39 #define _AL_type__e() entity
40 #define AL_gete(this, idx) ftoe(AL_getf(this, idx))
41 #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val))
42
43 #define AL_EACH(this, T, cond, body) \
44         do \
45         { \
46                 const noref ArrayList _al = this; \
47                 for (int i = 0, n = _al.al_len; i < n; ++i) \
48                 { \
49                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
50                         if (cond) { body } \
51                 } \
52         } \
53         while (0)
54
55 #endif