Removed all RCS / CVS tags (Id, Header, Date, etc.) from everything.
[mesa.git] / src / mesa / main / simple_list.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.5
5 *
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /* Simple macros for typesafe, intrusive lists.
27 * (C) 1997, Keith Whitwell
28 *
29 * Intended to work with a list sentinal which is created as an empty
30 * list. Insert & delete are O(1).
31 */
32
33
34 #ifndef _SIMPLE_LIST_H
35 #define _SIMPLE_LIST_H
36
37 #define remove_from_list(elem) \
38 do { \
39 (elem)->next->prev = (elem)->prev; \
40 (elem)->prev->next = (elem)->next; \
41 } while (0)
42
43 #define insert_at_head(list, elem) \
44 do { \
45 (elem)->prev = list; \
46 (elem)->next = (list)->next; \
47 (list)->next->prev = elem; \
48 (list)->next = elem; \
49 } while(0)
50
51 #define insert_at_tail(list, elem) \
52 do { \
53 (elem)->next = list; \
54 (elem)->prev = (list)->prev; \
55 (list)->prev->next = elem; \
56 (list)->prev = elem; \
57 } while(0)
58
59 #define move_to_head(list, elem) \
60 do { \
61 remove_from_list(elem); \
62 insert_at_head(list, elem); \
63 } while (0)
64
65 #define move_to_tail(list, elem) \
66 do { \
67 remove_from_list(elem); \
68 insert_at_tail(list, elem); \
69 } while (0)
70
71
72 #define make_empty_list(sentinal) \
73 do { \
74 (sentinal)->next = sentinal; \
75 (sentinal)->prev = sentinal; \
76 } while (0)
77
78
79 #define first_elem(list) ((list)->next)
80 #define last_elem(list) ((list)->prev)
81 #define next_elem(elem) ((elem)->next)
82 #define prev_elem(elem) ((elem)->prev)
83 #define at_end(list, elem) ((elem) == (list))
84 #define is_empty_list(list) ((list)->next == (list))
85
86 #define foreach(ptr, list) \
87 for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
88
89 /* Kludgey - Lets you unlink the current value during a list
90 * traversal. Useful for free()-ing a list, element
91 * by element.
92 */
93 #define foreach_s(ptr, t, list) \
94 for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)
95
96
97 #endif