]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
Merge branch 'terencehill/cl_forceplayercolors_2' 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 #if defined(CSQC)
34 string al_ftos(float f) = #26;
35 float al_stof(string s) = #81;
36 #elif defined(SVQC)
37 string al_ftos(float f) = #26;
38 float al_stof(string s) = #81;
39 #elif defined(MENUQC)
40 string al_ftos(float f) = #17;
41 float al_stof(string s) = #21;
42 #endif
43
44 #define _AL_type__f() float
45 #define AL_getf(this, idx) al_stof(AL_gets(this, idx))
46 #define AL_setf(this, idx, val) AL_sets(this, idx, al_ftos(val))
47
48 #if defined(CSQC)
49 int al_etof(entity e) = #512;
50 entity al_ftoe(int i) = #459;
51 #elif defined(SVQC)
52 int al_etof(entity e) = #512;
53 entity al_ftoe(int i) = #459;
54 #elif defined(MENUQC)
55 int al_etof(entity e) = #79;
56 entity al_ftoe(int i) = #80;
57 #endif
58
59 #define _AL_type__e() entity
60 #define AL_gete(this, idx) al_ftoe(AL_getf(this, idx))
61 #define AL_sete(this, idx, val) AL_setf(this, idx, al_etof(val))
62
63 #define AL_EACH(this, T, cond, body) \
64         MACRO_BEGIN \
65         { \
66                 const noref ArrayList _al = this; \
67                 for (int i = 0, n = _al.al_len; i < n; ++i) \
68                 { \
69                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
70                         if (cond) { body } \
71                 } \
72         } MACRO_END
73
74 #endif