]> icculus.org git repositories - taylor/freespace2.git/blob - include/linklist.h
re-add PXO sources to project files
[taylor/freespace2.git] / include / linklist.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/GlobalIncs/LinkList.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Macros to handle doubly linked lists
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:13  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 2     10/07/98 10:52a Dave
26  * Initial checkin.
27  * 
28  * 1     10/07/98 10:48a Dave
29  * 
30  * 5     7/01/97 11:53a Lawrance
31  * add list_insert_before()
32  * 
33  * 4     4/15/97 1:27p Lawrance
34  * added a GET_PREV() macro
35  * 
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
38  * them.
39  *
40  * $NoKeywords: $
41  */
42
43 #ifndef _LINKLIST_H
44 #define _LINKLIST_H
45
46 // Initializes a list of zero elements
47 #define list_init( head )                                       \
48 do {                                                                                            \
49         (head)->next = (head);                                  \
50         (head)->prev = (head);                                  \
51 } while (0)
52
53 // Inserts element onto the front of the list
54 #define list_insert( head, elem )               \
55 do {                                                                                            \
56         (elem)->next = (head)->next;                    \
57         (head)->next->prev = (elem);                    \
58         (head)->next = (elem);                                  \
59         (elem)->prev = (head);                                  \
60 } while (0)
61
62 // Inserts new_elem before elem
63 #define list_insert_before(elem, new_elem)              \
64 do {                                                                                                                    \
65         (elem)->prev->next      = (new_elem);                           \
66         (new_elem)->prev                = (elem)->prev;                 \
67         (elem)->prev                    = (new_elem);                           \
68         (new_elem)->next                = (elem);                                       \
69 } while (0)     
70
71 // Appends an element on to the tail of the list
72 #define list_append( head, elem )               \
73 do      {                                                                                               \
74         (elem)->prev = (head)->prev;                    \
75         (elem)->next = (head);                                  \
76         (head)->prev->next = (elem);                    \
77         (head)->prev = (elem);                                  \
78 } while (0)
79
80 // Adds list b onto the end of list a
81 #define list_merge( a, b )                                      \
82 do {                                                                                            \
83         (a)->prev->next = (b)->next;                    \
84         (b)->next->prev = (a)->prev;                    \
85         (a)->prev = (b)->prev;                                  \
86         (b)->prev->next = (a);                                  \
87 } while (0)
88
89 // Removes an element from listit's in
90 #define list_remove( head, elem )               \
91 do {                                                                                            \
92         (elem)->prev->next = (elem)->next;      \
93         (elem)->next->prev = (elem)->prev;      \
94         (elem)->next = NULL;                                            \
95         (elem)->prev = NULL;                                            \
96 } while(0)
97
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))
105
106 #endif
107