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.6 2004/07/30 14:34:10 rasky
17 * Vari fix per documentazione e commenti
18 * Aggiunte PP_CATn e STATIC_ASSERT
20 * Revision 1.5 2004/07/20 23:45:01 bernie
21 * Finally remove redundant protos.
23 * Revision 1.4 2004/07/18 22:12:53 bernie
24 * Fix warnings with GCC 3.3.2.
26 * Revision 1.3 2004/07/18 22:01:43 bernie
27 * REMHEAD(), REMTAIL(): Move to list.h as inline functions.
29 * Revision 1.2 2004/06/03 11:27:09 bernie
30 * Add dual-license information.
32 * Revision 1.1 2004/05/23 15:43:16 bernie
33 * Import mware modules.
53 /*! Template for a list of \a T structures */
54 #define DECLARE_LIST(T) \
55 struct { T *head; T *null; T *tail; }
57 /*! Template for a node in a list of \a T structures */
58 #define DECLARE_NODE(T) \
59 struct { T *succ; T *pred; }
61 /*! Template for a node in a list of \a T structures */
62 #define DECLARE_NODE_ANON(T) \
66 * Iterate over all nodes in a list. This statement defines a for cicle
67 * accepting the following parameters:
68 * \param n node pointer to be used in each iteration
69 * \param l pointer to list
71 #define FOREACHNODE(n,l) \
73 (n) = (typeof(n))((l)->head); \
74 ((Node *)(n))->succ; \
75 (n) = (typeof(n))(((Node *)(n))->succ) \
78 /*! Initialize a list */
81 (l)->head = (Node *)(&(l)->null); \
83 (l)->tail = (Node *)(&(l)->head); \
86 /*! Add node to list head */
87 #define ADDHEAD(l,n) \
89 (n)->succ = (l)->head; \
90 (n)->pred = (Node *)&(l)->head; \
91 (n)->succ->pred = (n); \
95 /*! Add node to list tail */
96 #define ADDTAIL(l,n) \
98 (n)->succ = (Node *)(&(l)->null); \
99 (n)->pred = (l)->tail; \
100 (n)->pred->succ = (n); \
105 * Insert node \a n before node \a ln
106 * Note: you can't pass in a list header as \a ln, but
107 * it is safe to pass list-\>head of an empty list.
109 #define INSERTBEFORE(n,ln) \
112 (n)->pred = (ln)->pred; \
113 (ln)->pred->succ = (n); \
117 /*! Remove \a n from whatever list it is in */
120 (n)->pred->succ = (n)->succ; \
121 (n)->succ->pred = (n)->pred; \
124 /*! Tell whether a list is empty */
125 #define ISLISTEMPTY(l) ( (l)->head == (Node *)(&(l)->null) )
128 * Unlink a node from the head of the list \a l.
129 * \return Pointer to node, or NULL if the list was empty.
131 INLINE Node *REMHEAD(List *l)
140 n->succ->pred = (Node *)l;
145 * Unlink a node from the tail of the list \a l.
146 * \return Pointer to node, or NULL if the list was empty.
148 INLINE Node *REMTAIL(List *l)
157 n->pred->succ = (Node *)&l->null;
161 #endif /* MWARE_LIST_H */