Re: PATCH: G_DEFINE_INTERFACE_TYPE macro



*EDIT:* forgot to attach them

Corrected last remaining bugs (i had Class instead of Iface) and already
compiled/tested it.
I am sending two patches patch #1 has the 
egg_foobar_class_init (EggFoobarIface *klass) convention. The second
patch has egg_foobar_iface_init (EggFoobarIface *iface) which is what i
think as a more appropriate convention to interfaces.

On Wed, 2004-08-25 at 16:07, Tiago Cogumbreiro wrote:
> Added _WITH_CODE variants, pointed out by rambokid
> 
> On Wed, 2004-08-25 at 15:58, Tiago Cogumbreiro wrote:
> > I've added support for class_init in the macro (pointed out by Owen).
> > On Wed, 2004-08-25 at 15:42, Tiago Cogumbreiro wrote:
> > > After some suggestions on #gtk+ I've made some changes to the macro
> > > definition, hope it's better now :)
> > > 
> > > On Wed, 2004-08-25 at 15:26, Tiago Cogumbreiro wrote:
> > > > I've implemented a macro that i find it to be missing to the
> > > > G_DEFINE_*_TYPE: G_DEFINE_INTERFACE_TYPE
> > > > 
> > > > As the name infers it's supposed to define the get_type function which
> > > > defines an interface.
> > > > 
> > > > 
> > > > ______________________________________________________________________
> > > > _______________________________________________
> > > > gtk-devel-list mailing list
> > > > gtk-devel-list gnome org
> > > > http://mail.gnome.org/mailman/listinfo/gtk-devel-list
> > > 
> > > ______________________________________________________________________
> > > _______________________________________________
> > > gtk-devel-list mailing list
> > > gtk-devel-list gnome org
> > > http://mail.gnome.org/mailman/listinfo/gtk-devel-list
> > 
> > ______________________________________________________________________
> > _______________________________________________
> > gtk-devel-list mailing list
> > gtk-devel-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtk-devel-list
> 
> ______________________________________________________________________
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
--- /home/tiago/Downloads/gtype.h	2004-08-25 14:49:54.201027072 +0000
+++ gtype.h	2004-08-25 21:59:00.807947880 +0000
@@ -344,6 +344,29 @@ gpointer g_type_instance_get_private    
   }; \
   g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
 }
+/*
+ * Convenience macro to ease the interface definition. Works like G_DEFINE_TYPE.
+ */
+#define G_DEFINE_INTERFACE_TYPE(TN,t_n)                     G_DEFINE_INTERFACE_TYPE_WITH_CODE (TN, t_n, {})
+#define G_DEFINE_INTERFACE_TYPE_WITH_CODE(TypeName, type_name, CODE) \
+static void     type_name##_class_init        (TypeName##Iface *klass); \
+GType \
+type_name##_get_type (void) \
+{ \
+  static GType g_define_interface_id = 0; \
+  if (G_UNLIKELY (g_define_interface_id == 0)) \
+    { \
+      static const GTypeInfo g_define_type_info = { \
+        sizeof (TypeName##Iface), \
+        (GBaseInitFunc) NULL, \
+        (GBaseFinalizeFunc) NULL, \
+        (GClassInitFunc) type_name##_class_init, \
+      }; \
+      g_define_interface_id = g_type_register_static (G_TYPE_INTERFACE, #TypeName, &g_define_type_info, 0); \
+    } \
+    { CODE ;} \
+  return g_define_interface_id; \
+}
 
 #define G_DEFINE_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
 \
--- /home/tiago/Downloads/gtype.h	2004-08-25 14:49:54.201027072 +0000
+++ gtype2.h	2004-08-25 22:33:38.695061024 +0000
@@ -344,6 +344,29 @@ gpointer g_type_instance_get_private    
   }; \
   g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
 }
+/*
+ * Convenience macro to ease the interface definition. Works like G_DEFINE_TYPE.
+ */
+#define G_DEFINE_INTERFACE_TYPE(TN,t_n)                     G_DEFINE_INTERFACE_TYPE_WITH_CODE (TN, t_n, {})
+#define G_DEFINE_INTERFACE_TYPE_WITH_CODE(TypeName, type_name, CODE) \
+static void     type_name##_iface_init        (TypeName##Iface *iface); \
+GType \
+type_name##_get_type (void) \
+{ \
+  static GType g_define_interface_id = 0; \
+  if (G_UNLIKELY (g_define_interface_id == 0)) \
+    { \
+      static const GTypeInfo g_define_type_info = { \
+        sizeof (TypeName##Iface), \
+        (GBaseInitFunc) NULL, \
+        (GBaseFinalizeFunc) NULL, \
+        (GClassInitFunc) type_name##_iface_init, \
+      }; \
+      g_define_interface_id = g_type_register_static (G_TYPE_INTERFACE, #TypeName, &g_define_type_info, 0); \
+    } \
+    { CODE ;} \
+  return g_define_interface_id; \
+}
 
 #define G_DEFINE_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
 \


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