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