[AMSTREAM] We don't need to define WIDL_C_INLINE_WRAPPERS here anymore.
[reactos.git] / dll / directx / wine / dplayx / dplayx_queue.h
1 /* A queue definition based on sys/queue.h TAILQ definitions
2 *
3 * Copyright 2000 Peter Hunnisett
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 * NOTES
20 * o Linked list implementation for dplay/dplobby. Based off of the BSD
21 * version found in <sys/queue.h>
22 * o Port it to <wine/list.h> ?
23 *
24 */
25
26 #ifndef __WINE_DPLAYX_QUEUE_H
27 #define __WINE_DPLAYX_QUEUE_H
28
29 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
30
31 /*
32 * Tail queue definitions.
33 */
34 #define DPQ_HEAD(type) \
35 struct { \
36 struct type *lpQHFirst; /* first element */ \
37 struct type **lpQHLast; /* addr of last next element */ \
38 }
39
40 #define DPQ_ENTRY(type) \
41 struct { \
42 struct type *lpQNext; /* next element */ \
43 struct type **lpQPrev; /* address of previous next element */ \
44 }
45
46 /*
47 * Tail queue functions.
48 */
49 #define DPQ_INIT(head) \
50 do{ \
51 (head).lpQHFirst = NULL; \
52 (head).lpQHLast = &(head).lpQHFirst; \
53 } while(0)
54
55 /* Front of the queue */
56 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
57
58 /* Check if the queue has any elements */
59 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
60
61 /* Next entry -- FIXME: Convert everything over to this macro ... */
62 #define DPQ_NEXT( elem ) (elem).lpQNext
63
64 #define DPQ_IS_ENDOFLIST( elem ) \
65 ( DPQ_NEXT(elem) == NULL )
66
67 /* Insert element at end of queue */
68 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
69 do { \
70 (elm)->field.lpQNext = NULL; \
71 (elm)->field.lpQPrev = (head).lpQHLast; \
72 *(head).lpQHLast = (elm); \
73 (head).lpQHLast = &(elm)->field.lpQNext; \
74 } while(0)
75
76 /* Remove element from the queue */
77 #define DPQ_REMOVE(head, elm, field) \
78 do { \
79 if (((elm)->field.lpQNext) != NULL) \
80 (elm)->field.lpQNext->field.lpQPrev = \
81 (elm)->field.lpQPrev; \
82 else \
83 (head).lpQHLast = (elm)->field.lpQPrev; \
84 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
85 } while(0)
86
87 /* head - pointer to DPQ_HEAD struct
88 * elm - how to find the next element
89 * field - to be concatenated to rc to compare with fieldToCompare
90 * fieldToCompare - The value that we're comparing against
91 * fieldCompareOperator - The logical operator to compare field and
92 * fieldToCompare.
93 * rc - Variable to put the return code. Same type as (head).lpQHFirst
94 */
95 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
96 do { \
97 (rc) = DPQ_FIRST(head); /* NULL head? */ \
98 \
99 while( rc ) \
100 { \
101 /* What we're searching for? */ \
102 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
103 { \
104 break; /* rc == correct element */ \
105 } \
106 \
107 /* End of list check */ \
108 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
109 { \
110 rc = NULL; \
111 break; \
112 } \
113 } \
114 } while(0)
115
116 /* head - pointer to DPQ_HEAD struct
117 * elm - how to find the next element
118 * field - to be concatenated to rc to compare with fieldToCompare
119 * fieldToCompare - The value that we're comparing against
120 * compare_cb - Callback to invoke to determine if comparison should continue.
121 * Callback must be defined with DPQ_DECL_COMPARECB.
122 * rc - Variable to put the return code. Same type as (head).lpQHFirst
123 */
124 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
125 do { \
126 (rc) = DPQ_FIRST(head); /* NULL head? */ \
127 \
128 while( rc ) \
129 { \
130 /* What we're searching for? */ \
131 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
132 { \
133 break; /* no more */ \
134 } \
135 \
136 /* End of list check */ \
137 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
138 { \
139 rc = NULL; \
140 break; \
141 } \
142 } \
143 } while(0)
144
145 /* How to define the method to be passed to DPQ_DELETEQ */
146 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
147
148
149 /* head - pointer to DPQ_HEAD struct
150 * elm - how to find the next element
151 * field - to be concatenated to rc to compare with fieldToEqual
152 * fieldToCompare - The value that we're comparing against
153 * fieldCompareOperator - The logical operator to compare field and
154 * fieldToCompare.
155 * rc - Variable to put the return code. Same type as (head).lpQHFirst
156 */
157 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
158 do { \
159 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
160 \
161 /* Was the element found? */ \
162 if( rc ) \
163 { \
164 DPQ_REMOVE( head, rc, elm ); \
165 } \
166 } while(0)
167
168 /* head - pointer to DPQ_HEAD struct
169 * elm - how to find the next element
170 * field - to be concatenated to rc to compare with fieldToCompare
171 * fieldToCompare - The value that we're comparing against
172 * compare_cb - Callback to invoke to determine if comparison should continue.
173 * Callback must be defined with DPQ_DECL_COMPARECB.
174 * rc - Variable to put the return code. Same type as (head).lpQHFirst
175 */
176 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
177 do { \
178 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
179 \
180 /* Was the element found? */ \
181 if( rc ) \
182 { \
183 DPQ_REMOVE( head, rc, elm ); \
184 } \
185 } while(0)
186
187
188 /* Delete the entire queue
189 * head - pointer to the head of the queue
190 * field - field to access the next elements of the queue
191 * type - type of the pointer to the element element
192 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
193 */
194 #define DPQ_DELETEQ( head, field, type, df ) \
195 do \
196 { \
197 while( !DPQ_IS_EMPTY(head) ) \
198 { \
199 type holder = DPQ_FIRST(head); \
200 DPQ_REMOVE( head, holder, field ); \
201 df( holder ); \
202 } \
203 } while(0)
204
205 /* How to define the method to be passed to DPQ_DELETEQ */
206 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
207
208 /* Prototype of a method which just performs a HeapFree on the elem */
209 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID ) DECLSPEC_HIDDEN;
210
211 #endif /* __WINE_DPLAYX_QUEUE_H */