[cogl] cogl-bitmask: Add a return value for the foreach callback



commit dbc31b70cc790833d8926ebad3e03c2d236965ae
Author: Neil Roberts <neil linux intel com>
Date:   Wed Oct 26 18:43:21 2011 +0100

    cogl-bitmask: Add a return value for the foreach callback
    
    The foreach callback can now return FALSE to stop the iteration.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/cogl-attribute.c        |    6 ++++--
 cogl/cogl-bitmask.c          |   10 ++++++----
 cogl/cogl-bitmask.h          |    5 +++--
 tests/conform/test-bitmask.c |    6 +++---
 4 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c
index 348071d..853d989 100644
--- a/cogl/cogl-attribute.c
+++ b/cogl/cogl-attribute.c
@@ -428,13 +428,13 @@ validated:
   return status;
 }
 
-static void
+static gboolean
 toggle_enabled_cb (int bit_num, void *user_data)
 {
   const CoglBitmask *new_values = user_data;
   gboolean enabled = _cogl_bitmask_get (new_values, bit_num);
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+  _COGL_GET_CONTEXT (ctx, FALSE);
 
   if (ctx->driver == COGL_DRIVER_GLES2)
     {
@@ -454,6 +454,8 @@ toggle_enabled_cb (int bit_num, void *user_data)
         GE( ctx, glDisableClientState (GL_TEXTURE_COORD_ARRAY) );
     }
 #endif
+
+  return TRUE;
 }
 
 static void
diff --git a/cogl/cogl-bitmask.c b/cogl/cogl-bitmask.c
index bdd7b05..1fe2198 100644
--- a/cogl/cogl-bitmask.c
+++ b/cogl/cogl-bitmask.c
@@ -231,7 +231,7 @@ _cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask)
 void
 _cogl_bitmask_foreach (const CoglBitmask *bitmask,
                        CoglBitmaskForeachFunc func,
-                       gpointer user_data)
+                       void *user_data)
 {
   if (_cogl_bitmask_has_array (bitmask))
     {
@@ -251,8 +251,9 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
               bit += next_bit;
               mask >>= next_bit;
 
-              func (array_index * sizeof (unsigned long) * 8 + bit - 1,
-                    user_data);
+              if (!func (array_index * sizeof (unsigned long) * 8 + bit - 1,
+                         user_data))
+                return;
             }
         }
     }
@@ -268,7 +269,8 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
           bit += next_bit;
           mask >>= next_bit;
 
-          func (bit - 1, user_data);
+          if (!func (bit - 1, user_data))
+            return;
         }
     }
 }
diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h
index 42ba356..e36a551 100644
--- a/cogl/cogl-bitmask.h
+++ b/cogl/cogl-bitmask.h
@@ -125,7 +125,8 @@ void
 _cogl_bitmask_xor_bits (CoglBitmask *dst,
                         const CoglBitmask *src);
 
-typedef void (* CoglBitmaskForeachFunc) (int bit_num, gpointer user_data);
+/* The foreach function can return FALSE to stop iteration */
+typedef gboolean (* CoglBitmaskForeachFunc) (int bit_num, void *user_data);
 
 /*
  * cogl_bitmask_foreach:
@@ -138,7 +139,7 @@ typedef void (* CoglBitmaskForeachFunc) (int bit_num, gpointer user_data);
 void
 _cogl_bitmask_foreach (const CoglBitmask *bitmask,
                        CoglBitmaskForeachFunc func,
-                       gpointer user_data);
+                       void *user_data);
 
 /*
  * _cogl_bitmask_get:
diff --git a/tests/conform/test-bitmask.c b/tests/conform/test-bitmask.c
index b02a9ba..613e5ee 100644
--- a/tests/conform/test-bitmask.c
+++ b/tests/conform/test-bitmask.c
@@ -19,7 +19,7 @@ typedef struct
   int *bits;
 } CheckData;
 
-static void
+static gboolean
 check_bit (int bit_num, void *user_data)
 {
   CheckData *data = user_data;
@@ -29,12 +29,12 @@ check_bit (int bit_num, void *user_data)
     if (data->bits[i] == bit_num)
       {
         data->bits[i] = -1;
-        return;
+        return TRUE;
       }
 
   g_assert_not_reached ();
 
-  return;
+  return TRUE;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]