]> git.meshlink.io Git - catta/blob - avahi-common/llist.h
Include qt mainloop adapter in build system. Moc finding code is cracktastic thanks to
[catta] / avahi-common / llist.h
1 #ifndef foollistfoo
2 #define foollistfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of avahi.
8  
9   avahi is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13  
14   avahi is distributed in the hope that it will be useful, but WITHOUT
15   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17   Public License for more details.
18  
19   You should have received a copy of the GNU Lesser General Public
20   License along with avahi; 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 #include <assert.h>
28
29 /* The head of the linked list. Use this in the structure that shall
30  * contain the head of the linked list */
31 #define AVAHI_LLIST_HEAD(t,name) t *name
32
33 /* The pointers in the linked list's items. Use this in the item structure */
34 #define AVAHI_LLIST_FIELDS(t,name) t *name##_next, *name##_prev
35
36 /* Initialize the list's head */
37 #define AVAHI_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0)
38
39 /* Initialize a list item */
40 #define AVAHI_LLIST_INIT(t,name,item) do { \
41                                t *_item = (item); \
42                                assert(_item); \
43                                _item->name##_prev = _item->name##_next = NULL; \
44                                } while(0)
45
46 /* Prepend an item to the list */
47 #define AVAHI_LLIST_PREPEND(t,name,head,item) do { \
48                                         t **_head = &(head), *_item = (item); \
49                                         assert(_item); \
50                                         if ((_item->name##_next = *_head)) \
51                                            _item->name##_next->name##_prev = _item; \
52                                         _item->name##_prev = NULL; \
53                                         *_head = _item; \
54                                         } while (0)
55
56 /* Remove an item from the list */
57 #define AVAHI_LLIST_REMOVE(t,name,head,item) do { \
58                                     t **_head = &(head), *_item = (item); \
59                                     assert(_item); \
60                                     if (_item->name##_next) \
61                                        _item->name##_next->name##_prev = _item->name##_prev; \
62                                     if (_item->name##_prev) \
63                                        _item->name##_prev->name##_next = _item->name##_next; \
64                                     else {\
65                                        assert(*_head == _item); \
66                                        *_head = _item->name##_next; \
67                                     } \
68                                     _item->name##_next = _item->name##_prev = NULL; \
69                                     } while(0)
70
71 #endif