all interface examples use 'interface' instead of 'class'

This commit is contained in:
Stefan Kost 2005-04-23 09:50:36 +00:00
parent f57a5c33c3
commit 0979140060
3 changed files with 53 additions and 47 deletions

View File

@ -1,3 +1,9 @@
2005-04-23 Stefan Kost <ensonic@users.sf.net>
* gobject/tut_gtype.xml:
* gobject/tut_howto.xml:
all interface examples use 'interface' instead of 'class'
2005-04-22 Stefan Kost <ensonic@users.sf.net> 2005-04-22 Stefan Kost <ensonic@users.sf.net>
* gobject/Makefile.am: * gobject/Makefile.am:
@ -88,7 +94,7 @@
2005-01-04 Matthias Clasen <mclasen@redhat.com> 2005-01-04 Matthias Clasen <mclasen@redhat.com>
* gobject/tmpl/signals.sgml: Small addition. (#145158, * gobject/tmpl/signals.sgml: Small addition. (#145158,
Mariano Suárez-Alvarez) Mariano Su??rez-Alvarez)
2004-12-20 Matthias Clasen <mclasen@redhat.com> 2004-12-20 Matthias Clasen <mclasen@redhat.com>
@ -521,7 +527,7 @@ Wed Jan 28 01:39:59 2004 Matthias Clasen <maclas@gmx.de>
Thu Jan 22 14:51:19 2004 Owen Taylor <otaylor@redhat.com> Thu Jan 22 14:51:19 2004 Owen Taylor <otaylor@redhat.com>
* glib/glib-sections.txt glib/tmpl/timers.sgml: Document * glib/glib-sections.txt glib/tmpl/timers.sgml: Document
g_timer_continue. (Tim-Philipp Müller) g_timer_continue. (Tim-Philipp M??ller)
Sun Jan 11 01:25:44 2004 Matthias Clasen <maclas@gmx.de> Sun Jan 11 01:25:44 2004 Matthias Clasen <maclas@gmx.de>
@ -657,7 +663,7 @@ Mon Oct 20 01:12:46 2003 Matthias Clasen <maclas@gmx.de>
Sun Oct 19 22:18:28 2003 Matthias Clasen <maclas@gmx.de> Sun Oct 19 22:18:28 2003 Matthias Clasen <maclas@gmx.de>
* gobject/Makefile.am (INCLUDES): Add $(top_builddir)/glib * gobject/Makefile.am (INCLUDES): Add $(top_builddir)/glib
as an include dir. (#124934, Mariano Suárez-Alvarez) as an include dir. (#124934, Mariano Su??rez-Alvarez)
Sun Oct 19 00:33:28 2003 Matthias Clasen <maclas@gmx.de> Sun Oct 19 00:33:28 2003 Matthias Clasen <maclas@gmx.de>

View File

@ -649,17 +649,15 @@ The class initialization process is entirely implemented in
you have to register a non-instantiable classed type which derives from you have to register a non-instantiable classed type which derives from
<type><link linkend="GTypeInterface">GTypeInterface</link></type>. The following piece of code declares such an interface. <type><link linkend="GTypeInterface">GTypeInterface</link></type>. The following piece of code declares such an interface.
<programlisting> <programlisting>
#define MAMAN_IBAZ_TYPE (maman_ibaz_get_type ()) #define MAMAN_IBAZ_TYPE (maman_ibaz_get_type ())
#define MAMAN_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_IBAZ_TYPE, MamanIbaz)) #define MAMAN_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_IBAZ_TYPE, MamanIbaz))
#define MAMAN_IBAZ_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MAMAN_IBAZ_TYPE, MamanIbazClass)) #define MAMAN_IS_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_IBAZ_TYPE))
#define MAMAN_IS_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_IBAZ_TYPE)) #define MAMAN_IBAZ_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), MAMAN_IBAZ_TYPE, MamanIbazInterface))
#define MAMAN_IS_IBAZ_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MAMAN_IBAZ_TYPE))
#define MAMAN_IBAZ_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), MAMAN_IBAZ_TYPE, MamanIbazClass))
typedef struct _MamanIbaz MamanIbaz; /* dummy object */ typedef struct _MamanIbaz MamanIbaz; /* dummy object */
typedef struct _MamanIbazClass MamanIbazClass; typedef struct _MamanIbazInterface MamanIbazInterface;
struct _MamanIbazClass { struct _MamanIbazInterface {
GTypeInterface parent; GTypeInterface parent;
void (*do_action) (MamanIbaz *self); void (*do_action) (MamanIbaz *self);
@ -674,7 +672,7 @@ void maman_ibaz_do_action (MamanIbaz *self);
<programlisting> <programlisting>
void maman_ibaz_do_action (MamanIbaz *self) void maman_ibaz_do_action (MamanIbaz *self)
{ {
MAMAN_IBAZ_GET_CLASS (self)->do_action (self); MAMAN_IBAZ_GET_INTERFACE (self)->do_action (self);
} }
</programlisting> </programlisting>
<function>maman_ibaz_get_gtype</function> registers a type named <emphasis>MamanIBaz</emphasis> <function>maman_ibaz_get_gtype</function> registers a type named <emphasis>MamanIBaz</emphasis>
@ -707,8 +705,8 @@ static void
baz_interface_init (gpointer g_iface, baz_interface_init (gpointer g_iface,
gpointer iface_data) gpointer iface_data)
{ {
MamanIbazClass *klass = (MamanIbazClass *)g_iface; MamanIbazInterface *iface = (MamanIbazInterface *)g_iface;
klass->do_action = maman_baz_do_action; iface->do_action = maman_baz_do_action;
} }
GType GType
@ -717,7 +715,7 @@ maman_baz_get_type (void)
static GType type = 0; static GType type = 0;
if (type == 0) { if (type == 0) {
static const GTypeInfo info = { static const GTypeInfo info = {
sizeof (MamanBazClass), sizeof (MamanBazInterface),
NULL, /* base_init */ NULL, /* base_init */
NULL, /* base_finalize */ NULL, /* base_finalize */
NULL, /* class_init */ NULL, /* class_init */
@ -799,7 +797,7 @@ struct _GInterfaceInfo
multiple implementations of the interface: multiple implementations of the interface:
<programlisting> <programlisting>
static void static void
maman_ibaz_base_init (gpointer g_class) maman_ibaz_base_init (gpointer g_iface)
{ {
static gboolean initialized = FALSE; static gboolean initialized = FALSE;

View File

@ -776,18 +776,16 @@ b_method_to_call (B *obj, int a)
#include &lt;glib-object.h&gt; #include &lt;glib-object.h&gt;
#define MAMAN_TYPE_IBAZ (maman_ibaz_get_type ()) #define MAMAN_TYPE_IBAZ (maman_ibaz_get_type ())
#define MAMAN_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_IBAZ, MamanIbaz)) #define MAMAN_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_IBAZ, MamanIbaz))
#define MAMAN_IBAZ_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MAMAN_TYPE_IBAZ, MamanIbazClass)) #define MAMAN_IS_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_TYPE_IBAZ))
#define MAMAN_IS_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_TYPE_IBAZ)) #define MAMAN_IBAZ_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), MAMAN_TYPE_IBAZ, MamanIbazInterface))
#define MAMAN_IS_IBAZ_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MAMAN_TYPE_IBAZ))
#define MAMAN_IBAZ_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), MAMAN_TYPE_IBAZ, MamanIbazClass))
typedef struct _MamanIbaz MamanIbaz; /* dummy object */ typedef struct _MamanIbaz MamanIbaz; /* dummy object */
typedef struct _MamanIbazClass MamanIbazClass; typedef struct _MamanIbazInterface MamanIbazInterface;
struct _MamanIbazClass { struct _MamanIbazInterface {
GTypeInterface parent; GTypeInterface parent;
void (*do_action) (MamanIbaz *self); void (*do_action) (MamanIbaz *self);
@ -803,8 +801,9 @@ void maman_ibaz_do_action (MamanIbaz *self);
which derives from a <type><link linkend="GObject">GObject</link></type> except for a few details: which derives from a <type><link linkend="GObject">GObject</link></type> except for a few details:
<itemizedlist> <itemizedlist>
<listitem><para> <listitem><para>
The <function>_GET_CLASS</function> macro is not implemented with The <function>_GET_CLASS</function> macro is called <function>_GET_INTERFACE</function>
<function>G_TYPE_INSTANCE_GET_CLASS</function> but with <function>G_TYPE_INSTANCE_GET_INTERFACE</function>. and not implemented with <function><link linkend="G_TYPE_INSTANCE_GET_CLASS">G_TYPE_INSTANCE_GET_CLASS</link></function>
but with <function><link linkend="G_TYPE_INSTANCE_GET_INTERFACE">G_TYPE_INSTANCE_GET_INTERFACE</link></function>.
</para></listitem> </para></listitem>
<listitem><para> <listitem><para>
The instance type, <type>MamanIbaz</type> is not fully defined: it is used merely as an abstract The instance type, <type>MamanIbaz</type> is not fully defined: it is used merely as an abstract
@ -848,7 +847,7 @@ maman_ibaz_get_type (void)
static GType type = 0; static GType type = 0;
if (type == 0) { if (type == 0) {
static const GTypeInfo info = { static const GTypeInfo info = {
sizeof (MamanIbazClass), sizeof (MamanIbazInterface),
maman_ibaz_base_init, /* base_init */ maman_ibaz_base_init, /* base_init */
NULL, /* base_finalize */ NULL, /* base_finalize */
NULL, /* class_init */ NULL, /* class_init */
@ -865,7 +864,7 @@ maman_ibaz_get_type (void)
void maman_ibaz_do_action (MamanIbaz *self) void maman_ibaz_do_action (MamanIbaz *self)
{ {
MAMAN_IBAZ_GET_CLASS (self)->do_action (self); MAMAN_IBAZ_GET_INTERFACE (self)->do_action (self);
} }
</programlisting> </programlisting>
</para> </para>
@ -969,14 +968,14 @@ static void
baz_interface_init (gpointer g_iface, baz_interface_init (gpointer g_iface,
gpointer iface_data) gpointer iface_data)
{ {
MamanIbazClass *klass = (MamanIbazClass *)g_iface; MamanIbazInteface *iface = (MamanIbazInteface *)g_iface;
klass->do_action = (void (*) (MamanIbaz *self))baz_do_action; iface->do_action = (void (*) (MamanIbaz *self))baz_do_action;
} }
static void static void
baz_instance_init (GTypeInstance *instance, baz_instance_init (GTypeInstance *instance,
gpointer g_class) gpointer g_class)
{ {
MamanBaz *self = (MamanBaz *)instance; MamanBaz *self = MAMAN_BAZ(instance);
self->instance_member = 0xdeadbeaf; self->instance_member = 0xdeadbeaf;
} }
</programlisting> </programlisting>
@ -1016,8 +1015,8 @@ static void
ibar_interface_init (gpointer g_iface, ibar_interface_init (gpointer g_iface,
gpointer iface_data) gpointer iface_data)
{ {
MamanIbarClass *klass = (MamanIbarClass *)g_iface; MamanIbarInterface *iface = (MamanIbarInterface *)g_iface;
klass->do_another_action = (void (*) (MamanIbar *self))ibar_do_another_action; iface->do_another_action = (void (*) (MamanIbar *self))ibar_do_another_action;
} }
@ -1030,8 +1029,8 @@ static void
ibaz_interface_init (gpointer g_iface, ibaz_interface_init (gpointer g_iface,
gpointer iface_data) gpointer iface_data)
{ {
MamanIbazClass *klass = (MamanIbazClass *)g_iface; MamanIbazInterface *iface = (MamanIbazInterface *)g_iface;
klass->do_action = (void (*) (MamanIbaz *self))ibaz_do_action; iface->do_action = (void (*) (MamanIbaz *self))ibaz_do_action;
} }
@ -1063,7 +1062,7 @@ maman_bar_get_type (void)
static const GInterfaceInfo ibar_info = { static const GInterfaceInfo ibar_info = {
(GInterfaceInitFunc) ibar_interface_init, /* interface_init */ (GInterfaceInitFunc) ibar_interface_init, /* interface_init */
NULL, /* interface_finalize */ NULL, /* interface_finalize */
NULL /* interface_data */ NULL /* interface_data */
}; };
static const GInterfaceInfo ibaz_info = { static const GInterfaceInfo ibaz_info = {
(GInterfaceInitFunc) ibaz_interface_init, /* interface_init */ (GInterfaceInitFunc) ibaz_interface_init, /* interface_init */
@ -1088,11 +1087,11 @@ maman_bar_get_type (void)
no prerequisites and then on the others. no prerequisites and then on the others.
</para> </para>
<para> <para>
Complete source code showing how to define the MamanIbar interface which requires MamanIbaz and how to Complete source code showing how to define the MamanIbar interface which requires MamanIbaz and how to
implement the MamanIbar interface is located in <filename>sample/interface/maman-ibar.{h|c}</filename> implement the MamanIbar interface is located in <filename>sample/interface/maman-ibar.{h|c}</filename>
and <filename>sample/interface/maman-bar.{h|c}</filename>. and <filename>sample/interface/maman-bar.{h|c}</filename>.
</para> </para>
</sect1> </sect1>
@ -1109,25 +1108,28 @@ maman_bar_get_type (void)
<para>To include a property named 'name' of type <type>string</type> in the <para>To include a property named 'name' of type <type>string</type> in the
<type>maman_ibaz</type> interface example code above, we only need to add one <type>maman_ibaz</type> interface example code above, we only need to add one
<footnote> <footnote>
<para>That really is one line extended to six for the sake of clarity <para>
</para> That really is one line extended to six for the sake of clarity
</para>
</footnote> </footnote>
line in the <function>maman_ibaz_base_init</function> line in the <function>maman_ibaz_base_init</function>
<footnote> <footnote>
<para>The gobject_install_property can also be called from <function>class_init</function> but it must not be called after that point. <para>
</para> The <function><link linkend="g-object-interface-install-property">g_object_interface_install_property</link></function> can also be called from
<function>class_init</function> but it must not be called after that point.
</para>
</footnote> </footnote>
as shown below: as shown below:
<programlisting> <programlisting>
static void static void
maman_ibaz_base_init (gpointer g_class) maman_ibaz_base_init (gpointer g_iface)
{ {
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
if (!initialized) { if (!initialized) {
/* create interface signals here. */ /* create interface signals here. */
g_object_interface_install_property (g_class, g_object_interface_install_property (g_iface,
g_param_spec_string ("name", g_param_spec_string ("name",
"maman_ibaz_name", "maman_ibaz_name",
"Name of the MamanIbaz", "Name of the MamanIbaz",