2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/GlobalIncs/LinkList.h $
15 * Macros to handle doubly linked lists
18 * Revision 1.2 2002/06/09 04:41:13 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:12 root
25 * 2 10/07/98 10:52a Dave
28 * 1 10/07/98 10:48a Dave
30 * 5 7/01/97 11:53a Lawrance
31 * add list_insert_before()
33 * 4 4/15/97 1:27p Lawrance
34 * added a GET_PREV() macro
36 * 3 2/17/97 5:18p John
37 * Added a bunch of RCS headers to a bunch of old files that don't have
46 // Initializes a list of zero elements
47 #define list_init( head ) \
49 (head)->next = (head); \
50 (head)->prev = (head); \
53 // Inserts element onto the front of the list
54 #define list_insert( head, elem ) \
56 (elem)->next = (head)->next; \
57 (head)->next->prev = (elem); \
58 (head)->next = (elem); \
59 (elem)->prev = (head); \
62 // Inserts new_elem before elem
63 #define list_insert_before(elem, new_elem) \
65 (elem)->prev->next = (new_elem); \
66 (new_elem)->prev = (elem)->prev; \
67 (elem)->prev = (new_elem); \
68 (new_elem)->next = (elem); \
71 // Appends an element on to the tail of the list
72 #define list_append( head, elem ) \
74 (elem)->prev = (head)->prev; \
75 (elem)->next = (head); \
76 (head)->prev->next = (elem); \
77 (head)->prev = (elem); \
80 // Adds list b onto the end of list a
81 #define list_merge( a, b ) \
83 (a)->prev->next = (b)->next; \
84 (b)->next->prev = (a)->prev; \
85 (a)->prev = (b)->prev; \
86 (b)->prev->next = (a); \
89 // Removes an element from listit's in
90 #define list_remove( head, elem ) \
92 (elem)->prev->next = (elem)->next; \
93 (elem)->next->prev = (elem)->prev; \
94 (elem)->next = NULL; \
95 (elem)->prev = NULL; \
98 #define GET_FIRST(head) ((head)->next)
99 #define GET_LAST(head) ((head)->prev)
100 #define GET_NEXT(elem) ((elem)->next)
101 #define GET_PREV(elem) ((elem)->prev)
102 #define END_OF_LIST(head) (head)
103 #define NOT_EMPTY(head) ((head)->next != (head))
104 #define EMPTY(head) ((head)->next == (head))