Added dlist iteration macros.

Wed, 23 Feb 2005 19:05:01 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 23 Feb 2005 19:05:01 +0100
changeset 87
95553f8ea540
parent 86
d0a4defeb2cd
child 88
308dfa54da3e

Added dlist iteration macros.

dlist.h file | annotate | diff | comparison | revisions
--- a/dlist.h	Tue Feb 15 19:06:37 2005 +0100
+++ b/dlist.h	Wed Feb 23 19:05:01 2005 +0100
@@ -1,7 +1,7 @@
 /*
  * libtu/common.h
  *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
+ * Copyright (c) Tuomo Valkonen 1999-2005. 
  *
  * You may distribute and modify this library under the terms of either
  * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
@@ -10,6 +10,10 @@
 #ifndef LIBTU_DLIST_H
 #define LIBTU_DLIST_H
 
+
+/*{{{ Linking */
+
+
 #define LINK_ITEM(LIST, ITEM, NEXT, PREV) \
     (ITEM)->NEXT=NULL;                    \
     if((LIST)==NULL){                     \
@@ -73,4 +77,36 @@
     (ITEM)->NEXT=NULL;                       \
     (ITEM)->PREV=NULL;
 
+
+/*}}}*/
+
+
+/*{{{ Iteration */
+
+
+#define LIST_FIRST(LIST, NEXT, PREV) \
+    (LIST)
+#define LIST_LAST(LIST, NEXT, PREV) \
+    ((LIST)==NULL ? NULL : LIST_PREV_WRAP(LIST, LIST, NEXT, PREV))
+#define LIST_NEXT(LIST, REG, NEXT, PREV) \
+    ((REG)->NEXT)
+#define LIST_PREV(LIST, REG, NEXT, PREV) \
+    ((REG)->PREV->NEXT ? (REG)->PREV : NULL)
+#define LIST_NEXT_WRAP(LIST, REG, NEXT, PREV) \
+    (((REG) && (REG)->NEXT) ? (REG)->NEXT : (LIST))
+#define LIST_PREV_WRAP(LIST, REG, NEXT, PREV) \
+    ((REG) ? (REG)->PREV : (LIST))
+
+#define LIST_FOR_ALL(LIST, NODE, NEXT, PREV) \
+    for(NODE=LIST; NODE!=NULL; NODE=(NODE)->NEXT)
+
+#define LIST_FOR_ALL_W_NEXT(LIST, NODE, NXT, NEXT, PREV)  \
+    for(NODE=LL, NXT=(NODE==NULL ? NULL : (NODE)->NEXT);  \
+        NODE!=NULL;                                       \
+        NODE=NXT, NXT=(NODE==NULL ? NULL : (NODE)->NEXT))
+
+
+/*}}}*/
+
+
 #endif /* LIBTU_DLIST_H */

mercurial