From: Matthias Clasen Date: Tue, 5 Jul 2005 05:54:42 +0000 (+0000) Subject: Add an example X-Git-Tag: GLIB_2_7_2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f77e7d12727b153cd91c9dd0c65be5da748757fa;p=platform%2Fupstream%2Fglib.git Add an example --- diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 92b1506..eccfd6d 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2005-07-05 Matthias Clasen + + * gobject/tmpl/objects.sgml: Add an example + for using a custom constructor. + 2005-06-30 Matthias Clasen * === Released 2.7.1 === diff --git a/docs/reference/gobject/tmpl/objects.sgml b/docs/reference/gobject/tmpl/objects.sgml index 1546e07..b634e7a 100644 --- a/docs/reference/gobject/tmpl/objects.sgml +++ b/docs/reference/gobject/tmpl/objects.sgml @@ -17,9 +17,6 @@ Signals are described in detail in . #GParamSpecObject, g_param_spec_object() - - - All the fields in the GObject structure are private @@ -42,13 +39,38 @@ the setter for the property is called to reinstate the previous value. The class structure for the GObject type. + +Implementing singletons using a constructor + +static MySingleton *the_singleton = NULL; + +static GObject* +my_singleton_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + + if (!the_singleton) + { + object = G_OBJECT_CLASS (parent_class)->constructor (type, + n_construct_params, + construct_params); + the_singleton = MY_SINGLETON (object); + } + else + object = g_object_ref (G_OBJECT (the_singleton)); + + return object; +} + @g_type_class: the parent class @constructor: the @constructor function is called by g_object_new () to complete the object initialization after all the construction properties are set. The first thing a @constructor implementation must do is chain up to the @constructor of the parent class. Overriding @constructor should be rarely - needed. + needed, e.g. to handle construct properties, or to implement singletons. @set_property: the generic setter for all properties of this type. Should be overridden for every type with properties. Implementations of @set_property don't need to emit property change notification explicitly, this is handled