]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/arraylist.qh
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / arraylist.qh
1 #pragma once
2
3 USING(ArrayList, entity);
4 .int al_buf;
5 .int al_len;
6
7 #define AL_NEW(this, n, default, T) \
8         MACRO_BEGIN \
9         { \
10                 ArrayList _al = this = new_pure(ArrayList); \
11                 _al.al_buf = buf_create(); \
12                 for (int i = 0, _n = _al.al_len = n; i < _n; ++i) \
13                 { \
14                         const _AL_type__##T() it = default; \
15                         AL_set##T(this, i, it); \
16                 } \
17         } MACRO_END
18
19 #define AL_DELETE(this) \
20         MACRO_BEGIN \
21         { \
22                 buf_del(this.al_buf); \
23                 delete(this); \
24                 this = NULL; \
25         } MACRO_END
26
27 #define _AL_type__s() string
28 #define AL_gets(this, idx) bufstr_get(this.al_buf, idx)
29 #define AL_sets(this, idx, val) bufstr_set(this.al_buf, idx, val)
30
31 #if defined(CSQC)
32 string al_ftos(float f) = #26;
33 float al_stof(string s) = #81;
34 #elif defined(SVQC)
35 string al_ftos(float f) = #26;
36 float al_stof(string s) = #81;
37 #elif defined(MENUQC)
38 string al_ftos(float f) = #17;
39 float al_stof(string s) = #21;
40 #endif
41
42 #define _AL_type__f() float
43 #define AL_getf(this, idx) al_stof(AL_gets(this, idx))
44 #define AL_setf(this, idx, val) AL_sets(this, idx, al_ftos(val))
45
46 #if defined(CSQC)
47 int al_etof(entity e) = #512;
48 entity al_ftoe(int i) = #459;
49 #elif defined(SVQC)
50 int al_etof(entity e) = #512;
51 entity al_ftoe(int i) = #459;
52 #elif defined(MENUQC)
53 int al_etof(entity e) = #79;
54 entity al_ftoe(int i) = #80;
55 #endif
56
57 #define _AL_type__e() entity
58 #define AL_gete(this, idx) al_ftoe(AL_getf(this, idx))
59 #define AL_sete(this, idx, val) AL_setf(this, idx, al_etof(val))
60
61 #define AL_EACH(this, T, cond, body) \
62         MACRO_BEGIN \
63         { \
64                 const noref ArrayList _al = this; \
65                 for (int i = 0, n = _al.al_len; i < n; ++i) \
66                 { \
67                         const noref _AL_type__##T() it = AL_get##T(_al, i); \
68                         if (cond) { body } \
69                 } \
70         } MACRO_END