[glib/wip/gobjectnew: 3/4] paramspec changes



commit 5154a152777f02d6e2d67ca4dd877a7cee1b2c04
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Apr 1 14:52:08 2013 -0400

    paramspec changes

 gobject/gparam.c      | 34 ++++++++++++++++++++++++
 gobject/gparam.h      |  4 ++-
 gobject/gparamspecs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 gobject/gparamspecs.h | 58 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 165 insertions(+), 2 deletions(-)
---
diff --git a/gobject/gparam.c b/gobject/gparam.c
index b2958ac..08f694d 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -654,6 +654,40 @@ g_param_value_validate (GParamSpec *pspec,
   return FALSE;
 }
 
+#if 0
+gboolean
+g_param_value_is_valid (GParamSpec   *pspec,
+                        const GValue *value)
+{
+  GParamSpecClass *class;
+  gboolean valid;
+
+  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
+  g_return_val_if_fail (G_IS_VALUE (value), FALSE);
+
+  if (value->g_type != pspec->value_type)
+    return FALSE;
+
+  class = G_PARAM_SPEC_GET_CLASS (pspec);
+
+  if (class->value_is_valid == NULL)
+    {
+      /* Need to emulate this the slow way... */
+      GValue copy = { 0, };
+      gboolean valid;
+
+      g_value_init (&copy, value->g_type);
+      g_value_copy (value, &copy);
+      valid = !g_param_value_validate (pspec, value);
+      g_value_unset (copy);
+    }
+  else
+    valid = class->value_is_valid (pspec, value);
+
+  return valid;
+}
+#endif
+
 /**
  * g_param_value_convert:
  * @pspec: a valid #GParamSpec
diff --git a/gobject/gparam.h b/gobject/gparam.h
index b35ad51..315c428 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -252,8 +252,10 @@ struct _GParamSpecClass
   gint          (*values_cmp)           (GParamSpec   *pspec,
                                         const GValue *value1,
                                         const GValue *value2);
+  gboolean      (*value_is_valid)       (GParamSpec   *pspec,
+                                         const GValue *value);
   /*< private >*/
-  gpointer       dummy[4];
+  gpointer       dummy[3];
 };
 /**
  * GParameter:
diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c
index fb5ce50..1481486 100644
--- a/gobject/gparamspecs.c
+++ b/gobject/gparamspecs.c
@@ -1059,6 +1059,57 @@ param_override_values_cmp (GParamSpec   *pspec,
 }
 
 static void
+param_default_init (GParamSpec *pspec)
+{
+  /* GParamSpecDefault *dspec = G_PARAM_SPEC_DEFAULT (pspec); */
+}
+
+static void
+param_default_finalize (GParamSpec *pspec)
+{
+  GParamSpecDefault *dspec = G_PARAM_SPEC_OVERRIDE (pspec);
+  GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
+
+  if (dspec->implementation)
+    {
+      g_param_spec_unref (dspec->implementation);
+      dspec->implementation = NULL;
+    }
+
+  g_value_unset (&dspec->default_value);
+
+  parent_class->finalize (pspec);
+}
+
+static void
+param_default_set_default (GParamSpec *pspec,
+                           GValue     *value)
+{
+  GParamSpecDefault *dspec = G_PARAM_SPEC_OVERRIDE (pspec);
+
+  g_value_copy (&dpspec->default_value, value);
+}
+
+static gboolean
+param_default_validate (GParamSpec *pspec,
+                        GValue     *value)
+{
+  GParamSpecDefault *dspec = G_PARAM_SPEC_OVERRIDE (pspec);
+
+  return g_param_value_validate (dspec->implementation, value);
+}
+
+static gint
+param_default_values_cmp (GParamSpec   *pspec,
+                          const GValue *value1,
+                          const GValue *value2)
+{
+  GParamSpecDefault *dspec = G_PARAM_SPEC_OVERRIDE (pspec);
+
+  return g_param_values_cmp (dspec->implementation, value1, value2);
+}
+
+static void
 param_gtype_init (GParamSpec *pspec)
 {
 }
@@ -1166,7 +1217,7 @@ GType *g_param_spec_types = NULL;
 void
 _g_param_spec_types_init (void)        
 {
-  const guint n_types = 23;
+  const guint n_types = 24;
   GType type, *spec_types, *spec_types_bound;
 
   g_param_spec_types = g_new0 (GType, n_types);
@@ -1589,6 +1640,24 @@ _g_param_spec_types_init (void)
     g_assert (type == G_TYPE_PARAM_VARIANT);
   }
 
