From ded44e52a14efa002a61f2925612fd418a8053b0 Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Thu, 25 May 2006 17:04:08 +0000
Subject: [PATCH] add a g_list_foreach style function which allows quitting
 from the loop.

---
 src/include/ZMap/zmapGLibUtils.h | 14 +++++++++-----
 src/zmapUtils/zmapGLibUtils.c    | 32 +++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/src/include/ZMap/zmapGLibUtils.h b/src/include/ZMap/zmapGLibUtils.h
index 1e426167e..941dceb65 100755
--- a/src/include/ZMap/zmapGLibUtils.h
+++ b/src/include/ZMap/zmapGLibUtils.h
@@ -26,9 +26,9 @@
  *              glib but not included with their distribution.
  *
  * HISTORY:
- * Last edited: May 19 16:51 2006 (edgrif)
+ * Last edited: May 25 16:12 2006 (edgrif)
  * Created: Thu Oct 13 15:56:54 2005 (edgrif)
- * CVS info:   $Id: zmapGLibUtils.h,v 1.6 2006-05-19 15:55:58 edgrif Exp $
+ * CVS info:   $Id: zmapGLibUtils.h,v 1.7 2006-05-25 17:04:08 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_GLIBUTILS_H
@@ -56,6 +56,10 @@ typedef enum
   } ZMapGListDirection;
 
 
+typedef gboolean (*ZMapGFuncCond)(gpointer data, gpointer user_data) ;
+
+
+
 /*! @} end of zmapGLibutils docs. */
 
 
@@ -63,10 +67,10 @@ typedef enum
 char *zMap_g_remove_char(char *string, char ch) ;
 
 void zMap_g_list_foreach_reverse(GList *list, GFunc func, gpointer user_data);
-void zMap_g_list_foreach_directional(GList   *list, 
-                                     GFunc    func,
-                                     gpointer user_data,
+void zMap_g_list_foreach_directional(GList *list, GFunc func, gpointer user_data,
                                      ZMapGListDirection forward);
+gboolean zMap_g_list_cond_foreach(GList *list, ZMapGFuncCond func, gpointer user_data) ;
+
 
 gboolean zMap_g_string_replace(GString *string, char *target, char *source) ;
 
diff --git a/src/zmapUtils/zmapGLibUtils.c b/src/zmapUtils/zmapGLibUtils.c
index a983ffd1e..93e27baa8 100755
--- a/src/zmapUtils/zmapGLibUtils.c
+++ b/src/zmapUtils/zmapGLibUtils.c
@@ -26,9 +26,9 @@
  *
  * Exported functions: See ZMap/zmapGLibUtils.h
  * HISTORY:
- * Last edited: May 19 16:50 2006 (edgrif)
+ * Last edited: May 25 16:02 2006 (edgrif)
  * Created: Thu Oct 13 15:22:35 2005 (edgrif)
- * CVS info:   $Id: zmapGLibUtils.c,v 1.6 2006-05-19 15:55:58 edgrif Exp $
+ * CVS info:   $Id: zmapGLibUtils.c,v 1.7 2006-05-25 17:04:08 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -129,7 +129,6 @@ char *zMap_g_remove_char(char *string, char ch)
 
 
 
-
 /* 
  *                Additions to GList 
  */
@@ -184,6 +183,33 @@ void zMap_g_list_foreach_directional(GList   *list,
 }
 
 
+/*! Just like g_list_foreach() except that the ZMapGFuncCond function can return
+ * FALSE to stop the foreach loop from executing.
+ * 
+ * Returns FALSE if ZMapGFuncCond returned FALSE, TRUE otherwise.
+ * 
+ *  */
+gboolean zMap_g_list_cond_foreach(GList *list, ZMapGFuncCond func, gpointer user_data)
+{
+  gboolean status = TRUE ;
+
+  while (list)
+    {
+      GList *next = list->next ;
+
+      if (!((*func)(list->data, user_data)))
+	{
+	  status = FALSE ;
+	  break ;
+	}
+
+      list = next ;
+    }
+
+  return status ;
+}
+
+
 
 
 
-- 
GitLab