mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-09 03:59:42 +02:00
Use correct naming conventions when explaining maman_bar_get_type().
* docs/reference/gobject/tut_gtype.xml: Use correct naming conventions when explaining maman_bar_get_type(). (#493688) Mention G_DEFINE_TYPE. svn path=/trunk/; revision=5799
This commit is contained in:
parent
96fe690d5a
commit
9b79a12192
@ -1,3 +1,8 @@
|
|||||||
|
2007-11-05 Mathias Hasselmann <mathias@openismus.com>
|
||||||
|
|
||||||
|
* docs/reference/gobject/tut_gtype.xml: Use correct naming conventions
|
||||||
|
when explaining maman_bar_get_type(). (#493688) Mention G_DEFINE_TYPE.
|
||||||
|
|
||||||
2007-10-16 Matthias Clasen <mclasen@redhat.com>
|
2007-10-16 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gobject/tmpl/gparamspec.sgml: Small update (#477704, Ross Burton)
|
* gobject/tmpl/gparamspec.sgml: Small update (#477704, Ross Burton)
|
||||||
|
@ -159,9 +159,9 @@ static void test_object (void)
|
|||||||
GObject *obj;
|
GObject *obj;
|
||||||
GValue obj_vala = {0, };
|
GValue obj_vala = {0, };
|
||||||
GValue obj_valb = {0, };
|
GValue obj_valb = {0, };
|
||||||
obj = g_object_new (MAMAN_BAR_TYPE, NULL);
|
obj = g_object_new (MAMAN_TYPE_BAR, NULL);
|
||||||
|
|
||||||
g_value_init (&obj_vala, MAMAN_BAR_TYPE);
|
g_value_init (&obj_vala, MAMAN_TYPE_BAR);
|
||||||
g_value_set_object (&obj_vala, obj);
|
g_value_set_object (&obj_vala, obj);
|
||||||
|
|
||||||
g_value_init (&obj_valb, G_TYPE_OBJECT);
|
g_value_init (&obj_valb, G_TYPE_OBJECT);
|
||||||
@ -169,7 +169,7 @@ static void test_object (void)
|
|||||||
/* g_value_copy's semantics for G_TYPE_OBJECT types is to copy the reference.
|
/* g_value_copy's semantics for G_TYPE_OBJECT types is to copy the reference.
|
||||||
This function thus calls g_object_ref.
|
This function thus calls g_object_ref.
|
||||||
It is interesting to note that the assignment works here because
|
It is interesting to note that the assignment works here because
|
||||||
MAMAN_BAR_TYPE is a G_TYPE_OBJECT.
|
MAMAN_TYPE_BAR is a G_TYPE_OBJECT.
|
||||||
*/
|
*/
|
||||||
g_value_copy (&obj_vala, &obj_valb);
|
g_value_copy (&obj_vala, &obj_valb);
|
||||||
|
|
||||||
@ -246,10 +246,10 @@ struct _GTypeValueTable
|
|||||||
prefix all your function names with <emphasis>maman_</emphasis>.
|
prefix all your function names with <emphasis>maman_</emphasis>.
|
||||||
For example: <function>maman_object_method</function>.
|
For example: <function>maman_object_method</function>.
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>Create a macro named <function>PREFIX_OBJECT_TYPE</function> which always
|
<listitem><para>Create a macro named <function>PREFIX_TYPE_OBJECT</function> which always
|
||||||
returns the GType for the associated object type. For an object of type
|
returns the GType for the associated object type. For an object of type
|
||||||
<emphasis>Bar</emphasis> in a libray prefixed by <emphasis>maman</emphasis>,
|
<emphasis>Bar</emphasis> in a libray prefixed by <emphasis>maman</emphasis>,
|
||||||
use: <function>MAMAN_BAR_TYPE</function>.
|
use: <function>MAMAN_TYPE_BAR</function>.
|
||||||
It is common although not a convention to implement this macro using either a global
|
It is common although not a convention to implement this macro using either a global
|
||||||
static variable or a function named <function>prefix_object_get_type</function>.
|
static variable or a function named <function>prefix_object_get_type</function>.
|
||||||
We will follow the function pattern wherever possible in this document.
|
We will follow the function pattern wherever possible in this document.
|
||||||
@ -288,12 +288,12 @@ struct _GTypeValueTable
|
|||||||
macros are provided in <filename>gtype.h</filename>. For the example we used above, we would
|
macros are provided in <filename>gtype.h</filename>. For the example we used above, we would
|
||||||
write the following trivial code to declare the macros:
|
write the following trivial code to declare the macros:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
#define MAMAN_BAR_TYPE (maman_bar_get_type ())
|
#define MAMAN_TYPE_BAR (maman_bar_get_type ())
|
||||||
#define MAMAN_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_BAR_TYPE, MamanBar))
|
#define MAMAN_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_BAR, MamanBar))
|
||||||
#define MAMAN_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAMAN_BAR_TYPE, MamanBarClass))
|
#define MAMAN_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAMAN_TYPE_BAR, MamanBarClass))
|
||||||
#define MAMAN_IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_BAR_TYPE))
|
#define MAMAN_IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_TYPE_BAR))
|
||||||
#define MAMAN_IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAMAN_BAR_TYPE))
|
#define MAMAN_IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAMAN_TYPE_BAR))
|
||||||
#define MAMAN_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAMAN_BAR_TYPE, MamanBarClass))
|
#define MAMAN_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAMAN_TYPE_BAR, MamanBarClass))
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<note><simpara>Stick to the naming <varname>klass</varname> as <varname>class</varname> is a registered c++ keyword.</simpara></note>
|
<note><simpara>Stick to the naming <varname>klass</varname> as <varname>class</varname> is a registered c++ keyword.</simpara></note>
|
||||||
</para>
|
</para>
|
||||||
@ -318,6 +318,14 @@ GType maman_bar_get_type (void)
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
When having no special requirements you also can use the <function>G_DEFINE_TYPE</function>
|
||||||
|
macro:
|
||||||
|
<programlisting>
|
||||||
|
G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT)
|
||||||
|
</programlisting>
|
||||||
|
</para>
|
||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
<sect1 id="gtype-non-instantiable">
|
<sect1 id="gtype-non-instantiable">
|
||||||
@ -404,7 +412,7 @@ typedef struct {
|
|||||||
void (*do_action_public_pure_virtual) (MamanBar *self, guint8 i);
|
void (*do_action_public_pure_virtual) (MamanBar *self, guint8 i);
|
||||||
} MamanBarClass;
|
} MamanBarClass;
|
||||||
|
|
||||||
#define MAMAN_BAR_TYPE (maman_bar_get_type ())
|
#define MAMAN_TYPE_BAR (maman_bar_get_type ())
|
||||||
|
|
||||||
GType
|
GType
|
||||||
maman_bar_get_type (void)
|
maman_bar_get_type (void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user