Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

LinkList.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
00003  *
00004  * All source code herein is the property of Volition, Inc. You may not sell 
00005  * or otherwise commercially exploit the source or things you created based on the 
00006  * source.
00007  *
00008 */ 
00009 
00010 /*
00011  * $Logfile: /Freespace2/code/GlobalIncs/LinkList.h $
00012  * $Revision: 2 $
00013  * $Date: 10/07/98 10:52a $
00014  * $Author: Dave $
00015  *
00016  * Macros to handle doubly linked lists
00017  *
00018  * $Log: /Freespace2/code/GlobalIncs/LinkList.h $
00019  * 
00020  * 2     10/07/98 10:52a Dave
00021  * Initial checkin.
00022  * 
00023  * 1     10/07/98 10:48a Dave
00024  * 
00025  * 5     7/01/97 11:53a Lawrance
00026  * add list_insert_before()
00027  * 
00028  * 4     4/15/97 1:27p Lawrance
00029  * added a GET_PREV() macro
00030  * 
00031  * 3     2/17/97 5:18p John
00032  * Added a bunch of RCS headers to a bunch of old files that don't have
00033  * them.
00034  *
00035  * $NoKeywords: $
00036  */
00037 
00038 #ifndef _LINKLIST_H
00039 #define _LINKLIST_H
00040 
00041 // Initializes a list of zero elements
00042 #define list_init( head )                                       \
00043 do {                                                                                            \
00044         (head)->next = (head);                                  \
00045         (head)->prev = (head);                                  \
00046 } while (0)
00047 
00048 // Inserts element onto the front of the list
00049 #define list_insert( head, elem )               \
00050 do {                                                                                            \
00051         (elem)->next = (head)->next;                    \
00052         (head)->next->prev = (elem);                    \
00053         (head)->next = (elem);                                  \
00054         (elem)->prev = (head);                                  \
00055 } while (0)
00056 
00057 // Inserts new_elem before elem
00058 #define list_insert_before(elem, new_elem)              \
00059 do {                                                                                                                    \
00060         (elem)->prev->next      = (new_elem);                           \
00061         (new_elem)->prev                = (elem)->prev;                 \
00062         (elem)->prev                    = (new_elem);                           \
00063         (new_elem)->next                = (elem);                                       \
00064 } while (0)     
00065 
00066 // Appends an element on to the tail of the list
00067 #define list_append( head, elem )               \
00068 do      {                                                                                               \
00069         (elem)->prev = (head)->prev;                    \
00070         (elem)->next = (head);                                  \
00071         (head)->prev->next = (elem);                    \
00072         (head)->prev = (elem);                                  \
00073 } while (0)
00074 
00075 // Adds list b onto the end of list a
00076 #define list_merge( a, b )                                      \
00077 do {                                                                                            \
00078         (a)->prev->next = (b)->next;                    \
00079         (b)->next->prev = (a)->prev;                    \
00080         (a)->prev = (b)->prev;                                  \
00081         (b)->prev->next = (a);                                  \
00082 } while (0)
00083 
00084 // Removes an element from listit's in
00085 #define list_remove( head, elem )               \
00086 do {                                                                                            \
00087         (elem)->prev->next = (elem)->next;      \
00088         (elem)->next->prev = (elem)->prev;      \
00089         (elem)->next = NULL;                                            \
00090         (elem)->prev = NULL;                                            \
00091 } while(0)
00092 
00093 #define GET_FIRST(head)         ((head)->next)
00094 #define GET_LAST(head)          ((head)->prev)
00095 #define GET_NEXT(elem)          ((elem)->next)
00096 #define GET_PREV(elem)          ((elem)->prev)
00097 #define END_OF_LIST(head)       (head)
00098 #define NOT_EMPTY(head)         ((head)->next != (head))
00099 #define EMPTY(head)                     ((head)->next == (head))
00100 
00101 #endif

Generated on Mon Jul 8 11:28:29 2002 for fs2source_released by doxygen1.2.16