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.5 2004/07/20 23:45:01 bernie
17 * Finally remove redundant protos.
19 * Revision 1.4 2004/07/18 22:12:53 bernie
20 * Fix warnings with GCC 3.3.2.
22 * Revision 1.3 2004/07/18 22:01:43 bernie
23 * REMHEAD(), REMTAIL(): Move to list.h as inline functions.
25 * Revision 1.2 2004/06/03 11:27:09 bernie
26 * Add dual-license information.
28 * Revision 1.1 2004/05/23 15:43:16 bernie
29 * Import mware modules.
49 /*! Template for a list of \a T structures */
50 #define DECLARE_LIST(T) \
51 struct { T *head; T *null; T *tail; }
53 /*! Template for a node in a list of \a T structures */
54 #define DECLARE_NODE(T) \
55 struct { T *succ; T *pred; }
57 /*! Template for a node in a list of \a T structures */
58 #define DECLARE_NODE_ANON(T) \
62 * Iterate over all nodes in a list. This statement defines a for cicle
63 * accepting the following parameters:
64 * \param n node pointer to be used in each iteration
65 * \param l pointer to list
67 #define FOREACHNODE(n,l) \
69 (n) = (typeof(n))((l)->head); \
70 ((Node *)(n))->succ; \
71 (n) = (typeof(n))(((Node *)(n))->succ) \
74 /*! Initialize a list */
77 (l)->head = (Node *)(&(l)->null); \
79 (l)->tail = (Node *)(&(l)->head); \
82 /*! Add node to list head */
83 #define ADDHEAD(l,n) \
85 (n)->succ = (l)->head; \
86 (n)->pred = (Node *)&(l)->head; \
87 (n)->succ->pred = (n); \
91 /*! Add node to list tail */
92 #define ADDTAIL(l,n) \
94 (n)->succ = (Node *)(&(l)->null); \
95 (n)->pred = (l)->tail; \
96 (n)->pred->succ = (n); \
101 * Insert node \a n before node \a ln
102 * Note: you can't pass in a list header as \a ln, but
103 * it is safe to pass list-\>head of an empty list.
105 #define INSERTBEFORE(n,ln) \
108 (n)->pred = (ln)->pred; \
109 (ln)->pred->succ = (n); \
113 /*! Remove \a n from whatever list it is in */
116 (n)->pred->succ = (n)->succ; \
117 (n)->succ->pred = (n)->pred; \
120 /*! Tell whether a list is empty */
121 #define ISLISTEMPTY(l) ( (l)->head == (Node *)(&(l)->null) )
124 * \name Unlink a node from the head of the list \a l.
125 * \return Pointer to node, or NULL if the list was empty.
127 INLINE Node *REMHEAD(List *l)
136 n->succ->pred = (Node *)l;
141 * \name Unlink a node from the tail of the list \a l.
142 * \return Pointer to node, or NULL if the list was empty.
144 INLINE Node *REMTAIL(List *l)
153 n->pred->succ = (Node *)&l->null;
157 #endif /* MWARE_LIST_H */