add a new param spec to handle interfaces.
authorJonathan Blandford <jrb@redhat.com>
Tue, 6 Mar 2001 00:29:46 +0000 (00:29 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Tue, 6 Mar 2001 00:29:46 +0000 (00:29 +0000)
Mon Mar  5 15:26:30 2001  Jonathan Blandford  <jrb@redhat.com>

* gparamspecs.c (g_param_spec_interface): add a new param spec to
handle interfaces.

gobject/ChangeLog
gobject/gparamspecs.c
gobject/gparamspecs.h
gobject/gtype.h

index c97705f..9f51b5b 100644 (file)
@@ -1,3 +1,8 @@
+Mon Mar  5 15:26:30 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gparamspecs.c (g_param_spec_interface): add a new param spec to
+       handle interfaces.
+
 Wed Feb 21 18:31:46 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gsignal.h (g_signal_connect): Add g_signal_connect define to
index cc40f73..358041c 100644 (file)
@@ -680,6 +680,12 @@ param_spec_object_init (GParamSpec *pspec)
 }
 
 static void
+param_spec_interface_init (GParamSpec *pspec)
+{
+  /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
+}
+
+static void
 param_object_set_default (GParamSpec *pspec,
                          GValue     *value)
 {
@@ -713,6 +719,33 @@ param_object_values_cmp (GParamSpec   *pspec,
 }
 
 static void
+param_interface_set_default (GParamSpec *pspec,
+                            GValue     *value)
+{
+  value->data[0].v_pointer = NULL;
+}
+
+static gboolean
+param_interface_validate (GParamSpec *pspec,
+                         GValue     *value)
+{
+  guint changed = 0;
+  
+  if (value->data[0].v_pointer == NULL)
+    changed++;
+
+  return changed;
+}
+
+static gint
+param_interface_values_cmp (GParamSpec   *pspec,
+                           const GValue *value1,
+                           const GValue *value2)
+{
+  return value1->data[0].v_pointer != value2->data[0].v_pointer;
+}
+
+static void
 value_exch_memcpy (GValue *value1,
                   GValue *value2)
 {
@@ -1134,6 +1167,23 @@ g_param_spec_types_init (void)   /* sync with gtype.c */
     type = g_param_type_register_static ("GParamObject", &pspec_info);
     g_assert (type == G_TYPE_PARAM_OBJECT);
   }
+
+  /* G_TYPE_PARAM_INTERFACE
+   */
+  {
+    static const GParamSpecTypeInfo pspec_info = {
+      sizeof (GParamSpecInterface),    /* instance_size */
+      4,                               /* n_preallocs */
+      param_spec_interface_init,       /* instance_init */
+      G_TYPE_INTERFACE,                        /* value_type */
+      NULL,                            /* finalize */
+      param_interface_set_default,     /* value_set_default */
+      param_interface_validate,                /* value_validate */
+      param_interface_values_cmp,      /* values_cmp */
+    };
+    type = g_param_type_register_static ("GParamInterface", &pspec_info);
+    g_assert (type == G_TYPE_PARAM_INTERFACE);
+  }
   
   g_value_register_exchange_func (G_TYPE_CHAR,    G_TYPE_UCHAR,   value_exch_memcpy);
   g_value_register_exchange_func (G_TYPE_CHAR,    G_TYPE_BOOLEAN, value_exch_memcpy);
@@ -1576,3 +1626,25 @@ g_param_spec_object (const gchar *name,
   
   return G_PARAM_SPEC (ospec);
 }
+
+GParamSpec*
+g_param_spec_interface (const gchar *name,
+                       const gchar *nick,
+                       const gchar *blurb,
+                       GType        interface_type,
+                       GParamFlags  flags)
+{
+  GParamSpecInterface *ispec;
+  
+  g_return_val_if_fail (G_TYPE_IS_INTERFACE (interface_type), NULL);
+  
+  ispec = g_param_spec_internal (G_TYPE_PARAM_INTERFACE,
+                                name,
+                                nick,
+                                blurb,
+                                flags);
+  G_PARAM_SPEC (ispec)->value_type = interface_type;
+  
+  return G_PARAM_SPEC (ispec);
+}
+
index a455063..a3dc723 100644 (file)
@@ -68,6 +68,8 @@ extern "C" {
 #define G_PARAM_SPEC_BOXED(pspec)        (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOXED, GParamSpecBoxed))
 #define G_IS_PARAM_SPEC_OBJECT(pspec)    (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_OBJECT))
 #define G_PARAM_SPEC_OBJECT(pspec)       (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_OBJECT, GParamSpecObject))
+#define G_IS_PARAM_SPEC_INTERFACE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INTERFACE))
+#define G_PARAM_SPEC_INTERFACE(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INTERFACE, GParamSpecInterface))
 
 
 /* --- typedefs & structures --- */
@@ -88,6 +90,7 @@ typedef struct _GParamSpecPointer   GParamSpecPointer;
 typedef struct _GParamSpecCCallback GParamSpecCCallback;
 typedef struct _GParamSpecBoxed     GParamSpecBoxed;
 typedef struct _GParamSpecObject    GParamSpecObject;
+typedef struct _GParamSpecInterface GParamSpecInterface;
 struct _GParamSpecChar
 {
   GParamSpec    parent_instance;
@@ -205,6 +208,10 @@ struct _GParamSpecObject
 {
   GParamSpec    parent_instance;
 };
+struct _GParamSpecInterface
+{
+  GParamSpec    parent_instance;
+};
 
 
 /* --- GParamSpec prototypes --- */
@@ -314,6 +321,11 @@ GParamSpec*     g_param_spec_object     (const gchar    *name,
                                          const gchar    *blurb,
                                          GType           object_type,
                                          GParamFlags     flags);
+GParamSpec*     g_param_spec_interface  (const gchar    *name,
+                                         const gchar    *nick,
+                                         const gchar    *blurb,
+                                         GType           object_type,
+                                         GParamFlags     flags);
 
 
 #ifdef __cplusplus
index d3604e3..b251c39 100644 (file)
@@ -96,7 +96,8 @@ typedef enum    /*< skip >*/
   G_TYPE_PARAM_POINTER          = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14),
   G_TYPE_PARAM_CCALLBACK        = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15),
   G_TYPE_PARAM_BOXED            = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16),
-  G_TYPE_PARAM_OBJECT           = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17)
+  G_TYPE_PARAM_OBJECT           = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17),
+  G_TYPE_PARAM_INTERFACE        = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 18)
 } GTypeFundamentals;