[glib-controller] Add a variadic arguments version of get_index_value()



commit c84b71544ad4bcfcf7dc08673c14660570db8e42
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Apr 30 17:27:00 2010 +0100

    Add a variadic arguments version of get_index_value()
    
    Similarly to what we have with add_index()/add_index_value(), we should
    have a variadic arguments version of get_index_value() that does the
    automagic unboxing of the GValue storing the index for a given position.

 doc/reference/glib-controller-sections.txt |    3 ++
 glib-controller/gcontrollerreference.c     |   48 ++++++++++++++++++++++++++++
 glib-controller/gcontrollerreference.h     |    3 ++
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/glib-controller-sections.txt b/doc/reference/glib-controller-sections.txt
index 4c95f53..323029b 100644
--- a/doc/reference/glib-controller-sections.txt
+++ b/doc/reference/glib-controller-sections.txt
@@ -98,6 +98,9 @@ g_controller_reference_get_index_type
 g_controller_reference_add_index_value
 g_controller_reference_get_index_value
 g_controller_reference_add_index
+g_controller_reference_get_index
+
+<SUBSECTION>
 g_controller_reference_get_index_int
 g_controller_reference_get_index_uint
 g_controller_reference_get_index_string
diff --git a/glib-controller/gcontrollerreference.c b/glib-controller/gcontrollerreference.c
index 6cc5522..0e230f7 100644
--- a/glib-controller/gcontrollerreference.c
+++ b/glib-controller/gcontrollerreference.c
@@ -435,6 +435,54 @@ out:
 }
 
 /**
+ * g_controller_reference_get_index:
+ * @ref: a #GControllerReference
+ * @pos: the position of the index
+ * @Varargs: return location for the index value at the given position
+ *
+ * Retrieves the index inside the @ref
+ *
+ * Return value: %TRUE on success
+ */
+gboolean
+g_controller_reference_get_index (GControllerReference *ref,
+                                  gint                  pos,
+                                  ...)
+{
+  GValue *value;
+  gchar *error = NULL;
+  va_list args;
+  gboolean res = FALSE;
+
+  g_return_val_if_fail (G_IS_CONTROLLER_REFERENCE (ref), FALSE);
+
+  if (ref->priv->indices == NULL)
+    return FALSE;
+
+  va_start (args, pos);
+
+  value = g_value_array_get_nth (ref->priv->indices, pos);
+  if (value == NULL)
+    goto out;
+
+  G_VALUE_LCOPY (value, args, 0, &error);
+
+  if (error != NULL)
+    {
+      g_warning ("%s: %s", G_STRLOC, error);
+      g_free (error);
+      res = FALSE;
+    }
+  else
+    res = TRUE;
+
+out:
+  va_end (args);
+
+  return res;
+}
+
+/**
  * g_controller_reference_get_index_int:
  * @ref: a #GControllerReference
  * @pos: the position of the index
diff --git a/glib-controller/gcontrollerreference.h b/glib-controller/gcontrollerreference.h
index 93a7773..f77ba2d 100644
--- a/glib-controller/gcontrollerreference.h
+++ b/glib-controller/gcontrollerreference.h
@@ -62,6 +62,9 @@ gboolean              g_controller_reference_get_index_value   (GControllerRefer
 
 void                  g_controller_reference_add_index         (GControllerReference *ref,
                                                                 ...);
+gboolean              g_controller_reference_get_index         (GControllerReference *ref,
+                                                                gint                  pos,
+                                                                ...);
 
 gint                  g_controller_reference_get_index_int     (GControllerReference *ref,
                                                                 gint                  pos);



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