+  /* G_TYPE_PARAM_DEFAULT
+   */
+  {
+    static const GParamSpecTypeInfo pspec_info = {
+      sizeof (GParamSpecDefault), /* instance_size */
+      16,                         /* n_preallocs */
+      param_default_init,         /* instance_init */
+      G_TYPE_NONE,                /* value_type */
+      param_default_finalize,     /* finalize */
+      param_default_set_default,  /* value_set_default */
+      param_default_validate,     /* value_validate */
+      param_default_values_cmp,   /* values_cmp */
+    };
+    type = g_param_type_register_static (g_intern_static_string ("GParamDefault"), &pspec_info);
+    *spec_types++ = type;
+    g_assert (type == G_TYPE_PARAM_DEFAULT);
+  }
+
   g_assert (spec_types == spec_types_bound);
 }
 
diff --git a/gobject/gparamspecs.h b/gobject/gparamspecs.h
index b3245a8..a7fc97f 100644
--- a/gobject/gparamspecs.h
+++ b/gobject/gparamspecs.h
@@ -583,6 +583,33 @@ G_BEGIN_DECLS
  * Since: 2.26
  */
 #define G_PARAM_SPEC_VARIANT(pspec)         (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_VARIANT, 
GParamSpecVariant))
+/**
+ * G_TYPE_PARAM_DEFAULT:
+ *
+ * The #GType of #GParamSpecDefault.
+ *
+ * Since: 2.38
+ */
+#define G_TYPE_PARAM_DEFAULT                (g_param_spec_types[23])
+/**
+ * G_IS_PARAM_SPEC_DEFAULT:
+ * @pspec: a #GParamSpec
+ *
+ * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_DEFAULT.
+ *
+ * Since: 2.38
+ * Returns: %TRUE on success.
+ */
+#define G_IS_PARAM_SPEC_DEFAULT(pspec)      (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_DEFAULT))
+/**
+ * G_PARAM_SPEC_DEFAULT:
+ * @pspec: a #GParamSpec
+ *
+ * Casts a #GParamSpec into a #GParamSpecDefault.
+ *
+ * Since: 2.38
+ */
+#define G_PARAM_SPEC_DEFAULT(pspec)       (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_DEFAULT, 
GParamSpecDefault))
 
 /* --- typedefs & structures --- */
 typedef struct _GParamSpecChar       GParamSpecChar;
@@ -608,6 +635,7 @@ typedef struct _GParamSpecObject     GParamSpecObject;
 typedef struct _GParamSpecOverride   GParamSpecOverride;
 typedef struct _GParamSpecGType      GParamSpecGType;
 typedef struct _GParamSpecVariant    GParamSpecVariant;
+typedef struct _GParamSpecDefault    GParamSpecDefault;
 
 /**
  * GParamSpecChar:
@@ -956,6 +984,7 @@ struct _GParamSpecGType
   GParamSpec    parent_instance;
   GType         is_a_type;
 };
+
 /**
  * GParamSpecVariant:
  * @parent_instance: private #GParamSpec portion
@@ -976,6 +1005,35 @@ struct _GParamSpecVariant
   gpointer      padding[4];
 };
 
+/**
+ * GParamSpecDefault:
+ *
+ * This type of #GParamSpec does not define a new property but changes
+ * the default value for an existing property.
+ *
+ * It is used in subclasses of the class which the property is
+ * associated with to change the default value for all instances of the
+ * subclass.
+ *
+ * g_param_set_default() will get the modified default value.  As with
+ * #GParamSpecOverride, g_param_spec_get_redirect_target() will find the
+ * highest-level #GParamSpec for the property (ie: the one that defines
+ * the interface).  If you want to find the #GParamSpec defined by the
+ * type to which the g_object_set_property() call will be delivered, use
+ * g_param_spec_get_implementation().
+ *
+ * Since: 2.38
+ */
+struct _GParamSpecVariant
+{
+  GParamSpec    parent_instance;
+  GVariantType *type;
+  GVariant     *default_value;
+
+  /*< private >*/
+  gpointer      padding[4];
+};
+
 /* --- GParamSpec prototypes --- */
 GLIB_AVAILABLE_IN_ALL
 GParamSpec*    g_param_spec_char        (const gchar    *name,


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