]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
ArrayList: implement
[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
20 #define _AL_type__s() string
21 #define AL_gets(this, idx) bufstr_get(this, idx)
22 #define AL_sets(this, idx, val) bufstr_set(this, idx, val)
23
24 #define _AL_type__f() float
25 #define AL_getf(this, idx) stof(AL_gets(this, idx))
26 #define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val))
27
28 #define _AL_type__e() entity
29 #define AL_gete(this, idx) ftoe(AL_getf(this, idx))
30 #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val))
31
32 #define AL_EACH(this, T, cond, body) \
33         do \
34         { \
35                 const noref ArrayList _al = this; \
36                 for (int i = 0, n = this##_len; i < n; ++i) \
37                 { \
38                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
39                         if (cond) { body } \
40                 } \
41         } \
42         while (0)
43
44 #endif