#ifndef ITER_H #define ITER_H #define FOREACH_ARRAY(arr, start, end, cond, body) \ do \ { \ for (int i = start; i < end; ++i) \ { \ const noref entity it = arr[i]; \ if (cond) { body } \ } \ } \ while (0) #define FOREACH_LIST(list, next, cond, body) \ do \ { \ int i = 0; \ for (entity it = list##_first; it; (it = it.next, ++i)) \ { \ if (cond) { body } \ } \ } \ while (0) #define FOREACH_WORD(words, cond, body) \ do \ { \ string _words = words; \ int i = 0; \ for (string _it; (_it = car(_words)); (_words = cdr(_words), ++i)) \ { \ const noref string it = _it; \ if (cond) { body } \ } \ } \ while (0) #if defined(CSQC) entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403; #elif defined(SVQC) entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403; #elif defined(MENUQC) entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #27; #endif .entity _FOREACH_ENTITY_fld; .entity _FOREACH_ENTITY_next; #define FOREACH_ENTITY_UNORDERED(cond, body) \ do { \ int i = 0; \ for (entity it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ if (cond) { body } \ } \ } \ while (0) #define FOREACH_ENTITY_ORDERED(cond, body) \ do { \ int i = 0; \ for (entity it = NULL; (it = nextent(it)); ++i) \ { \ if (cond) { body } \ } \ } \ while (0) #define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body) #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body) #endif