ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/dlink.h
Revision: 1.5
Committed: Sat Sep 22 14:27:26 2007 UTC (16 years, 7 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * dlink.h: Data structures and macros for manipulating linked lists.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: dlink.h,v 1.4 2007-09-16 18:54:42 pippijn Exp $
13 */
14
15 #ifndef NODE_H
16 #define NODE_H
17
18 #include <util/memory.h>
19
20 /* macros for linked lists */
21 #define LIST_FOREACH(n, head) for (n = (head); n; n = n->next)
22 #define LIST_FOREACH_NEXT(n, head) for (n = (head); n->next; n = n->next)
23 #define LIST_FOREACH_PREV(n, tail) for (n = (tail); n; n = n->prev)
24
25 #define LIST_LENGTH(list) (list)->count
26
27 #define LIST_FOREACH_SAFE(n, tn, head) for (n = (head), tn = n ? n->next : NULL; n != NULL; n = tn, tn = n ? n->next : NULL)
28
29 /* list node struct */
30 struct node_t : zero_initialised
31 {
32 node_t *next;
33 node_t *prev;
34 void *data; /* pointer to real structure */
35 };
36
37 /* node list struct */
38 struct list_t : zero_initialised
39 {
40 node_t *head;
41 node_t *tail;
42 unsigned int count; /* how many entries in the list */
43
44 list_t ()
45 : head (0), tail (0), count (0)
46 {
47 }
48 };
49
50 E node_t *node_create (void);
51 E void node_free (node_t *n);
52 E void node_add (void *data, node_t *n, list_t *l);
53 E void node_add_head (void *data, node_t *n, list_t *l);
54 E void node_add_before (void *data, node_t *n, list_t *l, node_t *before);
55 E void node_del (node_t *n, list_t *l);
56 E node_t *node_find (void *data, list_t *l);
57 E void node_move (node_t *m, list_t *oldlist, list_t *newlist);
58
59 #endif