[PATCH 1/6] core: added support for boxed types in GrlData and GrlRelatedKeys
- From: Guillaume Emont <guijemont igalia com>
- To: grilo-list gnome org
- Cc: Guillaume Emont <guijemont igalia com>
- Subject: [PATCH 1/6] core: added support for boxed types in GrlData and GrlRelatedKeys
- Date: Wed, 22 Jun 2011 19:07:51 +0200
---
src/data/grl-data.c | 69 +++++++++++++++++++++++++++++++++++++++++++
src/data/grl-data.h | 6 ++++
src/data/grl-related-keys.c | 51 +++++++++++++++++++++++++++++++
src/data/grl-related-keys.h | 7 ++++
4 files changed, 133 insertions(+), 0 deletions(-)
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index 9628c83..9897470 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -419,6 +419,53 @@ grl_data_get_binary(GrlData *data, GrlKeyID key, gsize *size)
}
/**
+ * grl_data_set_boxed:
+ * @data: data to modify
+ * @key: key to change or add
+ * @boxed: the new value
+ *
+ * Sets the first boxed value associated with @key in @data. If @key already
+ * has a value, the old value is freed and the new one is set.
+ **/
+void
+grl_data_set_boxed (GrlData *data, GrlKeyID key, gconstpointer boxed)
+{
+ GValue value = { 0 };
+
+ if (boxed) {
+ g_value_init (&value, GRL_METADATA_KEY_GET_TYPE (key));
+ g_value_set_boxed (&value, boxed);
+ grl_data_set (data, key, &value);
+ g_value_unset (&value);
+ }
+}
+
+/**
+ * grl_data_get_boxed:
+ * @data: data to inspect
+ * @key: (type GrlKeyID): key to use
+ *
+ * Returns the first boxed value associated with @key from @data. If @key has
+ * no first value, that value is not of a boxed type, or @key is not in @data,
+ * then %NULL is returned.
+ *
+ * Returns: (transfer none): the boxed instance associated with @key if
+ * possible, or %NULL in other cases. The caller should not change nor free the
+ * value.
+ **/
+gconstpointer
+grl_data_get_boxed (GrlData *data, GrlKeyID key)
+{
+ const GValue *value = grl_data_get (data, key);
+
+ if (!value || !G_VALUE_HOLDS_BOXED (value)) {
+ return NULL;
+ } else {
+ return g_value_get_boxed (value);
+ }
+}
+
+/**
* grl_data_remove:
* @data: data to change
* @key: (type GrlKeyID): key to remove
@@ -655,6 +702,28 @@ grl_data_add_binary (GrlData *data,
}
/**
+ * grl_data_add_boxed:
+ * @data: data to append
+ * @key: (type GrlKeyID): key to append
+ * @boxed: the new value
+ *
+ * Appends a new boxed value for @key in @data.
+ **/
+void
+grl_data_add_boxed (GrlData *data,
+ GrlKeyID key,
+ gconstpointer boxed)
+{
+ GrlRelatedKeys *relkeys;
+
+ if (boxed) {
+ relkeys = grl_related_keys_new ();
+ grl_related_keys_set_boxed (relkeys, key, boxed);
+ grl_data_add_related_keys (data, relkeys);
+ }
+}
+
+/**
* grl_data_length:
* @data: a data
* @key: a metadata key
diff --git a/src/data/grl-data.h b/src/data/grl-data.h
index ebcdcf3..98f0e1c 100644
--- a/src/data/grl-data.h
+++ b/src/data/grl-data.h
@@ -107,6 +107,8 @@ void grl_data_set_float (GrlData *data,
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);
+
const GValue *grl_data_get (GrlData *data, GrlKeyID key);
const gchar *grl_data_get_string (GrlData *data, GrlKeyID key);
@@ -117,6 +119,8 @@ gfloat grl_data_get_float (GrlData *data, GrlKeyID key);
const guint8 *grl_data_get_binary(GrlData *data, GrlKeyID key, gsize *size);
+gconstpointer grl_data_get_boxed (GrlData *data, GrlKeyID key);
+
void grl_data_remove (GrlData *data, GrlKeyID key);
gboolean grl_data_has_key (GrlData *data, GrlKeyID key);
@@ -133,6 +137,8 @@ void grl_data_add_float (GrlData *data, GrlKeyID key, gfloat floatvalue);
void grl_data_add_binary (GrlData *data, GrlKeyID key, const guint8 *buf, gsize size);
+void grl_data_add_boxed (GrlData *data, GrlKeyID key, gconstpointer boxed);
+
guint grl_data_length (GrlData *data, GrlKeyID key);
GrlRelatedKeys *grl_data_get_related_keys (GrlData *data, GrlKeyID key, guint index);
diff --git a/src/data/grl-related-keys.c b/src/data/grl-related-keys.c
index 112daaf..8d79072 100644
--- a/src/data/grl-related-keys.c
+++ b/src/data/grl-related-keys.c
@@ -483,6 +483,57 @@ grl_related_keys_get_binary (GrlRelatedKeys *relkeys,
}
/**
+ * grl_related_keys_set_boxed:
+ *
+ * @relkeys: set of related keys to modify
+ * @key: key to change or add
+ * @boxed: the new value
+ *
+ * Sets the value associated with @key into @relkeys. @key must have been
+ * registered as a boxed-type key. Old value is freed and the new one is set.
+ */
+void
+grl_related_keys_set_boxed (GrlRelatedKeys *relkeys,
+ GrlKeyID key,
+ gconstpointer boxed)
+{
+ GValue value = { 0 };
+
+ if (boxed) {
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_boxed (&value, boxed);
+ grl_related_keys_set (relkeys, key, &value);
+ g_value_unset (&value);
+ }
+}
+
+/**
+ * grl_related_keys_get_boxed:
+ * @relkeys: set of related keys to inspect
+ * @key: key to use
+ *
+ * Returns the value associated with @key from @relkeys. If @key has no value,
+ * the value is not of a boxed type, or @key is not in @relkeys, then %NULL is
+ * returned.
+ *
+ * Returns: (transfer none): the #GBoxed value associated with @key if
+ * possible, or %NULL in other case. The caller should not change nor free the
+ * value.
+ */
+gconstpointer
+grl_related_keys_get_boxed (GrlRelatedKeys *relkeys,
+ GrlKeyID key)
+{
+ const GValue *value = grl_related_keys_get (relkeys, key);
+
+ if (!value || !G_VALUE_HOLDS_BOXED (value)) {
+ return NULL;
+ } else {
+ return g_value_get_boxed (value);
+ }
+}
+
+/**
* grl_related_keys_has_key:
* @relkeys: set of related keys to inspect
* @key: (type GrlKeyID): key to search
diff --git a/src/data/grl-related-keys.h b/src/data/grl-related-keys.h
index 8c47e19..9cb1371 100644
--- a/src/data/grl-related-keys.h
+++ b/src/data/grl-related-keys.h
@@ -118,6 +118,10 @@ void grl_related_keys_set_binary(GrlRelatedKeys *relkeys,
const guint8 *buf,
gsize size);
+void grl_related_keys_set_boxed (GrlRelatedKeys *relkeys,
+ GrlKeyID key,
+ gconstpointer boxed);
+
const GValue *grl_related_keys_get (GrlRelatedKeys *relkeys,
GrlKeyID key);
@@ -134,6 +138,9 @@ const guint8 *grl_related_keys_get_binary(GrlRelatedKeys *relkeys,
GrlKeyID key,
gsize *size);
+gconstpointer grl_related_keys_get_boxed (GrlRelatedKeys *relkeys,
+ GrlKeyID key);
+
gboolean grl_related_keys_has_key (GrlRelatedKeys *relkeys,
GrlKeyID key);
--
1.7.4.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]