X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Flinkedlist.qh;h=6afc862ed0a6306b97e2ad5ca02702b3a79a4817;hb=b31c13cbd4fb79981e881e0599caf01d9d8dfd62;hp=19d72ac27e0a1209043b79e76d915d219cb3eeab;hpb=0ddc1f98883661f494e7d231432b6c1c81f7b205;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index 19d72ac27..6afc862ed 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -1,5 +1,4 @@ -#ifndef LINKEDLIST_H -#define LINKEDLIST_H +#pragma once CLASS(LinkedListNode, Object) ATTRIB(LinkedListNode, ll_data, entity, NULL) @@ -45,10 +44,11 @@ entity LL_POP(LinkedList this) return e; } -#define LL_DELETE(...) EVAL(OVERLOAD(LL_DELETE, __VA_ARGS__)) -#define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA()) -#define LL_DELETE_2(this, dtor) \ - 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); \ @@ -59,20 +59,26 @@ entity LL_POP(LinkedList this) 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