Added sprintfW and vsprintfW.
[wine] / dlls / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef __WINE_DPLAYX_QUEUE_H
21 #define __WINE_DPLAYX_QUEUE_H
22
23 #include "winbase.h"
24
25 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
26
27 /*
28  * Tail queue definitions.
29  */
30 #define DPQ_HEAD(type)                                           \
31 struct {                                                         \
32         struct type *lpQHFirst; /* first element */              \
33         struct type **lpQHLast; /* addr of last next element */  \
34 }
35
36 #define DPQ_ENTRY(type)                                               \
37 struct {                                                              \
38         struct type *lpQNext;  /* next element */                     \
39         struct type **lpQPrev; /* address of previous next element */ \
40 }
41
42 /*
43  * Tail queue functions.
44  */
45 #define DPQ_INIT(head)                       \
46 do{                                          \
47         (head).lpQHFirst = NULL;             \
48         (head).lpQHLast = &(head).lpQHFirst; \
49 } while(0)
50
51 /* Front of the queue */
52 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
53
54 /* Check if the queue has any elements */
55 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
56
57 /* Next entry -- FIXME: Convert everything over to this macro ... */
58 #define DPQ_NEXT( elem ) (elem).lpQNext
59
60 #define DPQ_IS_ENDOFLIST( elem ) \
61     ( DPQ_NEXT(elem) == NULL )
62
63 /* Insert element at end of queue */
64 #define DPQ_INSERT_IN_TAIL(head, elm, field)     \
65 do {                                             \
66         (elm)->field.lpQNext = NULL;             \
67         (elm)->field.lpQPrev = (head).lpQHLast;  \
68         *(head).lpQHLast = (elm);                \
69         (head).lpQHLast = &(elm)->field.lpQNext; \
70 } while(0)
71
72 /* Remove element from the queue */
73 #define DPQ_REMOVE(head, elm, field)                    \
74 do {                                                    \
75         if (((elm)->field.lpQNext) != NULL)             \
76                 (elm)->field.lpQNext->field.lpQPrev =   \
77                     (elm)->field.lpQPrev;               \
78         else                                            \
79                 (head).lpQHLast = (elm)->field.lpQPrev; \
80         *(elm)->field.lpQPrev = (elm)->field.lpQNext;   \
81 } while(0)
82
83 /* head - pointer to DPQ_HEAD struct
84  * elm  - how to find the next element
85  * field - to be concatenated to rc to compare with fieldToCompare
86  * fieldToCompare - The value that we're comparing against
87  * fieldCompareOperator - The logical operator to compare field and
88  *                        fieldToCompare.
89  * rc - Variable to put the return code. Same type as (head).lpQHFirst
90  */
91 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
92 do {                                                           \
93   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
94                                                                \
95   while( rc )                                                  \
96   {                                                            \
97       /* What we're searching for? */                          \
98       if( (rc)->field fieldCompareOperator (fieldToCompare) )  \
99       {                                                        \
100         break; /* rc == correct element */                     \
101       }                                                        \
102                                                                \
103       /* End of list check */                                  \
104       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
105       {                                                        \
106         rc = NULL;                                             \
107         break;                                                 \
108       }                                                        \
109   }                                                            \
110 } while(0)
111
112 /* head - pointer to DPQ_HEAD struct
113  * elm  - how to find the next element
114  * field - to be concatenated to rc to compare with fieldToCompare
115  * fieldToCompare - The value that we're comparing against
116  * compare_cb - Callback to invoke to determine if comparision should continue.
117  *              Callback must be defined with DPQ_DECL_COMPARECB.
118  * rc - Variable to put the return code. Same type as (head).lpQHFirst
119  */
120 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
121 do {                                                           \
122   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
123                                                                \
124   while( rc )                                                  \
125   {                                                            \
126       /* What we're searching for? */                          \
127       if( compare_cb( &((rc)->field), &(fieldToCompare) ) )    \
128       {                                                        \
129         break; /* no more */                                   \
130       }                                                        \
131                                                                \
132       /* End of list check */                                  \
133       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
134       {                                                        \
135         rc = NULL;                                             \
136         break;                                                 \
137       }                                                        \
138   }                                                            \
139 } while(0)
140
141 /* How to define the method to be passed to DPQ_DELETEQ */
142 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
143
144
145 /* head - pointer to DPQ_HEAD struct
146  * elm  - how to find the next element
147  * field - to be concatenated to rc to compare with fieldToEqual
148  * fieldToCompare - The value that we're comparing against
149  * fieldCompareOperator - The logical operator to compare field and
150  *                        fieldToCompare.
151  * rc - Variable to put the return code. Same type as (head).lpQHFirst
152  */
153 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
154 do {                                                           \
155   DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
156                                                                \
157   /* Was the element found? */                                 \
158   if( rc )                                                     \
159   {                                                            \
160     DPQ_REMOVE( head, rc, elm );                               \
161   }                                                            \
162 } while(0)
163
164 /* head - pointer to DPQ_HEAD struct
165  * elm  - how to find the next element
166  * field - to be concatenated to rc to compare with fieldToCompare
167  * fieldToCompare - The value that we're comparing against
168  * compare_cb - Callback to invoke to determine if comparision should continue.
169  *              Callback must be defined with DPQ_DECL_COMPARECB.
170  * rc - Variable to put the return code. Same type as (head).lpQHFirst
171  */
172 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
173 do {                                                           \
174   DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
175                                                                \
176   /* Was the element found? */                                 \
177   if( rc )                                                     \
178   {                                                            \
179     DPQ_REMOVE( head, rc, elm );                               \
180   }                                                            \
181 } while(0)
182
183
184 /* Delete the entire queue
185  * head - pointer to the head of the queue
186  * field - field to access the next elements of the queue
187  * type - type of the pointer to the element element
188  * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
189  */
190 #define DPQ_DELETEQ( head, field, type, df )     \
191 do                                               \
192 {                                                \
193   while( !DPQ_IS_EMPTY(head) )                   \
194   {                                              \
195     type holder = DPQ_FIRST(head);               \
196     DPQ_REMOVE( head, holder, field );           \
197     df( holder );                                \
198   }                                              \
199 } while(0)
200
201 /* How to define the method to be passed to DPQ_DELETEQ */
202 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
203
204 /* Prototype of a method which just performs a HeapFree on the elem */
205 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
206
207 #endif /* __WINE_DPLAYX_QUEUE_H */