[glib] gobject: Add g_object_setv and g_object_getv functions



commit c6d373bfe71800a9e7921f091af8e02e8ae85dff
Author: Fabian Orccon <cfoch fabian gmail com>
Date:   Thu Jan 26 19:39:33 2017 -0500

    gobject: Add g_object_setv and g_object_getv functions
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709865

 gobject/gobject.c |  119 +++++++++++++++++++++++++++++++++++++++++++----------
 gobject/gobject.h |   10 ++++
 2 files changed, 107 insertions(+), 22 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 2423dfe..2b9540f 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -2185,6 +2185,54 @@ g_object_set_is_valid_property (GObject         *object,
 }
 
 /**
+ * g_object_setv: (skip)
+ * @object: a #GObject
+ * @n_properties: the number of properties
+ * @names: (array length=n_properties): the names of each property to be set
+ * @values: (array length=n_properties): the values of each property to be set
+ *
+ * Sets @n_properties properties for an @object.
+ * Properties to be set will be taken from @values. All properties must be
+ * valid. Warnings will be emitted and undefined behaviour may result if invalid
+ * properties are passed in.
+ *
+ * Since: 2.52
+ */
+void
+g_object_setv (GObject       *object,
+               guint          n_properties,
+               const gchar   *names[],
+               const GValue   values[])
+{
+  guint i;
+  GObjectNotifyQueue *nqueue;
+  GParamSpec *pspec;
+  GType obj_type;
+
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  if (n_properties == 0)
+    return;
+
+  g_object_ref (object);
+  obj_type = G_OBJECT_TYPE (object);
+  nqueue = g_object_notify_queue_freeze (object, FALSE);
+  for (i = 0; i < n_properties; i++)
+    {
+      pspec = g_param_spec_pool_lookup (pspec_pool, names[i], obj_type, TRUE);
+
+      if (!g_object_set_is_valid_property (object, pspec, names[i]))
+        break;
+
+      consider_issuing_property_deprecation_warning (pspec);
+      object_set_property (object, pspec, &values[i], nqueue);
+    }
+
+  g_object_notify_queue_thaw (object, nqueue);
+  g_object_unref (object);
+}
+
+/**
  * g_object_set_valist: (skip)
  * @object: a #GObject
  * @first_property_name: name of the first property to set
@@ -2263,6 +2311,54 @@ g_object_get_is_valid_property (GObject          *object,
 }
 
 /**
+ * g_object_getv:
+ * @object: a #GObject
+ * @n_properties: the number of properties
+ * @names: (array length=n_properties): the names of each property to get
+ * @values: (array length=n_properties): the values of each property to get
+ *
+ * Gets @n_properties properties for an @object.
+ * Obtained properties will be set to @values. All properties must be valid.
+ * Warnings will be emitted and undefined behaviour may result if invalid
+ * properties are passed in.
+ *
+ * Since: 2.52
+ */
+void
+g_object_getv (GObject      *object,
+               guint         n_properties,
+               const gchar  *names[],
+               GValue        values[])
+{
+  guint i;
+  GParamSpec *pspec;
+  GType obj_type;
+
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  if (n_properties == 0)
+    return;
+
+  g_object_ref (object);
+
+  obj_type = G_OBJECT_TYPE (object);
+  for (i = 0; i < n_properties; i++)
+    {
+      pspec = g_param_spec_pool_lookup (pspec_pool,
+                                       names[i],
+                                       obj_type,
+                                       TRUE);
+      if (!g_object_get_is_valid_property (object, pspec, names[i]))
+        break;
+
+      memset (&values[i], 0, sizeof (GValue));
+      g_value_init (&values[i], pspec->value_type);
+      object_get_property (object, pspec, &values[i]);
+    }
+  g_object_unref (object);
+}
+
+/**
  * g_object_get_valist: (skip)
  * @object: a #GObject
  * @first_property_name: name of the first property to get
@@ -2413,28 +2509,7 @@ g_object_set_property (GObject       *object,
                       const gchar  *property_name,
                       const GValue *value)
 {
-  GObjectNotifyQueue *nqueue;
-  GParamSpec *pspec;
-  
-  g_return_if_fail (G_IS_OBJECT (object));
-  g_return_if_fail (property_name != NULL);
-  g_return_if_fail (G_IS_VALUE (value));
-  
-  g_object_ref (object);
-  nqueue = g_object_notify_queue_freeze (object, FALSE);
-  
-  pspec = g_param_spec_pool_lookup (pspec_pool,
-                                   property_name,
-                                   G_OBJECT_TYPE (object),
-                                   TRUE);
-  if (g_object_set_is_valid_property (object, pspec, property_name))
-    {
-      consider_issuing_property_deprecation_warning (pspec);
-      object_set_property (object, pspec, value, nqueue);
-    }
-
-  g_object_notify_queue_thaw (object, nqueue);
-  g_object_unref (object);
+  g_object_setv (object, 1, &property_name, value);
 }
 
 /**
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 3fd59eb..fd2c5a8 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -449,10 +449,20 @@ GLIB_AVAILABLE_IN_ALL
 void       g_object_disconnect               (gpointer        object,
                                               const gchar    *signal_spec,
                                               ...) G_GNUC_NULL_TERMINATED;
+GLIB_AVAILABLE_IN_2_52
+void        g_object_setv                     (GObject        *object,
+                                               guint           n_properties,
+                                               const gchar    *names[],
+                                               const GValue    values[]);
 GLIB_AVAILABLE_IN_ALL
 void        g_object_set_valist               (GObject        *object,
                                               const gchar    *first_property_name,
                                               va_list         var_args);
+GLIB_AVAILABLE_IN_2_52
+void        g_object_getv                     (GObject        *object,
+                                               guint           n_properties,
+                                               const gchar    *names[],
+                                               GValue          values[]);
 GLIB_AVAILABLE_IN_ALL
 void        g_object_get_valist               (GObject        *object,
                                               const gchar    *first_property_name,


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