]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/linkedlist.qh
Purge other from blocked
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / linkedlist.qh
index a4200122f473452e3c76c4d9ca40c7d71e89c939..6afc862ed0a6306b97e2ad5ca02702b3a79a4817 100644 (file)
@@ -1,5 +1,4 @@
-#ifndef LINKEDLIST_H
-#define LINKEDLIST_H
+#pragma once
 
 CLASS(LinkedListNode, Object)
        ATTRIB(LinkedListNode, ll_data, entity, NULL)
@@ -45,30 +44,41 @@ entity LL_POP(LinkedList this)
        return e;
 }
 
-#define LL_DELETE(this) \
-       do \
+#define LL_CLEAR(...) EVAL_LL_CLEAR(OVERLOAD(LL_CLEAR, __VA_ARGS__))
+#define EVAL_LL_CLEAR(...) __VA_ARGS__
+#define LL_CLEAR_1(this) LL_CLEAR_2(this, LAMBDA())
+#define LL_CLEAR_2(this, dtor) \
+       MACRO_BEGIN \
        { \
                LinkedList _ll = this; \
                assert(_ll); \
                while (_ll.ll_tail) \
                { \
                        entity it = LL_POP(_ll); \
-                       if (it) remove(it); \
+                       if (!it) continue; \
+                       dtor \
+                       remove(it); \
                } \
+       } MACRO_END
+
+#define LL_DELETE(...) EVAL_LL_DELETE(OVERLOAD(LL_DELETE, __VA_ARGS__))
+#define EVAL_LL_DELETE(...) __VA_ARGS__
+#define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA())
+#define LL_DELETE_2(this, dtor) \
+       MACRO_BEGIN \
+       { \
+               LL_CLEAR_2(this, dtor); \
+               remove(this); \
                this = NULL; \
-       } \
-       while (0)
+       } MACRO_END
 
 #define LL_EACH(list, cond, body) \
-       do                                                                  \
+       MACRO_BEGIN                                                         \
        {                                                                   \
                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 }                                          \
                }                                                               \
-       }                                                                   \
-       while (0)
-
-#endif
+       } MACRO_END