2 * Copyright 2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 /* this usually points to the list head */
29 /* these point to the list item, for simple lists data2 is usually NULL */
34 static inline void iter_init(struct iter
*iter
)
41 static inline void iter_head(struct iter
*iter
)
47 static inline int iters_equal(struct iter
*a
, struct iter
*b
)
49 return a
->data0
== b
->data0
&&
50 a
->data1
== b
->data1
&&
54 static inline int iter_is_head(struct iter
*iter
)
56 return iter
->data0
!= NULL
&&
57 iter
->data1
== NULL
&&
61 static inline int iter_is_null(struct iter
*iter
)
63 return iter
->data0
== NULL
&&
64 iter
->data1
== NULL
&&
68 static inline int iter_is_empty(struct iter
*iter
)
70 return iter
->data0
== NULL
|| (iter
->data1
== NULL
&& iter
->data2
== NULL
);
73 #define GENERIC_ITER_PREV(FUNC, TYPE, MEMBER) \
74 int FUNC(struct iter *iter) \
76 struct list_head *head = iter->data0; \
77 TYPE *e = iter->data1; \
82 /* head, get last */ \
83 if (head->prev == head) { \
84 /* empty, iter points to the head already */ \
87 iter->data1 = container_of(head->prev, TYPE, MEMBER); \
90 if (e->MEMBER.prev == head) { \
94 iter->data1 = container_of(e->MEMBER.prev, TYPE, MEMBER); \
98 #define GENERIC_ITER_NEXT(FUNC, TYPE, MEMBER) \
99 int FUNC(struct iter *iter) \
101 struct list_head *head = iter->data0; \
102 TYPE *e = iter->data1; \
107 /* head, get first */ \
108 if (head->next == head) { \
109 /* empty, iter points to the head already */ \
112 iter->data1 = container_of(head->next, TYPE, MEMBER); \
115 if (e->MEMBER.next == head) { \
116 iter->data1 = NULL; \
119 iter->data1 = container_of(e->MEMBER.next, TYPE, MEMBER); \