Correct struct tag name for UDACCEL.
[wine] / include / wine / list.h
1 /*
2  * Linked lists support
3  *
4  * Copyright (C) 2002 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_SERVER_LIST_H
22 #define __WINE_SERVER_LIST_H
23
24 struct list
25 {
26     struct list *next;
27     struct list *prev;
28 };
29
30 /* add an element after the specified one */
31 inline static void list_add_after( struct list *elem, struct list *to_add )
32 {
33     to_add->next = elem->next;
34     to_add->prev = elem;
35     elem->next->prev = to_add;
36     elem->next = to_add;
37 }
38
39 /* add an element before the specified one */
40 inline static void list_add_before( struct list *elem, struct list *to_add )
41 {
42     to_add->next = elem;
43     to_add->prev = elem->prev;
44     elem->prev->next = to_add;
45     elem->prev = to_add;
46 }
47
48 /* add element at the head of the list */
49 inline static void list_add_head( struct list *list, struct list *elem )
50 {
51     list_add_after( list, elem );
52 }
53
54 /* add element at the tail of the list */
55 inline static void list_add_tail( struct list *list, struct list *elem )
56 {
57     list_add_before( list, elem );
58 }
59
60 /* remove an element from its list */
61 inline static void list_remove( struct list *elem )
62 {
63     elem->next->prev = elem->prev;
64     elem->prev->next = elem->next;
65 }
66
67 /* get the next element */
68 inline static struct list *list_next( struct list *list, struct list *elem )
69 {
70     struct list *ret = elem->next;
71     if (elem->next == list) ret = NULL;
72     return ret;
73 }
74
75 /* get the previous element */
76 inline static struct list *list_prev( struct list *list, struct list *elem )
77 {
78     struct list *ret = elem->prev;
79     if (elem->prev == list) ret = NULL;
80     return ret;
81 }
82
83 /* get the first element */
84 inline static struct list *list_head( struct list *list )
85 {
86     return list_next( list, list );
87 }
88
89 /* get the last element */
90 inline static struct list *list_tail( struct list *list )
91 {
92     return list_prev( list, list );
93 }
94
95 /* check if a list is empty */
96 inline static int list_empty( struct list *list )
97 {
98     return list->next == list;
99 }
100
101 /* initialize a list */
102 inline static void list_init( struct list *list )
103 {
104     list->next = list->prev = list;
105 }
106
107 /* iterate through the list */
108 #define LIST_FOR_EACH(cursor,list) \
109     for ((cursor) = (list)->next; (cursor) != (list); (cursor) = (cursor)->next)
110
111 /* macros for statically initialized lists */
112 #define LIST_INIT(list)  { &(list), &(list) }
113
114 /* get pointer to object containing list element */
115 #define LIST_ENTRY(elem, type, field) \
116     ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field)))
117
118 #endif  /* __WINE_SERVER_LIST_H */