1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 The GLib Runtime type identification and management system
7 <!-- ##### SECTION Long_Description ##### -->
9 The GType API is the foundation of the GObject system. It provides the
10 facilities for registering and managing all fundamental data types,
11 user-defined object and interface types. Before using any GType
12 or GObject functions, g_type_init() must be called to initialize the
16 For type creation and registration purposes, all types fall into one of
17 two categories: static or dynamic. Static types are never loaded or
18 unloaded at run-time as dynamic types may be. Static types are created
19 with g_type_register_static() that gets type specific information passed
20 in via a #GTypeInfo structure.
21 Dynamic types are created with g_type_register_dynamic() which takes a
22 #GTypePlugin structure instead. The remaining type information (the
23 #GTypeInfo structure) is retrived during runtime through #GTypePlugin
24 and the g_type_plugin_*() API.
25 These registration functions are usually called only once from a
26 function whose only purpose is to return the type identifier for a
27 specific class. Once the type (or class or interface) is registered,
28 it may be instantiated, inherited, or implemented depending on exactly
29 what sort of type it is.
30 There is also a third registration function for registering fundamental
31 types called g_type_register_fundamental() which requires both a #GTypeInfo
32 structure and a GTypeFundamentalInfo structure but it is seldom used
33 since most fundamental types are predefined rather than user-defined.
36 <!-- ##### SECTION See_Also ##### -->
41 <!-- ##### TYPEDEF GType ##### -->
43 A numerical value which represents the unique identifier of a registered
48 <!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
50 Returns #TRUE if @type is a fundamental data type such as #G_TYPE_INT or
51 #G_TYPE_POINTER. Fundamental types are types that serve as fundaments for
52 the derived types, thus they are the roots of distinct inheritance hierarchies.
55 @type: A #GType value.
58 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_MAX ##### -->
60 An integer constant that represents the number of identifiers reserved
61 for types that are assigned at compile-time.
66 <!-- ##### MACRO G_TYPE_DERIVE_ID ##### -->
75 <!-- ##### MACRO G_TYPE_BRANCH_SEQNO ##### -->
83 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_LAST ##### -->
85 An integer that currently represents the highest value of all
86 fundamental type identifiers. This is of interest for dynamic
87 introduction of new fundamental types (a
88 <emphasis>rarely</emphasis> needed feature).
93 <!-- ##### MACRO G_TYPE_IS_ABSTRACT ##### -->
95 Returns #TRUE if @type is an abstract type. An abstract type can not be
96 instantiated and is normally used as an abstract base class for
100 @type: A #GType value.
103 <!-- ##### MACRO G_TYPE_IS_DERIVED ##### -->
105 Returns #TRUE if @type is derived (or in object-oriented terminology:
106 inherited) from another type (this holds true for all non-fundamental
110 @type: A #GType value.
113 <!-- ##### MACRO G_TYPE_IS_FUNDAMENTAL ##### -->
115 Returns #TRUE if @type is a fundamental type.
118 @type: A #GType value.
121 <!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
126 @type: A #GType value.
129 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
131 Returns #TRUE if @type is a classed type.
134 @type: A #GType value.
137 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
139 Returns #TRUE if @type can be instantiated. Instantiation is the
140 process of creating an instance (object) of this type.
143 @type: A #GType value.
146 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
148 Returns #TRUE if @type is a derivable type. A derivable type can
149 be used as the base class of a flat (single-level) class hierarchy.
152 @type: A #GType value.
155 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
157 Returns #TRUE if @type is a deep derivable type. A deep derivable type
158 can be used as the base class of a deep (multi-level) class hierarchy.
161 @type: A #GType value.
164 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
166 Returns #TRUE if @type is an interface type.
167 Interface types are types that provide pure APIs, the implementation
168 of which is provided by another type (which is then said to conform
169 to the interface). GLib interfaces are somewhat analogous to Java
170 interfaces and C++ classes containing only pure virtual functions.
173 @type: A #GType value.
176 <!-- ##### ENUM GTypeFundamentals ##### -->
178 The predefined identifiers of the reserved fundamental types.
181 @G_TYPE_INVALID: Usually a return value indicating an error.
182 @G_TYPE_NONE: A synonym for the "void" type in C.
183 @G_TYPE_INTERFACE: Root type of all interface types.
184 @G_TYPE_CHAR: Identifier for the built-in type "gchar".
185 @G_TYPE_UCHAR: Identifier for the built-in type "guchar".
186 @G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean".
187 @G_TYPE_INT: Identifier for the built-in type "gint".
188 @G_TYPE_UINT: Identifier for the built-in type "guint".
189 @G_TYPE_LONG: Identifier for the built-in type "glong".
190 @G_TYPE_ULONG: Identifier for the built-in type "gulong".
193 @G_TYPE_ENUM: Identifier for the "#GEnum" type.
194 @G_TYPE_FLAGS: Identifier for the "#GFlags" type.
195 @G_TYPE_FLOAT: Identifier for the built-in type "gfloat".
196 @G_TYPE_DOUBLE: Identifier for the built-in type "gdouble".
197 @G_TYPE_STRING: Identifier for a pointer to a null-terminated string "gchar*".
198 @G_TYPE_POINTER: Identifier for anonymous pointers "void*".
199 @G_TYPE_BOXED: Identifier for the "#GBoxed" type.
200 @G_TYPE_PARAM: Identifier for the "#GParam" type.
201 @G_TYPE_OBJECT: Identifier for the "#GObject" type.
202 @G_TYPE_RESERVED_BSE_FIRST: First fundamental type ID reserved for BSE.
203 @G_TYPE_RESERVED_BSE_LAST: Last fundamental type ID reserved for BSE.
204 @G_TYPE_RESERVED_LAST_FUNDAMENTAL: Last reserved fundamental type ID.
209 @G_TYPE_PARAM_CHAR: Identifier for the "#GParamSpecChar" type.
210 @G_TYPE_PARAM_UCHAR: Identifier for the "#GParamSpecUChar" type.
211 @G_TYPE_PARAM_BOOLEAN: Identifier for the "#GParamSpecBoolean" type.
212 @G_TYPE_PARAM_INT: Identifier for the "#GParamSpecInt" type.
213 @G_TYPE_PARAM_UINT: Identifier for the "#GParamSpecUInt" type.
214 @G_TYPE_PARAM_LONG: Identifier for the "#GParamSpecLong" type.
215 @G_TYPE_PARAM_ULONG: Identifier for the "#GParamSpecULong" type.
217 @G_TYPE_PARAM_UINT64:
218 @G_TYPE_PARAM_UNICHAR:
219 @G_TYPE_PARAM_ENUM: Identifier for the "#GParamSpecEnum" type.
220 @G_TYPE_PARAM_FLAGS: Identifier for the "#GParamSpecFlags" type.
221 @G_TYPE_PARAM_FLOAT: Identifier for the "#GParamSpecFloat" type.
222 @G_TYPE_PARAM_DOUBLE: Identifier for the "#GParamSpecDouble" type.
223 @G_TYPE_PARAM_STRING: Identifier for the "#GParamSpecString" type.
224 @G_TYPE_PARAM_PARAM: Identifier for the "#GParamSpecParam" type.
225 @G_TYPE_PARAM_BOXED: Identifier for the "#GParamSpecBoxed" type.
226 @G_TYPE_PARAM_POINTER: Identifier for the "#GParamSpecPointer" type.
227 @G_TYPE_PARAM_VALUE_ARRAY: Identifier for the "#GParamSpecValueArray" type.
228 @G_TYPE_PARAM_CLOSURE: Identifier for the "#GParamClosure" type.
229 @G_TYPE_PARAM_OBJECT: Identifier for the "#GParamSpecObject" type.
231 <!-- ##### STRUCT GTypeInterface ##### -->
233 An opaque structure used as the base of all interface types.
237 <!-- ##### STRUCT GTypeInstance ##### -->
239 An opaque structure used as the base of all type instances.
243 <!-- ##### STRUCT GTypeInfo ##### -->
245 This structure is used to provide the type system with the information
246 required to initialize and destruct (finalize) a type's class and
248 The initialized structure is passed to the g_type_register_static() function
249 (or is copied into the provided #GTypeInfo structure in the
250 g_type_plugin_complete_type_info()). The type system will perform a deep
251 copy of this structure, so it's memory does not need to be persistent
252 across invocation of g_type_register_static().
255 @class_size: Size of the class structure (required for interface, classed and instantiatable types).
256 @base_init: Location of the base initialization function (optional).
257 @base_finalize: Location of the base finalization function (optional).
258 @class_init: Location of the class initialization function (optional, for classed and instantiatable types only).
259 @class_finalize: Location of the class finalization function (optional).
260 @class_data: User-supplied data passed to the class init/finalize functions.
261 @instance_size: Size of the instance (object) structure (required for instantiatable types only).
262 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
263 @instance_init: Location of the instance initialization function (optional, for instantiatable types only).
264 @value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usualy only
265 useful for fundamental types).
267 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
269 A structure that provides information to the type system which is
270 used specifically for managing fundamental types.
275 <!-- ##### STRUCT GInterfaceInfo ##### -->
277 A structure that provides information to the type system which is
278 used specifically for managing interface types.
281 @interface_init: Location of the function that initializes the interface.
282 @interface_finalize: Location of the function that finalizes the interface.
283 @interface_data: Location of user data passed to the @interface_init and
284 @interface_finalize functions (optional).
286 <!-- ##### STRUCT GTypeValueTable ##### -->
288 The #GTypeValueTable provides the functions required by the #GValue implementation,
289 to serve as a container for values of a type.
292 @value_init: Default initialize @values contents by poking values
293 directly into the value->data array. The data array of
294 the #GValue passed into this function was zero-filled
295 with memset, so no care has to be taken to free any
296 old contents. E.g. for the implementation of a string
297 value that may never be NULL, the implementation might
299 <msgtext><programlisting>
301 value->data[0].v_pointer = g_strdup ("");
303 </programlisting></msgtext>
304 @value_free: Free any old contents that might be left in the
305 data array of the passed in @value. No resources may
306 remain allocated through the #GValue contents after
307 this function returns. E.g. for our above string type:
308 <msgtext><programlisting>
310 /* only free strings without a specific flag for static storage */
311 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
312 g_free (value->data[0].v_pointer);
314 </programlisting></msgtext>
315 @value_copy: @dest_value is a #GValue with zero-filled data section
316 and @src_value is a properly setup #GValue of same or
318 The purpose of this function is to copy the contents of
319 @src_value into @dest_value in a way, that even after
320 @src_value has been freed, the contents of @dest_value
321 remain valid. String type example:
322 <msgtext><programlisting>
324 dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
326 </programlisting></msgtext>
327 @value_peek_pointer: If the value contents fit into a pointer, such as objects
328 or strings, return this pointer, so the caller can peek at
329 the current contents. To extend on our above string example:
330 <msgtext><programlisting>
332 return value->data[0].v_pointer;
334 </programlisting></msgtext>
335 @collect_format: A string format describing how to collect the contents of
336 this value, bit-by-bit. Each character in the format represents
337 an argument to be collected, the characters themselves indicate
338 the type of the argument. Currently supported arguments are:
339 <msgtext><variablelist>
340 <varlistentry><term></term><listitem><para>
341 'i' - Integers. passed as collect_values[].v_int.
342 </para></listitem></varlistentry>
343 <varlistentry><term></term><listitem><para>
344 'l' - Longs. passed as collect_values[].v_long.
345 </para></listitem></varlistentry>
346 <varlistentry><term></term><listitem><para>
347 'd' - Doubles. passed as collect_values[].v_double.
348 </para></listitem></varlistentry>
349 <varlistentry><term></term><listitem><para>
350 'p' - Pointers. passed as collect_values[].v_pointer.
351 </para></listitem></varlistentry>
352 </variablelist></msgtext>
353 It should be noted, that for variable argument list construction,
354 ANSI C promotes every type smaller than an integer to an int, and
355 floats to doubles. So for collection of short int or char, 'i'
356 needs to be used, and for collection of floats 'd'.
357 @collect_value: The collect_value() function is responsible for converting the
358 values collected from a variable argument list into contents
359 suitable for storage in a GValue. This function should setup
360 @value similar to value_init(), e.g. for a string value that
361 does not allow NULL pointers, it needs to either spew an error,
362 or do an implicit conversion by storing an empty string.
363 The @value passed in to this function has a zero-filled data
364 array, so just like for @value_init it is guaranteed to not
365 contain any old contents that might need freeing.
366 @n_collect_values is exactly the string length of @collect_format,
367 and @collect_values is an array of unions #GTypeCValue with
368 length @n_collect_values, containing the collected values
369 according to @collect_format.
370 @collect_flags is an argument provided as a hint by the caller,
371 which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
372 that the collected value contents may be considered "static"
373 for the duration of the #@value lifetime.
374 Thus an extra copy of the contents stored in @collect_values is
375 not required for assignment to @value.
376 For our above string example, we continue with:
377 <msgtext><programlisting>
379 if (!collect_values[0].v_pointer)
380 value->data[0].v_pointer = g_strdup ("");
381 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
383 value->data[0].v_pointer = collect_values[0].v_pointer;
384 /* keep a flag for the value_free() implementation to not free this string */
385 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
388 value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
392 </programlisting></msgtext>
393 It should be noted, that it is generally a bad idea to follow the
394 #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
395 reentrancy requirements and reference count assertions performed
396 by the GSignal code, reference counts should always be incremented
397 for reference counted contents stored in the value->data array.
398 To deviate from our string example for a moment, and taking a look
399 at an exemplary implementation for collect_value() of #GObject:
400 <msgtext><programlisting>
402 if (collect_values[0].v_pointer)
404 GObject *object = G_OBJECT (collect_values[0].v_pointer);
406 /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
407 value->data[0].v_pointer = g_object_ref (object);
411 return g_strdup_printf ("Object passed as invalid NULL pointer");
413 </programlisting></msgtext>
414 The reference count for valid objects is always incremented,
415 regardless of @collect_flags. For invalid objects, the example
416 returns a newly allocated string without altering @value.
417 Upon success, collect_value() needs to return NULL, if however
418 a malicious condition occurred, collect_value() may spew an
419 error by returning a newly allocated non-NULL string, giving
420 a suitable description of the error condition.
421 The calling code makes no assumptions about the @value
422 contents being valid upon error returns, @value
423 is simply thrown away without further freeing. As such, it is
424 a good idea to not allocate #GValue contents, prior to returning
425 an error, however, collect_values() is not obliged to return
426 a correctly setup @value for error returns, simply because
427 any non-NULL return is considered a fatal condition so further
428 program behaviour is undefined.
429 @lcopy_format: Format description of the arguments to collect for @lcopy_value,
430 analogous to @collect_format. Usually, @lcopy_format string consists
431 only of 'p's to provide lcopy_value() with pointers to storage locations.
432 @lcopy_value: This function is responsible for storing the @value contents into
433 arguments passed through a variable argument list which got
434 collected into @collect_values according to @lcopy_format.
435 @n_collect_values equals the string length of @lcopy_format,
436 and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS.
437 In contrast to collect_value(), lcopy_value() is obliged to
438 always properly support #G_VALUE_NOCOPY_CONTENTS.
439 Similar to collect_value() the function may prematurely abort
440 by returning a newly allocated string describing an error condition.
441 To complete the string example:
442 <msgtext><programlisting>
444 gchar **string_p = collect_values[0].v_pointer;
447 return g_strdup_printf ("string location passed as NULL");
449 if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
450 *string_p = value->data[0].v_pointer;
452 *string_p = g_strdup (value->data[0].v_pointer);
455 </programlisting></msgtext>
456 And an exemplary version of lcopy_value() for
457 reference-counted types:
458 <msgtext><programlisting>
460 GObject **object_p = collect_values[0].v_pointer;
463 return g_strdup_printf ("object location passed as NULL");
464 if (!value->data[0].v_pointer)
466 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) /* always honour */
467 *object_p = value->data[0].v_pointer;
469 *object_p = g_object_ref (value->data[0].v_pointer);
472 </programlisting></msgtext>
474 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
476 Returns the type identifier from a given @instance structure.
479 @instance: Location of a valid #GTypeInstance structure.
482 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
484 Returns the type identifier from a given @class structure.
487 @g_class: Location of a valid #GTypeClass structure.
490 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
492 Returns the type identifier from a given @interface structure.
495 @g_iface: Location of a valid #GTypeInterface structure.
498 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
500 Returns the class structure of a given @instance, casted
501 to a specified anchestor type @g_type of the instance.
504 @instance: Location of the #GTypeInstance structure.
505 @g_type: The anchestor type of the class to be returned.
506 @c_type: The corresponding C type of @g_Type.
509 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
519 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
527 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
537 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
546 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
556 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
565 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
573 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
582 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
589 <!-- ##### FUNCTION g_type_init ##### -->
591 Prior to any use of the type system, g_type_init() has to be called to initialize
592 the type system and assorted other code portions (such as the various fundamental
593 type implementations or the signal system).
596 <!-- # Unused Parameters # -->
597 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
600 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
608 <!-- ##### FUNCTION g_type_name ##### -->
610 Return the unique name that is assigned to a type ID (this is the preferred method
611 to find out whether a specific type has been registered for the passed in ID yet).
614 @type: Type to return name for.
615 @Returns: Static type name or NULL.
618 <!-- ##### FUNCTION g_type_qname ##### -->
620 Return the corresponding quark of the type IDs name.
623 @type: Type to return quark of type name for.
624 @Returns: The type names quark or 0.
627 <!-- ##### FUNCTION g_type_from_name ##### -->
629 Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
630 (this is the preferred method to find out by name whether a specific type has been registered yet).
633 @name: Type name to lookup.
634 @Returns: Corresponding type ID or 0.
637 <!-- ##### FUNCTION g_type_parent ##### -->
639 Return the direct parent type of the passed in type.
640 If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
643 @type: The derived type.
644 @Returns: The parent type.
647 <!-- ##### FUNCTION g_type_depth ##### -->
656 <!-- ##### FUNCTION g_type_next_base ##### -->
658 Given a @leaf_type and a @root_type which is contained in its anchestry, return
659 the type that @root_type is the immediate parent of.
660 In other words, this function determines the type that is derived directly from
661 @root_type which is also a base class of @leaf_type. Given a root type and a
662 leaf type, this function can be used to determine the types and order in which
663 the leaf type is descended from the root type.
666 @leaf_type: Descendant of @root_type and the type to be returned.
667 @root_type: Immediate parent of the returned type.
668 @Returns: Immediate child of @root_type and anchestor of @leaf_type.
671 <!-- ##### FUNCTION g_type_is_a ##### -->
673 Check whether @type is a descendant of @is_a_type.
676 @type: Type to check anchestry for.
677 @is_a_type: Possible anchestor of @type.
678 @Returns: %TRUE if @type is_a @is_a_type holds true.
681 <!-- ##### FUNCTION g_type_fundamental_branch_last ##### -->
690 <!-- ##### FUNCTION g_type_class_ref ##### -->
692 Increments the reference count of the class structure belonging to
693 @type. This function will demand-create the class if it doesn't
697 @type: Type ID of a classed type.
698 @Returns: The #GTypeClass structure for the given type ID.
701 <!-- ##### FUNCTION g_type_class_peek ##### -->
703 This function is essentially the same as g_type_class_ref(), except that
704 the classes reference count isn't incremented. Therefore, this function
705 may return NULL if the class of the type passed in does not currently
706 exist (hasn't been referenced before).
709 @type: Type ID of a classed type.
710 @Returns: The #GTypeClass structure for the given type ID or NULL
711 if the class does not currently exist.
714 <!-- ##### FUNCTION g_type_class_unref ##### -->
716 Decrements the reference count of the class structure being passed in.
717 Once the last reference count of a class has been released, classes
718 may be finalized by the type system, so further dereferencing of a
719 class pointer after g_type_class_unref() are invalid.
722 @g_class: The #GTypeClass structure to unreference.
725 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
727 This is a convenience function, often needed in class intializers.
728 It essentially takes the immediate parent type of the class passed in,
729 and returns the class structure thereof. Since derived classes hold
730 a reference count on their parent classes as long as they are instantiated,
731 the returned class will always exist. This function is essentially
734 <msgtext><programlisting>
735 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
736 </programlisting></msgtext>
740 @g_class: The #GTypeClass structure to retrieve the parent class for.
741 @Returns: The parent class of @g_class.
744 <!-- ##### FUNCTION g_type_interface_peek ##### -->
754 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
763 <!-- ##### FUNCTION g_type_children ##### -->
765 Return a newly allocated and 0 terminated array of type IDs, listing the
766 child types of @type. The return value has to be g_free()ed after use.
769 @type: The parent type.
770 @n_children: Optional #guint pointer to contain the number of child types.
771 @Returns: Newly allocated and 0 terminated array of child types.
774 <!-- ##### FUNCTION g_type_interfaces ##### -->
776 Return a newly allocated and 0 terminated array of type IDs, listing the
777 interface types that @type conforms to. The return value has to be
778 g_free()ed after use.
781 @type: The type to list interface types for.
782 @n_interfaces: Optional #guint pointer to contain the number of interface types.
783 @Returns: Newly allocated and 0 terminated array of interface types.
786 <!-- ##### FUNCTION g_type_set_qdata ##### -->
796 <!-- ##### FUNCTION g_type_get_qdata ##### -->
806 <!-- ##### FUNCTION g_type_query ##### -->
815 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
817 A callback function used by the type system to do base initialization
818 of the class structures of derived types. It is called as part of the
819 initialization process of all derived classes and should reallocate
820 or reset all dynamic class members copied over from the parent class.
821 Therefore class members, e.g. strings, that are not sufficiently
822 handled by a plain memory copy of the parent class into the derived class
823 have to be altered. See GClassInitFunc() for a discussion of the class
824 intialization process.
827 @g_class: The #GTypeClass structure to initialize.
830 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
832 A callback function used by the type system to finalize those portions
833 of a derived types class structure that were setup from the corresponding
834 GBaseInitFunc() function. Class finalization basically works the inverse
835 way in which class intialization is performed.
836 See GClassInitFunc() for a discussion of the class intialization process.
839 @g_class: The #GTypeClass structure to finalize.
842 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
844 A callback function used by the type system to initialize the class
845 of a specific type. This function should initialize all static class
847 The initialization process of a class involves:
849 <varlistentry><term></term><listitem><para>
850 1 - Copying common members from the parent class over to the
851 derived class structure.
852 </para></listitem></varlistentry>
853 <varlistentry><term></term><listitem><para>
854 2 - Zero initialization of the remaining members not copied
855 over from the parent class.
856 </para></listitem></varlistentry>
857 <varlistentry><term></term><listitem><para>
858 3 - Invocation of the GBaseInitFunc initializers of all parent
859 types and the class' type.
860 </para></listitem></varlistentry>
861 <varlistentry><term></term><listitem><para>
862 4 - Invocation of the class' GClassInitFunc initializer.
863 </para></listitem></varlistentry>
865 Since derived classes are partially initialized through a memory copy
866 of the parent class, the general rule is that GBaseInitFunc() and
867 GBaseFinalizeFunc() should take care of necessary reinitialization
868 and release of those class members that were introduced by the type
869 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
870 GClassInitFunc() should only care about intializing static
871 class members, while dynamic class members (such as allocated strings
872 or reference counted resources) are better handled by a GBaseInitFunc()
873 for this type, so proper initialization of the dynamic class members
874 are performed for class intialization of derived types as well.
875 An example may help to correspond the intend of the different class
878 <msgtext><programlisting>
880 GObjectClass parent_class;
882 gchar *dynamic_string;
885 type_a_base_class_init (TypeAClass *class)
887 class->dynamic_string = g_strdup ("some string");
890 type_a_base_class_finalize (TypeAClass *class)
892 g_free (class->dynamic_string);
895 type_a_class_init (TypeAClass *class)
897 class->static_integer = 42;
901 TypeAClass parent_class;
903 GString *dynamic_gstring;
906 type_b_base_class_init (TypeBClass *class)
908 class->dynamic_gstring = g_string_new ("some other string);
911 type_b_base_class_finalize (TypeBClass *class)
913 g_string_free (class->dynamic_gstring);
916 type_b_class_init (TypeBClass *class)
918 class->static_float = 3.14159265358979323846;
920 </programlisting></msgtext>
921 Initialization of TypeBClass will first cause initialization of
922 TypeAClass (derived classes reference their parent classes, see
923 g_type_class_ref() on this).
924 Initialization of TypeAClass roughly involves zero-initializing its fields,
925 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
926 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
927 type_a_class_init() to initialize its static members (static_integer).
928 The first step in the initialization process of TypeBClass is then
929 a plain memory copy of the contents of TypeAClass into TypeBClass and
930 zero-initialization of the remaining fields in TypeBClass.
931 The dynamic members of TypeAClass within TypeBClass now need
932 reinitialization which is performed by calling type_a_base_class_init()
933 with an argument of TypeBClass.
934 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
935 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
936 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
937 is called to complete the initialization process with the static members
939 Corresponding finalization counter parts to the GBaseInitFunc() functions
940 have to be provided to release allocated resources at class finalization
944 @g_class: The #GTypeClass structure to initialize.
945 @class_data: The @class_data member supplied via the #GTypeInfo structure.
948 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
950 A callback function used by the type system to finalize a class.
951 This function is rarely needed, as dynamically allocated class resources
952 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
953 Also, specification of a GClassFinalizeFunc in the #GTypeInfo
954 structure of a static type is invalid, because classes of static types
955 will never be finalized (they are artificially kept alive when their
956 reference count drops to zero).
959 @g_class: The #GTypeClass structure to finalize.
960 @class_data: The @class_data member supplied via the #GTypeInfo structure.
963 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
965 A callback function used by the type system to initialize a new
966 instance of a type. This function initializes all instance members and
967 allocates any resources required by it.
968 Initialization of a derived instance involves calling all its parent
969 types instance initializers, therefore the class member of the instance
970 is altered during its initialization to always point to the class that
971 belongs to the type the current initializer was introduced for.
974 @instance: The instance to initialize.
975 @g_class: The class of the type the instance is created for.
978 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
980 A callback function used by the type system to initialize a new
981 interface. This function should initialize all internal data and
982 allocate any resources required by the interface.
985 @g_iface: The interface structure to initialize.
986 @iface_data: The @class_data supplied via the #GTypeInfo structure.
989 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
991 A callback function used by the type system to finalize an interface.
992 This function should destroy any internal data and release any resources
993 allocated by the corresponding GInterfaceInitFunc() function.
996 @g_iface: The interface structure to finalize.
997 @iface_data: The @class_data supplied via the #GTypeInfo structure.
1000 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
1010 <!-- ##### ENUM GTypeFlags ##### -->
1012 Bit masks used to check or determine characteristics of a type.
1015 @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
1016 created for an abstract type.
1017 @G_TYPE_FLAG_VALUE_ABSTRACT:
1019 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
1021 Bit masks used to check or determine specific characteristics of a
1025 @G_TYPE_FLAG_CLASSED: Indicates a classed type.
1026 @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed).
1027 @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type.
1028 @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable).
1030 <!-- ##### FUNCTION g_type_register_static ##### -->
1032 Registers @type_name as the name of a new static type derived from
1033 @parent_type. The type system uses the information contained in the
1034 #GTypeInfo structure pointed to by @info to manage the type and its
1035 instances (if not abstract). The value of @flags determines the nature
1036 (e.g. abstract or not) of the type.
1039 @parent_type: Type which this type will be derived from.
1040 @type_name: Null-terminated string used as the name of the new type.
1041 @info: The #GTypeInfo structure for this type.
1042 @flags: Bitwise combination of #GTypeFlags values.
1043 @Returns: The new type identifier.
1046 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1048 Registers @type_name as the name of a new dynamic type derived from
1049 @parent_type. The type system uses the information contained in the
1050 #GTypePlugin structure pointed to by @plugin to manage the type and its
1051 instances (if not abstract). The value of @flags determines the nature
1052 (e.g. abstract or not) of the type.
1055 @parent_type: Type which this type will be derived from.
1056 @type_name: Null-terminated string used as the name of the new type.
1057 @plugin: The #GTypePlugin structure to retrive the #GTypeInfo from.
1058 @flags: Bitwise combination of #GTypeFlags values.
1059 @Returns: The new type identifier.
1060 <!-- # Unused Parameters # -->
1061 @Returns: #G_TYPE_INVALID if registration failed or the new type identifier.
1064 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1066 Registers @type_id as the predefined identifier and @type_name as the
1067 name of a fundamental type. The type system uses the information
1068 contained in the #GTypeInfo structure pointed to by @info and the
1069 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1070 type and its instances. The value of @flags determines additional
1071 characteristics of the fundamental type.
1074 @type_id: A predefined #GTypeFundamentals value.
1075 @type_name: Null-terminated string used as the name of the new type.
1076 @info: The #GTypeInfo structure for this type.
1077 @finfo: The #GTypeFundamentalInfo structure for this type.
1078 @flags: Bitwise combination of #GTypeFlags values.
1079 @Returns: The predefined type identifier.
1082 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1084 Adds the static @interface_type to @instantiable_type. The information
1085 contained in the #GTypeInterfaceInfo structure pointed to by @info
1086 is used to manage the relationship.
1089 @instance_type: #GType value of an instantiable type.
1090 @interface_type: #GType value of an interface type.
1091 @info: The #GInterfaceInfo structure for this
1092 (@instance_type, @interface_type) combination.
1095 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1104 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1113 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1115 Returns the the #GTypePlugin structure for @type or
1116 #NULL if @type does not have a #GTypePlugin structure.
1119 @type: The #GType to retrive the plugin for.
1120 @Returns: The corresponding plugin if @type is a dynamic type,
1124 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1129 @implementation_type:
1133 <!-- ##### FUNCTION g_type_fundamental_last ##### -->
1135 Returns the last fundamental type which is registered plus one,
1136 i.e. the next fundamental type ID that may be registered.
1139 @Returns: The nextmost not registered fundamental type ID.
1142 <!-- ##### FUNCTION g_type_create_instance ##### -->
1144 Creates and initializes an instance of @type if @type is valid and can
1145 be instantiated. The type system only performs basic allocation and
1146 structure setups for instances, actual instance creation should happen
1147 through functions supplied by the types fundamental type implementation.
1148 So use of g_type_create_instance() is reserved for implementators of
1149 fundamental types only. E.g. instances of the #GObject hierarchy
1150 should be created via g_object_new() and <emphasis>never</emphasis>
1151 directly through g_type_create_instance() which doesn't handle
1152 things like singleton objects or object construction.
1153 Note: Do <emphasis>not</emphasis> use this function, unless you're
1154 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1155 use this function but g_object_new() instead.
1158 @type: An instantiabtable type to create an instance for.
1159 @Returns: An allocated and initialized instance, subject to further
1160 treatment by the fundamental type implementation.
1163 <!-- ##### FUNCTION g_type_free_instance ##### -->
1170 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1179 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1188 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1196 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1198 Returns the location of the #GTypeValueTable associated with @type.
1199 <emphasis>Note, this function should only be used from source code
1200 that implements or has internal knowledge of the implementation of
1204 @type: A #GType value.
1205 @Returns: Location of the #GTypeValueTable associated with @type or
1206 #NULL if there is no #GTypeValueTable associated with @type.