[cogl/wip/neil/pipeline-uniforms: 6/9] Add _cogl_bitmask_is_empty



commit 9ab8298ca6b1359c602da75c26d180ea8e0a7748
Author: Neil Roberts <neil linux intel com>
Date:   Fri Oct 28 18:41:54 2011 +0100

    Add _cogl_bitmask_is_empty
    
    This just checks whether any of the bits are set.

 cogl/cogl-bitmask.c          |   13 +++++++++++++
 cogl/cogl-bitmask.h          |   18 ++++++++++++++++++
 tests/conform/test-bitmask.c |    2 ++
 3 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-bitmask.c b/cogl/cogl-bitmask.c
index 1fe2198..67f0fa4 100644
--- a/cogl/cogl-bitmask.c
+++ b/cogl/cogl-bitmask.c
@@ -274,3 +274,16 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
         }
     }
 }
+
+gboolean
+_cogl_bitmask_is_empty_array (const CoglBitmask *bitmask)
+{
+  const GArray *array = (const GArray *) *bitmask;
+  int i;
+
+  for (i = 0; i < array->len; i++)
+    if (g_array_index (array, unsigned long, i))
+      return FALSE;
+
+  return TRUE;
+}
diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h
index e36a551..e94f367 100644
--- a/cogl/cogl-bitmask.h
+++ b/cogl/cogl-bitmask.h
@@ -101,6 +101,9 @@ _cogl_bitmask_set_range_in_array (CoglBitmask *bitmask,
 void
 _cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask);
 
+gboolean
+_cogl_bitmask_is_empty_array (const CoglBitmask *bitmask);
+
 /*
  * cogl_bitmask_set_bits:
  * @dst: The bitmask to modify
@@ -233,6 +236,21 @@ _cogl_bitmask_clear_all (CoglBitmask *bitmask)
     *bitmask = _cogl_bitmask_from_bits (0);
 }
 
+/*
+ * _cogl_bitmask_is_empty:
+ * @bitmask: A pointer to a bitmask
+ *
+ * Return value: whether the bitmask has any bits set
+ */
+static inline gboolean
+_cogl_bitmask_is_empty (const CoglBitmask *bitmask)
+{
+  if (_cogl_bitmask_has_array (bitmask))
+    return _cogl_bitmask_is_empty_array (bitmask);
+  else
+    return *bitmask == _cogl_bitmask_from_bits (0);
+}
+
 G_END_DECLS
 
 #endif /* __COGL_BITMASK_H */
diff --git a/tests/conform/test-bitmask.c b/tests/conform/test-bitmask.c
index 66daa16..d741331 100644
--- a/tests/conform/test-bitmask.c
+++ b/tests/conform/test-bitmask.c
@@ -75,6 +75,8 @@ verify_bits (const CoglBitmask *bitmask,
 
       g_assert_cmpint (_cogl_bitmask_get (bitmask, i), ==, (j < data.n_bits));
     }
+
+  g_assert_cmpint (_cogl_bitmask_is_empty (bitmask), ==, (data.n_bits == 0));
 }
 
 void



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