Increased FOR_ALL macro reuse.

Sat, 26 Feb 2005 23:10:51 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 26 Feb 2005 23:10:51 +0100
changeset 93
5f72042eb91c
parent 92
55fcdff5bcea
child 94
f48ffd2f2224

Increased FOR_ALL macro reuse.

objlist.h file | annotate | diff | comparison | revisions
ptrlist.h file | annotate | diff | comparison | revisions
--- a/objlist.h	Sat Feb 26 22:09:33 2005 +0100
+++ b/objlist.h	Sat Feb 26 23:10:51 2005 +0100
@@ -12,6 +12,7 @@
 
 #include "types.h"
 #include "obj.h"
+#include "ptrlist.h"
 
 
 INTRSTRUCT(ObjList);
@@ -31,16 +32,11 @@
 #define OBJLIST_EMPTY(LIST) objlist_empty(LIST)
 
 #define FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, TMP) \
-    for(objlist_iter_init(&(TMP), LL),         \
-         VAR=(TYPE)objlist_iter(&(TMP));       \
-        VAR!=NULL;                             \
-        VAR=(TYPE)objlist_iter(&(TMP)))
+    FOR_ALL_ITER(objlist_iter_init, (TYPE)objlist_iter, VAR, LL, &(TMP))
 
-#define FOR_ALL_ON_OBJLIST_REV(TYPE, VAR, LL, TMP) \
-    for(objlist_iter_rev_init(&(TMP), LL),         \
-         VAR=(TYPE)objlist_iter_rev(&(TMP));       \
-        VAR!=NULL;                                 \
-        VAR=(TYPE)objlist_iter_rev(&(TMP)))
+#define FOR_ALL_ON_OBJLIST_REV(TYPE, VAR, LL, TMP)        \
+    FOR_ALL_ITER(objlist_iter_rev_init,                   \
+                 (TYPE)objlist_iter_rev, VAR, LL, &(TMP))
 
 #define FOR_ALL_ON_OBJLIST_UNSAFE(TYPE, VAR, LL) \
     FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, objlist_iter_tmp)
--- a/ptrlist.h	Sat Feb 26 22:09:33 2005 +0100
+++ b/ptrlist.h	Sat Feb 26 23:10:51 2005 +0100
@@ -29,17 +29,15 @@
 #define PTRLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->ptr)
 #define PTRLIST_EMPTY(LIST) ((LIST)==NULL)
 
-#define FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, TMP) \
-    for(ptrlist_iter_init(&(TMP), LL),         \
-         VAR=(TYPE)ptrlist_iter(&(TMP));       \
-        VAR!=NULL;                             \
-        VAR=(TYPE)ptrlist_iter(&(TMP)))
+#define FOR_ALL_ITER(INIT, ITER, VAR, LL, TMP) \
+    for(INIT(TMP, LL), (VAR)=ITER(TMP); (VAR)!=NULL; VAR=ITER(TMP))
 
-#define FOR_ALL_ON_PTRLIST_REV(TYPE, VAR, LL, TMP) \
-    for(ptrlist_iter_rev_init(&(TMP), LL),         \
-         VAR=(TYPE)ptrlist_iter_rev(&(TMP));       \
-        VAR!=NULL;                                 \
-        VAR=(TYPE)ptrlist_iter_rev(&(TMP)))
+#define FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, TMP) \
+    FOR_ALL_ITER(ptrlist_iter_init, (TYPE)ptrlist_iter, VAR, LL, &(TMP))
+
+#define FOR_ALL_ON_PTRLIST_REV(TYPE, VAR, LL, TMP)        \
+    FOR_ALL_ITER(ptrlist_iter_rev_init,                   \
+                 (TYPE)ptrlist_iter_rev, VAR, LL, &(TMP))
 
 #define FOR_ALL_ON_PTRLIST_UNSAFE(TYPE, VAR, LL) \
     FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, ptrlist_iter_tmp)

mercurial