3 * Copyright (C) 2003,2004 Develer S.r.l. (http://www.develer.com/)
4 * Copyright (C) 2001 Bernardo Innocenti <bernie@develer.com>
5 * This file is part of DevLib - See devlib/README for information.
9 * \author Bernardo Innocenti <bernie@develer.com>
11 * \brief General pourpose double-linked lists
16 *#* Revision 1.7 2004/08/25 14:12:09 rasky
17 *#* Aggiornato il comment block dei log RCS
19 *#* Revision 1.6 2004/07/30 14:34:10 rasky
20 *#* Vari fix per documentazione e commenti
21 *#* Aggiunte PP_CATn e STATIC_ASSERT
23 *#* Revision 1.5 2004/07/20 23:45:01 bernie
24 *#* Finally remove redundant protos.
26 *#* Revision 1.4 2004/07/18 22:12:53 bernie
27 *#* Fix warnings with GCC 3.3.2.
29 *#* Revision 1.3 2004/07/18 22:01:43 bernie
30 *#* REMHEAD(), REMTAIL(): Move to list.h as inline functions.
32 *#* Revision 1.2 2004/06/03 11:27:09 bernie
33 *#* Add dual-license information.
35 *#* Revision 1.1 2004/05/23 15:43:16 bernie
36 *#* Import mware modules.
56 /*! Template for a list of \a T structures */
57 #define DECLARE_LIST(T) \
58 struct { T *head; T *null; T *tail; }
60 /*! Template for a node in a list of \a T structures */
61 #define DECLARE_NODE(T) \
62 struct { T *succ; T *pred; }
64 /*! Template for a node in a list of \a T structures */
65 #define DECLARE_NODE_ANON(T) \
69 * Iterate over all nodes in a list. This statement defines a for cicle
70 * accepting the following parameters:
71 * \param n node pointer to be used in each iteration
72 * \param l pointer to list
74 #define FOREACHNODE(n,l) \
76 (n) = (typeof(n))((l)->head); \
77 ((Node *)(n))->succ; \
78 (n) = (typeof(n))(((Node *)(n))->succ) \
81 /*! Initialize a list */
84 (l)->head = (Node *)(&(l)->null); \
86 (l)->tail = (Node *)(&(l)->head); \
89 /*! Add node to list head */
90 #define ADDHEAD(l,n) \
92 (n)->succ = (l)->head; \
93 (n)->pred = (Node *)&(l)->head; \
94 (n)->succ->pred = (n); \
98 /*! Add node to list tail */
99 #define ADDTAIL(l,n) \
101 (n)->succ = (Node *)(&(l)->null); \
102 (n)->pred = (l)->tail; \
103 (n)->pred->succ = (n); \
108 * Insert node \a n before node \a ln
109 * Note: you can't pass in a list header as \a ln, but
110 * it is safe to pass list-\>head of an empty list.
112 #define INSERTBEFORE(n,ln) \
115 (n)->pred = (ln)->pred; \
116 (ln)->pred->succ = (n); \
120 /*! Remove \a n from whatever list it is in */
123 (n)->pred->succ = (n)->succ; \
124 (n)->succ->pred = (n)->pred; \
127 /*! Tell whether a list is empty */
128 #define ISLISTEMPTY(l) ( (l)->head == (Node *)(&(l)->null) )
131 * Unlink a node from the head of the list \a l.
132 * \return Pointer to node, or NULL if the list was empty.
134 INLINE Node *REMHEAD(List *l)
143 n->succ->pred = (Node *)l;
148 * Unlink a node from the tail of the list \a l.
149 * \return Pointer to node, or NULL if the list was empty.
151 INLINE Node *REMTAIL(List *l)
160 n->pred->succ = (Node *)&l->null;
164 #endif /* MWARE_LIST_H */