ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dplayx_queue.h
Go to the documentation of this file.
00001 /* A queue definition based on sys/queue.h TAILQ definitions
00002  *
00003  * Copyright 2000 Peter Hunnisett
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  * NOTES
00020  *  o Linked list implementation for dplay/dplobby. Based off of the BSD
00021  *    version found in <sys/queue.h>
00022  *  o Port it to <wine/list.h> ?
00023  *
00024  */
00025 
00026 #ifndef __WINE_DPLAYX_QUEUE_H
00027 #define __WINE_DPLAYX_QUEUE_H
00028 
00029 #include <stdarg.h>
00030 
00031 #include "windef.h"
00032 #include "winbase.h"
00033 
00034 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
00035 
00036 /*
00037  * Tail queue definitions.
00038  */
00039 #define DPQ_HEAD(type)                                           \
00040 struct {                                                         \
00041         struct type *lpQHFirst; /* first element */              \
00042         struct type **lpQHLast; /* addr of last next element */  \
00043 }
00044 
00045 #define DPQ_ENTRY(type)                                               \
00046 struct {                                                              \
00047         struct type *lpQNext;  /* next element */                     \
00048         struct type **lpQPrev; /* address of previous next element */ \
00049 }
00050 
00051 /*
00052  * Tail queue functions.
00053  */
00054 #define DPQ_INIT(head)                       \
00055 do{                                          \
00056         (head).lpQHFirst = NULL;             \
00057         (head).lpQHLast = &(head).lpQHFirst; \
00058 } while(0)
00059 
00060 /* Front of the queue */
00061 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
00062 
00063 /* Check if the queue has any elements */
00064 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
00065 
00066 /* Next entry -- FIXME: Convert everything over to this macro ... */
00067 #define DPQ_NEXT( elem ) (elem).lpQNext
00068 
00069 #define DPQ_IS_ENDOFLIST( elem ) \
00070     ( DPQ_NEXT(elem) == NULL )
00071 
00072 /* Insert element at end of queue */
00073 #define DPQ_INSERT_IN_TAIL(head, elm, field)     \
00074 do {                                             \
00075         (elm)->field.lpQNext = NULL;             \
00076         (elm)->field.lpQPrev = (head).lpQHLast;  \
00077         *(head).lpQHLast = (elm);                \
00078         (head).lpQHLast = &(elm)->field.lpQNext; \
00079 } while(0)
00080 
00081 /* Remove element from the queue */
00082 #define DPQ_REMOVE(head, elm, field)                    \
00083 do {                                                    \
00084         if (((elm)->field.lpQNext) != NULL)             \
00085                 (elm)->field.lpQNext->field.lpQPrev =   \
00086                     (elm)->field.lpQPrev;               \
00087         else                                            \
00088                 (head).lpQHLast = (elm)->field.lpQPrev; \
00089         *(elm)->field.lpQPrev = (elm)->field.lpQNext;   \
00090 } while(0)
00091 
00092 /* head - pointer to DPQ_HEAD struct
00093  * elm  - how to find the next element
00094  * field - to be concatenated to rc to compare with fieldToCompare
00095  * fieldToCompare - The value that we're comparing against
00096  * fieldCompareOperator - The logical operator to compare field and
00097  *                        fieldToCompare.
00098  * rc - Variable to put the return code. Same type as (head).lpQHFirst
00099  */
00100 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
00101 do {                                                           \
00102   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
00103                                                                \
00104   while( rc )                                                  \
00105   {                                                            \
00106       /* What we're searching for? */                          \
00107       if( (rc)->field fieldCompareOperator (fieldToCompare) )  \
00108       {                                                        \
00109         break; /* rc == correct element */                     \
00110       }                                                        \
00111                                                                \
00112       /* End of list check */                                  \
00113       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
00114       {                                                        \
00115         rc = NULL;                                             \
00116         break;                                                 \
00117       }                                                        \
00118   }                                                            \
00119 } while(0)
00120 
00121 /* head - pointer to DPQ_HEAD struct
00122  * elm  - how to find the next element
00123  * field - to be concatenated to rc to compare with fieldToCompare
00124  * fieldToCompare - The value that we're comparing against
00125  * compare_cb - Callback to invoke to determine if comparision should continue.
00126  *              Callback must be defined with DPQ_DECL_COMPARECB.
00127  * rc - Variable to put the return code. Same type as (head).lpQHFirst
00128  */
00129 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
00130 do {                                                           \
00131   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
00132                                                                \
00133   while( rc )                                                  \
00134   {                                                            \
00135       /* What we're searching for? */                          \
00136       if( compare_cb( &((rc)->field), &(fieldToCompare) ) )    \
00137       {                                                        \
00138         break; /* no more */                                   \
00139       }                                                        \
00140                                                                \
00141       /* End of list check */                                  \
00142       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
00143       {                                                        \
00144         rc = NULL;                                             \
00145         break;                                                 \
00146       }                                                        \
00147   }                                                            \
00148 } while(0)
00149 
00150 /* How to define the method to be passed to DPQ_DELETEQ */
00151 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
00152 
00153 
00154 /* head - pointer to DPQ_HEAD struct
00155  * elm  - how to find the next element
00156  * field - to be concatenated to rc to compare with fieldToEqual
00157  * fieldToCompare - The value that we're comparing against
00158  * fieldCompareOperator - The logical operator to compare field and
00159  *                        fieldToCompare.
00160  * rc - Variable to put the return code. Same type as (head).lpQHFirst
00161  */
00162 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
00163 do {                                                           \
00164   DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
00165                                                                \
00166   /* Was the element found? */                                 \
00167   if( rc )                                                     \
00168   {                                                            \
00169     DPQ_REMOVE( head, rc, elm );                               \
00170   }                                                            \
00171 } while(0)
00172 
00173 /* head - pointer to DPQ_HEAD struct
00174  * elm  - how to find the next element
00175  * field - to be concatenated to rc to compare with fieldToCompare
00176  * fieldToCompare - The value that we're comparing against
00177  * compare_cb - Callback to invoke to determine if comparision should continue.
00178  *              Callback must be defined with DPQ_DECL_COMPARECB.
00179  * rc - Variable to put the return code. Same type as (head).lpQHFirst
00180  */
00181 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
00182 do {                                                           \
00183   DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
00184                                                                \
00185   /* Was the element found? */                                 \
00186   if( rc )                                                     \
00187   {                                                            \
00188     DPQ_REMOVE( head, rc, elm );                               \
00189   }                                                            \
00190 } while(0)
00191 
00192 
00193 /* Delete the entire queue
00194  * head - pointer to the head of the queue
00195  * field - field to access the next elements of the queue
00196  * type - type of the pointer to the element element
00197  * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
00198  */
00199 #define DPQ_DELETEQ( head, field, type, df )     \
00200 do                                               \
00201 {                                                \
00202   while( !DPQ_IS_EMPTY(head) )                   \
00203   {                                              \
00204     type holder = DPQ_FIRST(head);               \
00205     DPQ_REMOVE( head, holder, field );           \
00206     df( holder );                                \
00207   }                                              \
00208 } while(0)
00209 
00210 /* How to define the method to be passed to DPQ_DELETEQ */
00211 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
00212 
00213 /* Prototype of a method which just performs a HeapFree on the elem */
00214 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
00215 
00216 #endif /* __WINE_DPLAYX_QUEUE_H */

Generated on Sun May 27 2012 04:21:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.