mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 20:38:48 +02:00
docs: Add missing <function> elements to GObject how-to
Break the text up a little with some formatting. https://bugzilla.gnome.org/show_bug.cgi?id=744060
This commit is contained in:
parent
b6b0f5f305
commit
0344e6cb83
@ -273,14 +273,16 @@ G_DEFINE_TYPE_WITH_PRIVATE (MamanBar, maman_bar, G_TYPE_OBJECT)
|
|||||||
<xref linkend="gobject-construction-table"/> shows what user-provided functions
|
<xref linkend="gobject-construction-table"/> shows what user-provided functions
|
||||||
are invoked during object instantiation and in which order they are invoked.
|
are invoked during object instantiation and in which order they are invoked.
|
||||||
A user looking for the equivalent of the simple C++ constructor function should use
|
A user looking for the equivalent of the simple C++ constructor function should use
|
||||||
the instance_init method. It will be invoked after all the parent's instance_init
|
the <function>instance_init</function> method. It will be invoked after
|
||||||
|
all the parents’ <function>instance_init</function>
|
||||||
functions have been invoked. It cannot take arbitrary construction parameters
|
functions have been invoked. It cannot take arbitrary construction parameters
|
||||||
(as in C++) but if your object needs arbitrary parameters to complete initialization,
|
(as in C++) but if your object needs arbitrary parameters to complete initialization,
|
||||||
you can use construction properties.
|
you can use construction properties.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Construction properties will be set only after all instance_init functions have run.
|
Construction properties will be set only after all
|
||||||
|
<function>instance_init</function> functions have run.
|
||||||
No object reference will be returned to the client of <function><link linkend="g-object-new">g_object_new</link></function>
|
No object reference will be returned to the client of <function><link linkend="g-object-new">g_object_new</link></function>
|
||||||
until all the construction properties have been set.
|
until all the construction properties have been set.
|
||||||
</para>
|
</para>
|
||||||
@ -288,7 +290,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (MamanBar, maman_bar, G_TYPE_OBJECT)
|
|||||||
<para>
|
<para>
|
||||||
It is important to note that object construction cannot <emphasis>ever</emphasis>
|
It is important to note that object construction cannot <emphasis>ever</emphasis>
|
||||||
fail. If you require a fallible GObject construction, you can use the
|
fail. If you require a fallible GObject construction, you can use the
|
||||||
GInitable and GAsyncInitable interfaces provided by the GIO library
|
<link linkend="GInitable"><type>GInitable</type></link> and
|
||||||
|
<link linkend="GAsyncInitable"><type>GAsyncInitable</type></link>
|
||||||
|
interfaces provided by the GIO library.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -364,7 +368,8 @@ bar_class_init (MamanBarClass *klass)
|
|||||||
more simply, using the <function>constructed()</function> class method
|
more simply, using the <function>constructed()</function> class method
|
||||||
available since GLib 2.12. Note that the <function>constructed()</function>
|
available since GLib 2.12. Note that the <function>constructed()</function>
|
||||||
virtual function will only be invoked after the properties marked as
|
virtual function will only be invoked after the properties marked as
|
||||||
G_PARAM_CONSTRUCT_ONLY or G_PARAM_CONSTRUCT have been consumed, but
|
<function>G_PARAM_CONSTRUCT_ONLY</function>s or
|
||||||
|
<function>G_PARAM_CONSTRUCT</function> have been consumed, but
|
||||||
before the regular properties passed to <function>g_object_new()</function>
|
before the regular properties passed to <function>g_object_new()</function>
|
||||||
have been set.
|
have been set.
|
||||||
</para>
|
</para>
|
||||||
@ -485,7 +490,7 @@ maman_bar_init (MamanBar *self);
|
|||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<sect2>
|
<sect2 id="non-virtual-public-methods">
|
||||||
<title>Non-virtual public methods</title>
|
<title>Non-virtual public methods</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -509,7 +514,7 @@ maman_bar_do_action (MamanBar *self, /* parameters */)
|
|||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2>
|
<sect2 id="virtual-public-methods">
|
||||||
<title>Virtual public methods</title>
|
<title>Virtual public methods</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -570,9 +575,10 @@ maman_bar_do_action (MamanBar *self, /* parameters */)
|
|||||||
Please, note that it is possible for you to provide a default
|
Please, note that it is possible for you to provide a default
|
||||||
implementation for this class method in the object's
|
implementation for this class method in the object's
|
||||||
<function>class_init</function> function: initialize the
|
<function>class_init</function> function: initialize the
|
||||||
klass->do_action field to a pointer to the actual implementation.
|
<function>klass->do_action</function> field to a pointer to the
|
||||||
|
actual implementation.
|
||||||
By default, class methods that are not inherited are initialized to
|
By default, class methods that are not inherited are initialized to
|
||||||
NULL, and thus are to be considered "pure virtual".
|
<function>NULL</function>, and thus are to be considered "pure virtual".
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
static void
|
static void
|
||||||
maman_bar_real_do_action_two (MamanBar *self, /* parameters */)
|
maman_bar_real_do_action_two (MamanBar *self, /* parameters */)
|
||||||
@ -622,12 +628,13 @@ maman_bar_do_action_two (MamanBar *self, /* parameters */)
|
|||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2>
|
<sect2 id="virtual-private-methods">
|
||||||
<title>Virtual private Methods</title>
|
<title>Virtual private Methods</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
These are very similar to Virtual Public methods. They just don't
|
These are very similar to <link linkend="virtual-public-methods">virtual
|
||||||
have a public function to call the function directly. The header
|
public methods</link>. They just don't
|
||||||
|
have a public function to call directly. The header
|
||||||
file contains only a declaration of the virtual function:
|
file contains only a declaration of the virtual function:
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
/* declaration in maman-bar.h. */
|
/* declaration in maman-bar.h. */
|
||||||
@ -745,8 +752,8 @@ maman_bar_subtype_class_init (MamanBarSubTypeClass *klass)
|
|||||||
is used to access the original parent class structure. Its input is a
|
is used to access the original parent class structure. Its input is a
|
||||||
pointer to the class of the derived object and it returns a pointer to
|
pointer to the class of the derived object and it returns a pointer to
|
||||||
the original parent class structure. Instead of using this function
|
the original parent class structure. Instead of using this function
|
||||||
directly, though, you should use the <function>parent_class</function>
|
directly, though, use the <function>parent_class</function>
|
||||||
pointer created and initialized for us by the G_DEFINE_TYPE_* family of
|
pointer created and initialized by the <function>G_DEFINE_TYPE_*</function> family of
|
||||||
macros, for instance:
|
macros, for instance:
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
static void
|
static void
|
||||||
@ -932,9 +939,9 @@ GType maman_baz_get_type (void);
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
The second step is to implement <type>MamanBaz</type> by defining
|
The second step is to implement <type>MamanBaz</type> by defining
|
||||||
its GType. Instead of using
|
its <type>GType</type>. Instead of using
|
||||||
<function><link linkend="G-DEFINE-TYPE:CAPS">G_DEFINE_TYPE</link></function>
|
<function><link linkend="G-DEFINE-TYPE:CAPS">G_DEFINE_TYPE</link></function>,
|
||||||
we use
|
use
|
||||||
<function><link linkend="G-DEFINE-TYPE-WITH-CODE:CAPS">G_DEFINE_TYPE_WITH_CODE</link></function>
|
<function><link linkend="G-DEFINE-TYPE-WITH-CODE:CAPS">G_DEFINE_TYPE_WITH_CODE</link></function>
|
||||||
and the
|
and the
|
||||||
<function><link linkend="G-IMPLEMENT-INTERFACE:CAPS">G_IMPLEMENT_INTERFACE</link></function>
|
<function><link linkend="G-IMPLEMENT-INTERFACE:CAPS">G_IMPLEMENT_INTERFACE</link></function>
|
||||||
@ -1016,7 +1023,8 @@ G_DEFINE_INTERFACE (MamanIbar, maman_ibar, MAMAN_TYPE_IBAZ);
|
|||||||
In the <function><link linkend="G-DEFINE-INTERFACE:CAPS">G_DEFINE_INTERFACE</link></function>
|
In the <function><link linkend="G-DEFINE-INTERFACE:CAPS">G_DEFINE_INTERFACE</link></function>
|
||||||
call above, the third parameter defines the prerequisite type. This
|
call above, the third parameter defines the prerequisite type. This
|
||||||
is the GType of either an interface or a class. In this case
|
is the GType of either an interface or a class. In this case
|
||||||
the MamanIbaz interface is a prerequisite of the MamanIbar. The code
|
the <type>MamanIbaz</type> interface is a prerequisite of
|
||||||
|
<type>MamanIbar</type>. The code
|
||||||
below shows how an implementation can implement both interfaces and
|
below shows how an implementation can implement both interfaces and
|
||||||
register their implementations:
|
register their implementations:
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
@ -1225,10 +1233,11 @@ maman_baz_class_init (MamanBazClass *klass)
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
In this example MamanDerivedBaz is derived from MamanBaz. Both
|
In this example, <type>MamanDerivedBaz</type> is derived from
|
||||||
implement the MamanIbaz interface. MamanDerivedBaz only implements one
|
<type>MamanBaz</type>. Both implement the <type>MamanIbaz</type>
|
||||||
method of the MamanIbaz interface and uses the base class implementation
|
interface. <type>MamanDerivedBaz</type> only implements one method of the
|
||||||
of the other.
|
<type>MamanIbaz</type> interface and uses the base class implementation of
|
||||||
|
the other.
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
static void
|
static void
|
||||||
maman_derived_ibaz_do_action (MamanIbaz *ibaz)
|
maman_derived_ibaz_do_action (MamanIbaz *ibaz)
|
||||||
@ -1282,7 +1291,7 @@ maman_derived_baz_init (MamanDerivedBaz *self)
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
In this example MamanDerivedBaz overides the
|
In this example <type>MamanDerivedBaz</type> overrides the
|
||||||
<function>do_action</function> interface method. In its overridden method
|
<function>do_action</function> interface method. In its overridden method
|
||||||
it calls the base class implementation of the same interface method.
|
it calls the base class implementation of the same interface method.
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
@ -1365,8 +1374,8 @@ maman_file_write (file, buffer, strlen (buffer));
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The <type>MamanFile</type> signal is registered in the class_init
|
The <type>MamanFile</type> signal is registered in the
|
||||||
function:
|
<function>class_init</function> function:
|
||||||
<informalexample><programlisting>
|
<informalexample><programlisting>
|
||||||
file_signals[CHANGED] =
|
file_signals[CHANGED] =
|
||||||
g_signal_newv ("changed",
|
g_signal_newv ("changed",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user