]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
This commit is dedicated to TimePath
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / arraylist.qh
1 #ifndef ARRAYLIST_H
2 #define ARRAYLIST_H
3
4 typedef int ArrayList;
5
6 #define AL_declare(this) ArrayList this; int this##_len = (0)
7 #define AL_init(this, n, default, T) \
8         do \
9         { \
10                 this = buf_create(); \
11                 this##_len = n; \
12                 for (int i = 0; i < this##_len; ++i) \
13                 { \
14                         const _AL_type__##T() it = default; \
15                         AL_set##T(this, i, it); \
16                 } \
17         } \
18         while (0)
19 #define AL_delete(this) buf_del(this)
20
21 #define _AL_type__s() string
22 #define AL_gets(this, idx) bufstr_get(this, idx)
23 #define AL_sets(this, idx, val) bufstr_set(this, idx, val)
24
25 #define _AL_type__f() float
26 #define AL_getf(this, idx) stof(AL_gets(this, idx))
27 #define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val))
28
29 #define _AL_type__e() entity
30 #define AL_gete(this, idx) ftoe(AL_getf(this, idx))
31 #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val))
32
33 #define AL_EACH(this, T, cond, body) \
34         do \
35         { \
36                 const noref ArrayList _al = this; \
37                 for (int i = 0, n = this##_len; i < n; ++i) \
38                 { \
39                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
40                         if (cond) { body } \
41                 } \
42         } \
43         while (0)
44
45 #endif