]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
iter: allow toggling between const/mutable `it`
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 17 Mar 2016 00:08:31 +0000 (11:08 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 17 Mar 2016 01:17:09 +0000 (12:17 +1100)
qcsrc/lib/iter.qh
qcsrc/lib/linkedlist.qh
qcsrc/lib/oo.qh
qcsrc/server/_all.qh

index 89b455ab56f9f6ea3d25a6850a36d0f8fb961b5e..eaac63f5eff415c8d7a5aec8fa815b70a3cbe433 100644 (file)
@@ -1,12 +1,18 @@
 #pragma once
 
+#if 1
+#define ITER_CONST const
+#else
+#define ITER_CONST
+#endif
+
 #define FOREACH_ARRAY(arr, start, end, cond, body) \
        MACRO_BEGIN \
        { \
                for (int _i = start; _i < end; ++_i) \
                { \
                        const noref int i = _i; \
-                       const noref entity it = arr[i]; \
+                       ITER_CONST noref entity it = arr[i]; \
                        if (cond) { LAMBDA(body) } \
                } \
        } MACRO_END
@@ -20,7 +26,7 @@
                for (entity _it = list##_first; _it; (_it = _it.next, ++_i)) \
                { \
                        const noref int i = _i; \
-                       const noref entity it = _it; \
+                       ITER_CONST noref entity it = _it; \
                        if (cond) { LAMBDA(body) } \
                } \
        } MACRO_END
@@ -88,7 +94,7 @@
                for (entity _it = NULL; (_it = nextent(_it)); ++_i) \
                { \
                        const noref int i = _i; \
-                       const noref entity it = _it; \
+                       ITER_CONST noref entity it = _it; \
                        if (cond) { LAMBDA(body) } \
                } \
        } MACRO_END
index 07d99b4f1226f73d843d0304e302d2439d6947e3..6afc862ed0a6306b97e2ad5ca02702b3a79a4817 100644 (file)
@@ -78,7 +78,7 @@ entity LL_POP(LinkedList this)
                noref int i = 0;                                                \
                for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i))  \
                {                                                               \
-                       noref entity it = _it.ll_data;                              \
+                       ITER_CONST noref entity it = _it.ll_data;                   \
                        if (cond) { body }                                          \
                }                                                               \
        } MACRO_END
index 8d50d2b929db771755e413826a5bee44b428c758..49147765e4f1d28ca943f975a359090d5a9d5981 100644 (file)
@@ -5,9 +5,9 @@
 #include "static.qh"
 
 #ifdef MENUQC
-       #define NULL (null_entity)
+       #define NULL (0, null_entity)
 #else
-       #define NULL (world)
+       #define NULL (0, world)
 #endif
 
 .vector origin;
index b52046037c973422e4465009bf2c920992c75915..c43605435e389cb13d1cbfb893d6fac48b43dcc7 100644 (file)
@@ -33,7 +33,7 @@ const string STR_OBSERVER = "observer";
                for(int _i = 1; _i <= maxclients; ++_i) \
                { \
                        const noref int i = _i; \
-                       const noref entity it = ftoe(i); \
+                       ITER_CONST noref entity it = ftoe(i); \
                        if(cond) { LAMBDA(body) } \
                } \
        } MACRO_END