/** * dlink.h: Data structures and macros for manipulating linked lists. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: dlink.h,v 1.4 2007/09/16 18:54:42 pippijn Exp $ */ #ifndef NODE_H #define NODE_H #include /* macros for linked lists */ #define LIST_FOREACH(n, head) for (n = (head); n; n = n->next) #define LIST_FOREACH_NEXT(n, head) for (n = (head); n->next; n = n->next) #define LIST_FOREACH_PREV(n, tail) for (n = (tail); n; n = n->prev) #define LIST_LENGTH(list) (list)->count #define LIST_FOREACH_SAFE(n, tn, head) for (n = (head), tn = n ? n->next : NULL; n != NULL; n = tn, tn = n ? n->next : NULL) /* list node struct */ struct node_t : zero_initialised { node_t *next; node_t *prev; void *data; /* pointer to real structure */ }; /* node list struct */ struct list_t : zero_initialised { node_t *head; node_t *tail; unsigned int count; /* how many entries in the list */ list_t () : head (0), tail (0), count (0) { } }; E node_t *node_create (void); E void node_free (node_t *n); E void node_add (void *data, node_t *n, list_t *l); E void node_add_head (void *data, node_t *n, list_t *l); E void node_add_before (void *data, node_t *n, list_t *l, node_t *before); E void node_del (node_t *n, list_t *l); E node_t *node_find (void *data, list_t *l); E void node_move (node_t *m, list_t *oldlist, list_t *newlist); #endif