From 88f7a78a974d4f6689835b82d5e3cc008667aff0 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 16 Apr 2011 14:55:10 +0200 Subject: [PATCH] add *_list_foreach Signed-off-by: Sven Verdoolaege --- doc/user.pod | 3 +++ include/isl/list.h | 4 +++- isl_list_templ.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index 370bc9c..3e389c0 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2025,6 +2025,9 @@ Lists can be inspected using the following functions. #include 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 diff --git a/include/isl/list.h b/include/isl/list.h index ddedaf3..ce251b4 100644 --- a/include/isl/list.h +++ b/include/isl/list.h @@ -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) diff --git a/isl_list_templ.c b/isl_list_templ.c index 4fb8965..bd94023 100644 --- a/isl_list_templ.c +++ b/isl_list_templ.c @@ -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; +} -- 2.7.4