[grilo] core: Add support for boolean data in GrlData



commit 6269a37296d3021bc4b8f602130e6e1c37d8ab3f
Author: AntÃa Puentes <apuentes igalia com>
Date:   Wed Oct 10 12:17:23 2012 +0200

    core: Add support for boolean data in GrlData
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685861
    
    Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>

 src/data/grl-data.c |   41 +++++++++++++++++++++++++++++++++++++++++
 src/data/grl-data.h |    4 ++++
 2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index fcf93f2..3ba92f0 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -357,6 +357,47 @@ grl_data_get_float (GrlData *data, GrlKeyID key)
 }
 
 /**
+ * grl_data_set_boolean:
+ * @data: data to change
+ * @key: (type GrlKeyID): key to change or add
+ * @boolvalue: the new value
+ *
+ * Sets the first boolean value associated with @key in @data. If @key already
+ * has a first value, old value is replaced by the new one.
+ *
+ **/
+void
+grl_data_set_boolean (GrlData *data, GrlKeyID key, gboolean boolvalue)
+{
+  GValue value = { 0 };
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&value, boolvalue);
+  grl_data_set (data, key, &value);
+}
+
+/**
+ * grl_data_get_boolean:
+ * @data: data to inspect
+ * @key (type GrlKeyID): key to use
+ *
+ * Returns the first boolean value associated with @key from @data. If @key has
+ * no first value, or value is not a gboolean, or @key is not in the data, then
+ * FALSE is returned
+ *
+ */
+gboolean
+grl_data_get_boolean (GrlData *data, GrlKeyID key)
+{
+  const GValue *value = grl_data_get (data, key);
+
+  if (!value || !G_VALUE_HOLDS_BOOLEAN (value)) {
+    return FALSE;
+  } else {
+    return g_value_get_boolean (value);
+  }
+}
+
+/**
  * grl_data_set_binary:
  * @data: data to change
  * @key: (type GrlKeyID): key to change or add
diff --git a/src/data/grl-data.h b/src/data/grl-data.h
index 91cdeab..4ee69e6 100644
--- a/src/data/grl-data.h
+++ b/src/data/grl-data.h
@@ -105,6 +105,8 @@ void grl_data_set_float (GrlData *data,
                          GrlKeyID key,
                          gfloat floatvalue);
 
+void grl_data_set_boolean (GrlData *data, GrlKeyID key, gboolean boolvalue);
+
 void grl_data_set_binary(GrlData *data, GrlKeyID key, const guint8 *buf, gsize size);
 
 void grl_data_set_boxed (GrlData *data, GrlKeyID key, gconstpointer boxed);
@@ -117,6 +119,8 @@ gint grl_data_get_int (GrlData *data, GrlKeyID key);
 
 gfloat grl_data_get_float (GrlData *data, GrlKeyID key);
 
+gboolean grl_data_get_boolean (GrlData *data, GrlKeyID key);
+
 const guint8 *grl_data_get_binary(GrlData *data, GrlKeyID key, gsize *size);
 
 gpointer grl_data_get_boxed (GrlData *data, GrlKeyID key);



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