Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
linkedlist.qh
Go to the documentation of this file.
1#pragma once
2
8
13
14#define LL_NEW() NEW(LinkedList)
15
16#define LL_EMPTY(ll) (ll.ll_head == NULL)
17
20{
21 assert(this);
23 n.ll_data = e;
24 LinkedListNode tail = n.ll_prev = this.ll_tail;
25 this.ll_tail = (tail) ? tail.ll_next = n : this.ll_head = n;
26 return e;
27}
28
31{
32 assert(this);
33 if (!this.ll_tail)
34 return NULL;
35 LinkedListNode n = this.ll_tail;
36 entity e = n.ll_data;
37 LinkedListNode prev = n.ll_prev;
38 if (prev)
39 (this.ll_tail = prev).ll_next = NULL;
40 else
41 this.ll_head = this.ll_tail = NULL;
42 delete(n);
43 return e;
44}
45
46#define LL_CLEAR(...) EVAL_LL_CLEAR(OVERLOAD(LL_CLEAR, __VA_ARGS__))
47#define EVAL_LL_CLEAR(...) __VA_ARGS__
48#define LL_CLEAR_1(this) LL_CLEAR_2(this, LAMBDA())
49#define LL_CLEAR_2(this, dtor) MACRO_BEGIN \
50 LinkedList _ll = this; \
51 assert(_ll); \
52 while (_ll.ll_tail) \
53 { \
54 entity it = LL_POP(_ll); \
55 if (!it) \
56 continue; \
57 dtor \
58 delete(it); \
59 } \
60MACRO_END
61
62#define LL_DELETE(...) EVAL_LL_DELETE(OVERLOAD(LL_DELETE, __VA_ARGS__))
63#define EVAL_LL_DELETE(...) __VA_ARGS__
64#define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA())
65#define LL_DELETE_2(this, dtor) \
66 MACRO_BEGIN \
67 LL_CLEAR_2(this, dtor); \
68 delete(this); \
69 this = NULL; \
70 MACRO_END
71
72#define LL_EACH(list, cond, body) MACRO_BEGIN \
73 noref int i = 0; \
74 for (entity _it = list.ll_head; _it; _it = _it.ll_next, ++i) \
75 { \
76 ITER_CONST noref entity it = _it.ll_data; \
77 if (cond) \
78 LAMBDA(body) \
79 } \
80MACRO_END
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
ATTRIB(LinkedListNode, ll_data, entity)
ATTRIB(LinkedList, ll_head, LinkedListNode)
prev
Definition all.qh:53
entity LL_POP(LinkedList this)
Pop from tail.
Definition linkedlist.qh:30
entity LL_PUSH(LinkedList this, entity e)
Push to tail.
Definition linkedlist.qh:19
#define assert(expr,...)
Definition log.qh:8
#define NEW(cname,...)
Definition oo.qh:120
#define CLASS(...)
Definition oo.qh:149
#define ENDCLASS(cname)
Definition oo.qh:286
#define NULL
Definition post.qh:14