Cleaned up all list iterations, added macro named LIST_FOREACH.
Previously you would have to do something like this:
for (type foo = (type) list_get_first(list); foo; foo = (type) list_get_next(list)
{
/* code */
}
Now, you can instead write this as:
LIST_FOREACH(type, foo, list,
{
/* code */
})
Basically, boilerplate stuff including the casting is gone.
This commit is contained in:
@@ -57,5 +57,9 @@ extern void* list_get_prev(struct linked_list*);
|
||||
extern struct node* list_get_first_node(struct linked_list*);
|
||||
extern struct node* list_get_last_node(struct linked_list*);
|
||||
|
||||
#define LIST_FOREACH(TYPE, ITEM, LIST, BLOCK) \
|
||||
for (ITEM = (TYPE) list_get_first(LIST); ITEM; ITEM = (TYPE) list_get_next(LIST)) \
|
||||
BLOCK
|
||||
|
||||
#endif /* HAVE_UHUB_LINKED_LIST_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user