add *_list_foreach
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 16 Apr 2011 12:55:10 +0000 (14:55 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 4 Jun 2011 11:19:23 +0000 (13:19 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/list.h
isl_list_templ.c

index 370bc9c..3e389c0 100644 (file)
@@ -2025,6 +2025,9 @@ Lists can be inspected using the following functions.
 
        #include <isl/list.h>
        isl_ctx *isl_set_list_get_ctx(__isl_keep isl_set_list *list);
+       int isl_set_list_foreach(__isl_keep isl_set_list *list,
+               int (*fn)(__isl_take struct isl_set *el, void *user),
+               void *user);
 
 =head2 Matrices
 
index ddedaf3..ce251b4 100644 (file)
@@ -27,7 +27,9 @@ __isl_give isl_##EL##_list *isl_##EL##_list_copy(                     \
 void isl_##EL##_list_free(__isl_take isl_##EL##_list *list);           \
 __isl_give isl_##EL##_list *isl_##EL##_list_add(                       \
        __isl_take isl_##EL##_list *list,                               \
-       __isl_take struct isl_##EL *el);
+       __isl_take struct isl_##EL *el);                                \
+int isl_##EL##_list_foreach(__isl_keep isl_##EL##_list *list,          \
+       int (*fn)(__isl_take struct isl_##EL *el, void *user), void *user);
 
 ISL_DECLARE_LIST(basic_set)
 ISL_DECLARE_LIST(set)
index 4fb8965..bd94023 100644 (file)
@@ -84,3 +84,22 @@ void FN(LIST(EL),free)(__isl_take LIST(EL) *list)
                FN(EL,free)(list->p[i]);
        free(list);
 }
+
+int FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list,
+       int (*fn)(__isl_take EL *el, void *user), void *user)
+{
+       int i;
+
+       if (!list)
+               return -1;
+
+       for (i = 0; i < list->n; ++i) {
+               EL *el = FN(EL,copy(list->p[i]));
+               if (!el)
+                       return -1;
+               if (fn(el, user) < 0)
+                       return -1;
+       }
+
+       return 0;
+}