]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/iter.qh
Merge branch 'master' into Mario/bulldozer
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / iter.qh
1 #ifndef ITER_H
2 #define ITER_H
3
4 #define FOREACH_ARRAY(arr, start, end, cond, body) \
5         do \
6         { \
7                 for (int i = start; i < end; ++i) \
8                 { \
9                         const noref entity it = arr[i]; \
10                         if (cond) { body } \
11                 } \
12         } \
13         while (0)
14
15 #define FOREACH_LIST(list, next, cond, body) \
16         do \
17         { \
18                 int i = 0; \
19                 for (entity it = list##_first; it; (it = it.next, ++i)) \
20                 { \
21                         if (cond) { body } \
22                 } \
23         } \
24         while (0)
25
26 #define FOREACH_WORD(words, cond, body) \
27         do \
28         { \
29                 string _words = words; \
30                 int i = 0; \
31                 for (string _it; (_it = car(_words)); (_words = cdr(_words), ++i)) \
32                 { \
33                         const noref string it = _it; \
34                         if (cond) { body } \
35                 } \
36         } \
37         while (0)
38
39 #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
40
41 #endif