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