]> code.delx.au - pulseaudio/blob - src/polypcore/llist.h
c54742d3276a755901fccde31d180f3fa7267d7e
[pulseaudio] / src / polypcore / llist.h
1 #ifndef foollistfoo
2 #define foollistfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 /* Some macros for maintaining doubly linked lists */
26
27 /* The head of the linked list. Use this in the structure that shall
28 * contain the head of the linked list */
29 #define PA_LLIST_HEAD(t,name) t *name
30
31 /* The pointers in the linked list's items. Use this in the item structure */
32 #define PA_LLIST_FIELDS(t) t *next, *prev
33
34 /* Initialize the list's head */
35 #define PA_LLIST_HEAD_INIT(t,item) do { (item) = NULL; } while(0)
36
37 /* Initialize a list item */
38 #define PA_LLIST_INIT(t,item) do { \
39 t *_item = (item); \
40 assert(_item); \
41 _item->prev = _item->next = NULL; \
42 } while(0)
43
44 /* Prepend an item to the list */
45 #define PA_LLIST_PREPEND(t,head,item) do { \
46 t **_head = &(head), *_item = (item); \
47 assert(_item); \
48 if ((_item->next = *_head)) \
49 _item->next->prev = _item; \
50 _item->prev = NULL; \
51 *_head = _item; \
52 } while (0)
53
54 /* Remove an item from the list */
55 #define PA_LLIST_REMOVE(t,head,item) do { \
56 t **_head = &(head), *_item = (item); \
57 assert(_item); \
58 if (_item->next) \
59 _item->next->prev = _item->prev; \
60 if (_item->prev) \
61 _item->prev->next = _item->next; \
62 else {\
63 assert(*_head == _item); \
64 *_head = _item->next; \
65 } \
66 _item->next = _item->prev = NULL; \
67 } while(0)
68
69 #define PA_LLIST_FIND_HEAD(t,item,head) \
70 do { \
71 t **_head = (head), *_item = (item); \
72 *_head = _item; \
73 assert(_head); \
74 while ((*_head)->prev) \
75 *_head = (*_head)->prev; \
76 } while (0) \
77
78
79 #endif