4 CLASS(LinkedListNode, Object)
5 ATTRIB(LinkedListNode, ll_data, entity, NULL)
6 ATTRIB(LinkedListNode, ll_prev, LinkedListNode, NULL)
7 ATTRIB(LinkedListNode, ll_next, LinkedListNode, NULL)
8 ENDCLASS(LinkedListNode)
10 CLASS(LinkedList, Object)
11 ATTRIB(LinkedList, ll_head, LinkedListNode, NULL);
12 ATTRIB(LinkedList, ll_tail, LinkedListNode, NULL);
15 #define LL_NEW() NEW(LinkedList)
17 #define LL_EMPTY(ll) (ll.ll_head == NULL)
22 entity LL_PUSH(LinkedList this, entity e)
25 LinkedListNode n = NEW(LinkedListNode);
27 LinkedListNode tail = n.ll_prev = this.ll_tail;
28 this.ll_tail = (tail) ? tail.ll_next = n : this.ll_head = n;
35 entity LL_POP(LinkedList this)
38 if (!this.ll_tail) return NULL;
39 LinkedListNode n = this.ll_tail;
41 LinkedListNode prev = n.ll_prev;
42 if (prev) (this.ll_tail = prev).ll_next = NULL;
43 else this.ll_head = this.ll_tail = NULL;
48 #define LL_CLEAR(...) EVAL_LL_CLEAR(OVERLOAD(LL_CLEAR, __VA_ARGS__))
49 #define EVAL_LL_CLEAR(...) __VA_ARGS__
50 #define LL_CLEAR_1(this) LL_CLEAR_2(this, LAMBDA())
51 #define LL_CLEAR_2(this, dtor) \
54 LinkedList _ll = this; \
58 entity it = LL_POP(_ll); \
65 #define LL_DELETE(...) EVAL_LL_DELETE(OVERLOAD(LL_DELETE, __VA_ARGS__))
66 #define EVAL_LL_DELETE(...) __VA_ARGS__
67 #define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA())
68 #define LL_DELETE_2(this, dtor) \
71 LL_CLEAR(this, dtor); \
76 #define LL_EACH(list, cond, body) \
80 for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) \
82 noref entity it = _it.ll_data; \