[gnome-builder] egg-state-machine: Add var arg version of add_property()
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] egg-state-machine: Add var arg version of add_property()
- Date: Thu, 21 May 2015 06:58:30 +0000 (UTC)
commit 0b578cef804370d41ab32c6b6f042d7592c5a9db
Author: Garrett Regier <garrettregier gmail com>
Date: Wed May 20 05:17:04 2015 -0700
egg-state-machine: Add var arg version of add_property()
This simplifies using EggStateMachine when
a GValue for the value is not already available.
contrib/egg/egg-state-machine.c | 59 ++++++++++++++++++++++++++++++++++++++-
contrib/egg/egg-state-machine.h | 11 +++++++
tests/test-egg-state-machine.c | 14 ++-------
3 files changed, 72 insertions(+), 12 deletions(-)
---
diff --git a/contrib/egg/egg-state-machine.c b/contrib/egg/egg-state-machine.c
index 1b4996e..0002f39 100644
--- a/contrib/egg/egg-state-machine.c
+++ b/contrib/egg/egg-state-machine.c
@@ -19,6 +19,7 @@
#define G_LOG_DOMAIN "egg-state-machine"
#include <glib/gi18n.h>
+#include <gobject/gvaluecollector.h>
#include "egg-binding-set.h"
#include "egg-signal-group.h"
@@ -353,7 +354,63 @@ egg_state_machine_add_property (EggStateMachine *self,
const gchar *state,
gpointer object,
const gchar *property,
- const GValue *value)
+ ...)
+{
+ va_list var_args;
+
+ g_return_if_fail (EGG_IS_STATE_MACHINE (self));
+ g_return_if_fail (state != NULL);
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (property != NULL);
+
+ va_start (var_args, property);
+ egg_state_machine_add_property_valist (self, state, object,
+ property, var_args);
+ va_end (var_args);
+}
+
+void
+egg_state_machine_add_property_valist (EggStateMachine *self,
+ const gchar *state,
+ gpointer object,
+ const gchar *property,
+ va_list var_args)
+{
+ GParamSpec *pspec;
+ gchar *error = NULL;
+ GValue value = G_VALUE_INIT;
+
+ g_return_if_fail (EGG_IS_STATE_MACHINE (self));
+ g_return_if_fail (state != NULL);
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (property != NULL);
+
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
+ property);
+ g_return_if_fail (pspec != NULL);
+
+ G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args, 0, &error);
+
+ if (error != NULL)
+ {
+ g_critical ("%s: %s", G_STRFUNC, error);
+ g_free (error);
+ }
+ else
+ {
+ egg_state_machine_add_propertyv (self, state, object,
+ property, &value);
+ }
+
+ g_value_unset (&value);
+}
+
+void
+egg_state_machine_add_propertyv (EggStateMachine *self,
+ const gchar *state,
+ gpointer object,
+ const gchar *property,
+ const GValue *value)
{
EggState *state_obj;
EggStateProperty *state_prop;
diff --git a/contrib/egg/egg-state-machine.h b/contrib/egg/egg-state-machine.h
index 2a10520..96b4a23 100644
--- a/contrib/egg/egg-state-machine.h
+++ b/contrib/egg/egg-state-machine.h
@@ -42,6 +42,17 @@ void egg_state_machine_add_property (EggStateMachine *self,
const gchar *state,
gpointer object,
const gchar *property,
+ ...);
+void egg_state_machine_add_property_valist
+ (EggStateMachine *self,
+ const gchar *state,
+ gpointer object,
+ const gchar *property,
+ va_list var_args);
+void egg_state_machine_add_propertyv (EggStateMachine *self,
+ const gchar *state,
+ gpointer object,
+ const gchar *property,
const GValue *value);
void egg_state_machine_add_binding (EggStateMachine *self,
const gchar *state,
diff --git a/tests/test-egg-state-machine.c b/tests/test-egg-state-machine.c
index 849a43b..d52731a 100644
--- a/tests/test-egg-state-machine.c
+++ b/tests/test-egg-state-machine.c
@@ -196,14 +196,6 @@ test_state_machine_basic (void)
TestObject *dummy;
TestObject *obj1;
TestObject *obj2;
- GValue vtrue = { 0 };
- GValue vfalse = { 0 };
-
- g_value_init (&vtrue, G_TYPE_BOOLEAN);
- g_value_set_boolean (&vtrue, TRUE);
-
- g_value_init (&vfalse, G_TYPE_BOOLEAN);
- g_value_set_boolean (&vfalse, FALSE);
machine = egg_state_machine_new ();
g_object_add_weak_pointer (G_OBJECT (machine), (gpointer *)&machine);
@@ -227,9 +219,9 @@ test_state_machine_basic (void)
egg_state_machine_add_binding (machine, "state1", obj1, "string", dummy, "string", 0);
egg_state_machine_add_binding (machine, "state2", obj2, "string", dummy, "string", 0);
- egg_state_machine_add_property (machine, "state1", action, "enabled", &vtrue);
- egg_state_machine_add_property (machine, "state2", action, "enabled", &vfalse);
- egg_state_machine_add_property (machine, "state3", action, "enabled", &vfalse);
+ egg_state_machine_add_property (machine, "state1", action, "enabled", TRUE);
+ egg_state_machine_add_property (machine, "state2", action, "enabled", FALSE);
+ egg_state_machine_add_property (machine, "state3", action, "enabled", FALSE);
g_assert_cmpint (g_action_get_enabled (G_ACTION (action)), ==, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]