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 retrieved 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_MAKE_FUNDAMENTAL ##### -->
68 Returns the type ID for the fundamental type number @x.
69 Use g_type_fundamental_next() instead of this macro to create new fundamental
73 @x: the fundamental type number.
76 <!-- ##### MACRO G_TYPE_IS_ABSTRACT ##### -->
78 Returns %TRUE if @type is an abstract type. An abstract type can not be
79 instantiated and is normally used as an abstract base class for
83 @type: A #GType value.
86 <!-- ##### MACRO G_TYPE_IS_DERIVED ##### -->
88 Returns %TRUE if @type is derived (or in object-oriented terminology:
89 inherited) from another type (this holds true for all non-fundamental
93 @type: A #GType value.
96 <!-- ##### MACRO G_TYPE_IS_FUNDAMENTAL ##### -->
98 Returns %TRUE if @type is a fundamental type.
101 @type: A #GType value.
104 <!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
109 @type: A #GType value.
112 <!-- ##### MACRO G_TYPE_HAS_VALUE_TABLE ##### -->
114 Returns %TRUE if @type has a #GTypeValueTable.
117 @type: A #GType value.
120 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
122 Returns %TRUE if @type is a classed type.
125 @type: A #GType value.
128 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
130 Returns %TRUE if @type can be instantiated. Instantiation is the
131 process of creating an instance (object) of this type.
134 @type: A #GType value.
137 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
139 Returns %TRUE if @type is a derivable type. A derivable type can
140 be used as the base class of a flat (single-level) class hierarchy.
143 @type: A #GType value.
146 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
148 Returns %TRUE if @type is a deep derivable type. A deep derivable type
149 can be used as the base class of a deep (multi-level) class hierarchy.
152 @type: A #GType value.
155 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
157 Returns %TRUE if @type is an interface type.
158 Interface types are types that provide pure APIs, the implementation
159 of which is provided by another type (which is then said to conform
160 to the interface). GLib interfaces are somewhat analogous to Java
161 interfaces and C++ classes containing only pure virtual functions,
162 with the difference that GType interfaces are not derivable (but see
163 g_type_interface_add_prerequisite() for an alternative).
166 @type: A #GType value.
169 <!-- ##### STRUCT GTypeInterface ##### -->
171 An opaque structure used as the base of all interface types.
175 <!-- ##### STRUCT GTypeInstance ##### -->
177 An opaque structure used as the base of all type instances.
181 <!-- ##### STRUCT GTypeInfo ##### -->
183 This structure is used to provide the type system with the information
184 required to initialize and destruct (finalize) a type's class and
186 The initialized structure is passed to the g_type_register_static() function
187 (or is copied into the provided #GTypeInfo structure in the
188 g_type_plugin_complete_type_info()). The type system will perform a deep
189 copy of this structure, so it's memory does not need to be persistent
190 across invocation of g_type_register_static().
193 @class_size: Size of the class structure (required for interface, classed and instantiatable types).
194 @base_init: Location of the base initialization function (optional).
195 @base_finalize: Location of the base finalization function (optional).
196 @class_init: Location of the class initialization function (optional, for classed and instantiatable types only).
197 @class_finalize: Location of the class finalization function (optional).
198 @class_data: User-supplied data passed to the class init/finalize functions.
199 @instance_size: Size of the instance (object) structure (required for instantiatable types only).
200 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
201 @instance_init: Location of the instance initialization function (optional, for instantiatable types only).
202 @value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usually only
203 useful for fundamental types).
205 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
207 A structure that provides information to the type system which is
208 used specifically for managing fundamental types.
213 <!-- ##### STRUCT GInterfaceInfo ##### -->
215 A structure that provides information to the type system which is
216 used specifically for managing interface types.
219 @interface_init: Location of the function that initializes the interface.
220 @interface_finalize: Location of the function that finalizes the interface.
221 @interface_data: Location of user data passed to the @interface_init and
222 @interface_finalize functions (optional).
224 <!-- ##### STRUCT GTypeValueTable ##### -->
226 The #GTypeValueTable provides the functions required by the #GValue implementation,
227 to serve as a container for values of a type.
230 @value_init: Default initialize @values contents by poking values
231 directly into the value->data array. The data array of
232 the #GValue passed into this function was zero-filled
233 with <function>memset()</function>, so no care has to
235 old contents. E.g. for the implementation of a string
236 value that may never be %NULL, the implementation might
240 value->data[0].v_pointer = g_strdup ("");
243 @value_free: Free any old contents that might be left in the
244 data array of the passed in @value. No resources may
245 remain allocated through the #GValue contents after
246 this function returns. E.g. for our above string type:
249 /* only free strings without a specific flag for static storage */
250 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
251 g_free (value->data[0].v_pointer);
254 @value_copy: @dest_value is a #GValue with zero-filled data section
255 and @src_value is a properly setup #GValue of same or
257 The purpose of this function is to copy the contents of
258 @src_value into @dest_value in a way, that even after
259 @src_value has been freed, the contents of @dest_value
260 remain valid. String type example:
263 dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
266 @value_peek_pointer: If the value contents fit into a pointer, such as objects
267 or strings, return this pointer, so the caller can peek at
268 the current contents. To extend on our above string example:
271 return value->data[0].v_pointer;
274 @collect_format: A string format describing how to collect the contents of
275 this value, bit-by-bit. Each character in the format represents
276 an argument to be collected, the characters themselves indicate
277 the type of the argument. Currently supported arguments are:
279 <varlistentry><term></term><listitem><para>
280 'i' - Integers. passed as collect_values[].v_int.
281 </para></listitem></varlistentry>
282 <varlistentry><term></term><listitem><para>
283 'l' - Longs. passed as collect_values[].v_long.
284 </para></listitem></varlistentry>
285 <varlistentry><term></term><listitem><para>
286 'd' - Doubles. passed as collect_values[].v_double.
287 </para></listitem></varlistentry>
288 <varlistentry><term></term><listitem><para>
289 'p' - Pointers. passed as collect_values[].v_pointer.
290 </para></listitem></varlistentry>
292 It should be noted, that for variable argument list construction,
293 ANSI C promotes every type smaller than an integer to an int, and
294 floats to doubles. So for collection of short int or char, 'i'
295 needs to be used, and for collection of floats 'd'.
296 @collect_value: The collect_value() function is responsible for converting the
297 values collected from a variable argument list into contents
298 suitable for storage in a GValue. This function should setup
299 @value similar to value_init(), e.g. for a string value that
300 does not allow %NULL pointers, it needs to either spew an error,
301 or do an implicit conversion by storing an empty string.
302 The @value passed in to this function has a zero-filled data
303 array, so just like for value_init() it is guaranteed to not
304 contain any old contents that might need freeing.
305 @n_collect_values is exactly the string length of @collect_format,
306 and @collect_values is an array of unions #GTypeCValue with
307 length @n_collect_values, containing the collected values
308 according to @collect_format.
309 @collect_flags is an argument provided as a hint by the caller,
310 which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
311 that the collected value contents may be considered "static"
312 for the duration of the @value lifetime.
313 Thus an extra copy of the contents stored in @collect_values is
314 not required for assignment to @value.
315 For our above string example, we continue with:
318 if (!collect_values[0].v_pointer)
319 value->data[0].v_pointer = g_strdup ("");
320 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
322 value->data[0].v_pointer = collect_values[0].v_pointer;
323 /* keep a flag for the value_free() implementation to not free this string */
324 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
327 value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
332 It should be noted, that it is generally a bad idea to follow the
333 #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
334 reentrancy requirements and reference count assertions performed
335 by the #GSignal code, reference counts should always be incremented
336 for reference counted contents stored in the value->data array.
337 To deviate from our string example for a moment, and taking a look
338 at an exemplary implementation for collect_value() of #GObject:
341 if (collect_values[0].v_pointer)
343 GObject *object = G_OBJECT (collect_values[0].v_pointer);
345 /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
346 value->data[0].v_pointer = g_object_ref (object);
350 return g_strdup_printf ("Object passed as invalid NULL pointer");
353 The reference count for valid objects is always incremented,
354 regardless of @collect_flags. For invalid objects, the example
355 returns a newly allocated string without altering @value.
356 Upon success, collect_value() needs to return %NULL, if however
357 a malicious condition occurred, collect_value() may spew an
358 error by returning a newly allocated non-%NULL string, giving
359 a suitable description of the error condition.
360 The calling code makes no assumptions about the @value
361 contents being valid upon error returns, @value
362 is simply thrown away without further freeing. As such, it is
363 a good idea to not allocate #GValue contents, prior to returning
364 an error, however, collect_values() is not obliged to return
365 a correctly setup @value for error returns, simply because
366 any non-%NULL return is considered a fatal condition so further
367 program behaviour is undefined.
368 @lcopy_format: Format description of the arguments to collect for @lcopy_value,
369 analogous to @collect_format. Usually, @lcopy_format string consists
370 only of 'p's to provide lcopy_value() with pointers to storage locations.
371 @lcopy_value: This function is responsible for storing the @value contents into
372 arguments passed through a variable argument list which got
373 collected into @collect_values according to @lcopy_format.
374 @n_collect_values equals the string length of @lcopy_format,
375 and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS.
376 In contrast to collect_value(), lcopy_value() is obliged to
377 always properly support #G_VALUE_NOCOPY_CONTENTS.
378 Similar to collect_value() the function may prematurely abort
379 by returning a newly allocated string describing an error condition.
380 To complete the string example:
383 gchar **string_p = collect_values[0].v_pointer;
386 return g_strdup_printf ("string location passed as NULL");
388 if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
389 *string_p = value->data[0].v_pointer;
391 *string_p = g_strdup (value->data[0].v_pointer);
395 And an exemplary version of lcopy_value() for
396 reference-counted types:
399 GObject **object_p = collect_values[0].v_pointer;
402 return g_strdup_printf ("object location passed as NULL");
403 if (!value->data[0].v_pointer)
405 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) /* always honour */
406 *object_p = value->data[0].v_pointer;
408 *object_p = g_object_ref (value->data[0].v_pointer);
413 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
415 Returns the type identifier from a given @instance structure.
418 @instance: Location of a valid #GTypeInstance structure.
421 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
423 Returns the type identifier from a given @class structure.
426 @g_class: Location of a valid #GTypeClass structure.
429 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
431 Returns the type identifier from a given @interface structure.
434 @g_iface: Location of a valid #GTypeInterface structure.
437 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
439 Returns the class structure of a given @instance, casted
440 to a specified anchestor type @g_type of the instance.
443 @instance: Location of the #GTypeInstance structure.
444 @g_type: The anchestor type of the class to be returned.
445 @c_type: The corresponding C type of @g_Type.
448 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
458 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
466 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
476 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
485 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
495 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
504 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
512 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
521 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
528 <!-- ##### FUNCTION g_type_init ##### -->
530 Prior to any use of the type system, g_type_init() has to be called to initialize
531 the type system and assorted other code portions (such as the various fundamental
532 type implementations or the signal system).
537 <!-- ##### ENUM GTypeDebugFlags ##### -->
539 The <type>GTypeDebugFlags</type> enumeration values can be passed to
540 g_type_init_with_debug_flags() to trigger debugging messages during runtime.
541 Note that the messages can also be triggered by setting the
542 <envar>GOBJECT_DEBUG</envar> environment variable to a ':'-separated list of
543 "objects" and "signals".
547 @G_TYPE_DEBUG_NONE: Print no messages.
548 @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping.
549 @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions.
552 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
554 Similar to g_type_init(), but additionally sets debug flags.
557 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
560 <!-- ##### FUNCTION g_type_name ##### -->
562 Return the unique name that is assigned to a type ID (this is the preferred method
563 to find out whether a specific type has been registered for the passed in ID yet).
566 @type: Type to return name for.
567 @Returns: Static type name or %NULL.
570 <!-- ##### FUNCTION g_type_qname ##### -->
572 Return the corresponding quark of the type IDs name.
575 @type: Type to return quark of type name for.
576 @Returns: The type names quark or 0.
579 <!-- ##### FUNCTION g_type_from_name ##### -->
581 Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
582 (this is the preferred method to find out by name whether a specific type has been registered yet).
585 @name: Type name to lookup.
586 @Returns: Corresponding type ID or 0.
589 <!-- ##### FUNCTION g_type_parent ##### -->
591 Return the direct parent type of the passed in type.
592 If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
595 @type: The derived type.
596 @Returns: The parent type.
599 <!-- ##### FUNCTION g_type_depth ##### -->
601 Returns the length of the ancestry of the passed in type. This includes the
602 type itself, so that e.g. a fundamental type has depth 1.
605 @type: A #GType value.
606 @Returns: The depth of @type.
609 <!-- ##### FUNCTION g_type_next_base ##### -->
611 Given a @leaf_type and a @root_type which is contained in its anchestry, return
612 the type that @root_type is the immediate parent of.
613 In other words, this function determines the type that is derived directly from
614 @root_type which is also a base class of @leaf_type. Given a root type and a
615 leaf type, this function can be used to determine the types and order in which
616 the leaf type is descended from the root type.
619 @leaf_type: Descendant of @root_type and the type to be returned.
620 @root_type: Immediate parent of the returned type.
621 @Returns: Immediate child of @root_type and anchestor of @leaf_type.
624 <!-- ##### FUNCTION g_type_is_a ##### -->
626 If @is_a_type is a derivable type, check whether @type is a descendant of @is_a_type.
627 If @is_a_type is an interface, check whether @type conforms to it.
630 @type: Type to check anchestry for.
631 @is_a_type: Possible anchestor of @type or interface @type could conform to.
632 @Returns: %TRUE if @type is_a @is_a_type holds true.
635 <!-- ##### FUNCTION g_type_class_ref ##### -->
637 Increments the reference count of the class structure belonging to
638 @type. This function will demand-create the class if it doesn't
642 @type: Type ID of a classed type.
643 @Returns: The #GTypeClass structure for the given type ID.
646 <!-- ##### FUNCTION g_type_class_peek ##### -->
648 This function is essentially the same as g_type_class_ref(), except that
649 the classes reference count isn't incremented. Therefore, this function
650 may return %NULL if the class of the type passed in does not currently
651 exist (hasn't been referenced before).
654 @type: Type ID of a classed type.
655 @Returns: The #GTypeClass structure for the given type ID or %NULL
656 if the class does not currently exist.
659 <!-- ##### FUNCTION g_type_class_unref ##### -->
661 Decrements the reference count of the class structure being passed in.
662 Once the last reference count of a class has been released, classes
663 may be finalized by the type system, so further dereferencing of a
664 class pointer after g_type_class_unref() are invalid.
667 @g_class: The #GTypeClass structure to unreference.
670 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
672 This is a convenience function, often needed in class initializers.
673 It essentially takes the immediate parent type of the class passed in,
674 and returns the class structure thereof. Since derived classes hold
675 a reference count on their parent classes as long as they are instantiated,
676 the returned class will always exist. This function is essentially
680 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
685 @g_class: The #GTypeClass structure to retrieve the parent class for.
686 @Returns: The parent class of @g_class.
689 <!-- ##### FUNCTION g_type_interface_peek ##### -->
691 Returns the #GTypeInterface structure of an interface to which the passed in
695 @instance_class: A #GTypeClass structure.
696 @iface_type: An interface ID which this class conforms to.
697 @Returns: The #GTypeInterface structure of @iface_type, or %NULL if the
698 class is not instantiated.
701 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
710 <!-- ##### FUNCTION g_type_children ##### -->
712 Return a newly allocated and 0-terminated array of type IDs, listing the
713 child types of @type. The return value has to be g_free()ed after use.
716 @type: The parent type.
717 @n_children: Optional #guint pointer to contain the number of child types.
718 @Returns: Newly allocated and 0-terminated array of child types.
721 <!-- ##### FUNCTION g_type_interfaces ##### -->
723 Return a newly allocated and 0-terminated array of type IDs, listing the
724 interface types that @type conforms to. The return value has to be
725 g_free()ed after use.
728 @type: The type to list interface types for.
729 @n_interfaces: Optional #guint pointer to contain the number of interface types.
730 @Returns: Newly allocated and 0-terminated array of interface types.
733 <!-- ##### FUNCTION g_type_set_qdata ##### -->
743 <!-- ##### FUNCTION g_type_get_qdata ##### -->
753 <!-- ##### FUNCTION g_type_query ##### -->
762 <!-- ##### STRUCT GTypeQuery ##### -->
772 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
774 A callback function used by the type system to do base initialization
775 of the class structures of derived types. It is called as part of the
776 initialization process of all derived classes and should reallocate
777 or reset all dynamic class members copied over from the parent class.
778 Therefore class members, e.g. strings, that are not sufficiently
779 handled by a plain memory copy of the parent class into the derived class
780 have to be altered. See GClassInitFunc() for a discussion of the class
781 intialization process.
784 @g_class: The #GTypeClass structure to initialize.
787 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
789 A callback function used by the type system to finalize those portions
790 of a derived types class structure that were setup from the corresponding
791 GBaseInitFunc() function. Class finalization basically works the inverse
792 way in which class intialization is performed.
793 See GClassInitFunc() for a discussion of the class intialization process.
796 @g_class: The #GTypeClass structure to finalize.
799 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
801 A callback function used by the type system to initialize the class
802 of a specific type. This function should initialize all static class
804 The initialization process of a class involves:
806 <varlistentry><term></term><listitem><para>
807 1 - Copying common members from the parent class over to the
808 derived class structure.
809 </para></listitem></varlistentry>
810 <varlistentry><term></term><listitem><para>
811 2 - Zero initialization of the remaining members not copied
812 over from the parent class.
813 </para></listitem></varlistentry>
814 <varlistentry><term></term><listitem><para>
815 3 - Invocation of the GBaseInitFunc() initializers of all parent
816 types and the class' type.
817 </para></listitem></varlistentry>
818 <varlistentry><term></term><listitem><para>
819 4 - Invocation of the class' GClassInitFunc() initializer.
820 </para></listitem></varlistentry>
822 Since derived classes are partially initialized through a memory copy
823 of the parent class, the general rule is that GBaseInitFunc() and
824 GBaseFinalizeFunc() should take care of necessary reinitialization
825 and release of those class members that were introduced by the type
826 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
827 GClassInitFunc() should only care about initializing static
828 class members, while dynamic class members (such as allocated strings
829 or reference counted resources) are better handled by a GBaseInitFunc()
830 for this type, so proper initialization of the dynamic class members
831 is performed for class initialization of derived types as well.
832 An example may help to correspond the intend of the different class
837 GObjectClass parent_class;
839 gchar *dynamic_string;
842 type_a_base_class_init (TypeAClass *class)
844 class->dynamic_string = g_strdup ("some string");
847 type_a_base_class_finalize (TypeAClass *class)
849 g_free (class->dynamic_string);
852 type_a_class_init (TypeAClass *class)
854 class->static_integer = 42;
858 TypeAClass parent_class;
860 GString *dynamic_gstring;
863 type_b_base_class_init (TypeBClass *class)
865 class->dynamic_gstring = g_string_new ("some other string");
868 type_b_base_class_finalize (TypeBClass *class)
870 g_string_free (class->dynamic_gstring);
873 type_b_class_init (TypeBClass *class)
875 class->static_float = 3.14159265358979323846;
878 Initialization of TypeBClass will first cause initialization of
879 TypeAClass (derived classes reference their parent classes, see
880 g_type_class_ref() on this).
881 Initialization of TypeAClass roughly involves zero-initializing its fields,
882 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
883 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
884 type_a_class_init() to initialize its static members (static_integer).
885 The first step in the initialization process of TypeBClass is then
886 a plain memory copy of the contents of TypeAClass into TypeBClass and
887 zero-initialization of the remaining fields in TypeBClass.
888 The dynamic members of TypeAClass within TypeBClass now need
889 reinitialization which is performed by calling type_a_base_class_init()
890 with an argument of TypeBClass.
891 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
892 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
893 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
894 is called to complete the initialization process with the static members
896 Corresponding finalization counter parts to the GBaseInitFunc() functions
897 have to be provided to release allocated resources at class finalization
901 @g_class: The #GTypeClass structure to initialize.
902 @class_data: The @class_data member supplied via the #GTypeInfo structure.
905 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
907 A callback function used by the type system to finalize a class.
908 This function is rarely needed, as dynamically allocated class resources
909 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
910 Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
911 structure of a static type is invalid, because classes of static types
912 will never be finalized (they are artificially kept alive when their
913 reference count drops to zero).
916 @g_class: The #GTypeClass structure to finalize.
917 @class_data: The @class_data member supplied via the #GTypeInfo structure.
920 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
922 A callback function used by the type system to initialize a new
923 instance of a type. This function initializes all instance members and
924 allocates any resources required by it.
925 Initialization of a derived instance involves calling all its parent
926 types instance initializers, therefore the class member of the instance
927 is altered during its initialization to always point to the class that
928 belongs to the type the current initializer was introduced for.
931 @instance: The instance to initialize.
932 @g_class: The class of the type the instance is created for.
935 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
937 A callback function used by the type system to initialize a new
938 interface. This function should initialize all internal data and
939 allocate any resources required by the interface.
942 @g_iface: The interface structure to initialize.
943 @iface_data: The @class_data supplied via the #GTypeInfo structure.
946 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
948 A callback function used by the type system to finalize an interface.
949 This function should destroy any internal data and release any resources
950 allocated by the corresponding GInterfaceInitFunc() function.
953 @g_iface: The interface structure to finalize.
954 @iface_data: The @class_data supplied via the #GTypeInfo structure.
957 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
967 <!-- ##### ENUM GTypeFlags ##### -->
969 Bit masks used to check or determine characteristics of a type.
972 @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
973 created for an abstract type.
974 @G_TYPE_FLAG_VALUE_ABSTRACT:
976 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
978 Bit masks used to check or determine specific characteristics of a
982 @G_TYPE_FLAG_CLASSED: Indicates a classed type.
983 @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed).
984 @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type.
985 @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable).
987 <!-- ##### FUNCTION g_type_register_static ##### -->
989 Registers @type_name as the name of a new static type derived from
990 @parent_type. The type system uses the information contained in the
991 #GTypeInfo structure pointed to by @info to manage the type and its
992 instances (if not abstract). The value of @flags determines the nature
993 (e.g. abstract or not) of the type.
996 @parent_type: Type which this type will be derived from.
997 @type_name: 0-terminated string used as the name of the new type.
998 @info: The #GTypeInfo structure for this type.
999 @flags: Bitwise combination of #GTypeFlags values.
1000 @Returns: The new type identifier.
1003 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1005 Registers @type_name as the name of a new dynamic type derived from
1006 @parent_type. The type system uses the information contained in the
1007 #GTypePlugin structure pointed to by @plugin to manage the type and its
1008 instances (if not abstract). The value of @flags determines the nature
1009 (e.g. abstract or not) of the type.
1012 @parent_type: Type which this type will be derived from.
1013 @type_name: 0-terminated string used as the name of the new type.
1014 @plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from.
1015 @flags: Bitwise combination of #GTypeFlags values.
1016 @Returns: The new type identifier or #G_TYPE_INVALID if registration failed.
1019 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1021 Registers @type_id as the predefined identifier and @type_name as the
1022 name of a fundamental type. The type system uses the information
1023 contained in the #GTypeInfo structure pointed to by @info and the
1024 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1025 type and its instances. The value of @flags determines additional
1026 characteristics of the fundamental type.
1029 @type_id: A predefined #GTypeFundamentals value.
1030 @type_name: 0-terminated string used as the name of the new type.
1031 @info: The #GTypeInfo structure for this type.
1032 @finfo: The #GTypeFundamentalInfo structure for this type.
1033 @flags: Bitwise combination of #GTypeFlags values.
1034 @Returns: The predefined type identifier.
1037 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1039 Adds the static @interface_type to @instantiable_type. The information
1040 contained in the #GTypeInterfaceInfo structure pointed to by @info
1041 is used to manage the relationship.
1044 @instance_type: #GType value of an instantiable type.
1045 @interface_type: #GType value of an interface type.
1046 @info: The #GInterfaceInfo structure for this
1047 (@instance_type, @interface_type) combination.
1050 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1059 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1068 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1070 Returns the #GTypePlugin structure for @type or
1071 %NULL if @type does not have a #GTypePlugin structure.
1074 @type: The #GType to retrieve the plugin for.
1075 @Returns: The corresponding plugin if @type is a dynamic type,
1079 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1084 @implementation_type:
1088 <!-- ##### FUNCTION g_type_fundamental_next ##### -->
1090 Returns the next free fundamental type id which can be used to
1091 register a new fundamental type with g_type_register_fundamental().
1092 The returned type ID represents the highest currently registered
1093 fundamental type identifier.
1097 @Returns: The nextmost fundamental type ID to be registered,
1098 or 0 if the type system ran out of fundamental type IDs.
1101 <!-- ##### FUNCTION g_type_fundamental ##### -->
1103 Internal function, used to extract the fundamental type ID portion.
1104 use G_TYPE_FUNDAMENTAL() instead.
1107 @type_id: valid type ID
1108 @Returns: fundamental type ID
1111 <!-- ##### FUNCTION g_type_create_instance ##### -->
1113 Creates and initializes an instance of @type if @type is valid and can
1114 be instantiated. The type system only performs basic allocation and
1115 structure setups for instances, actual instance creation should happen
1116 through functions supplied by the type's fundamental type implementation.
1117 So use of g_type_create_instance() is reserved for implementators of
1118 fundamental types only. E.g. instances of the #GObject hierarchy
1119 should be created via g_object_new() and <emphasis>never</emphasis>
1120 directly through g_type_create_instance() which doesn't handle
1121 things like singleton objects or object construction.
1122 Note: Do <emphasis>not</emphasis> use this function, unless you're
1123 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1124 use this function but g_object_new() instead.
1127 @type: An instantiabtable type to create an instance for.
1128 @Returns: An allocated and initialized instance, subject to further
1129 treatment by the fundamental type implementation.
1132 <!-- ##### FUNCTION g_type_free_instance ##### -->
1139 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1148 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1157 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1165 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1167 Returns the location of the #GTypeValueTable associated with @type.
1168 <emphasis>Note, this function should only be used from source code
1169 that implements or has internal knowledge of the implementation of
1173 @type: A #GType value.
1174 @Returns: Location of the #GTypeValueTable associated with @type or
1175 %NULL if there is no #GTypeValueTable associated with @type.
1178 <!-- ##### MACRO G_TYPE_INVALID ##### -->
1185 <!-- ##### MACRO G_TYPE_NONE ##### -->
1192 <!-- ##### MACRO G_TYPE_INTERFACE ##### -->
1199 <!-- ##### MACRO G_TYPE_CHAR ##### -->
1206 <!-- ##### MACRO G_TYPE_UCHAR ##### -->
1213 <!-- ##### MACRO G_TYPE_BOOLEAN ##### -->
1220 <!-- ##### MACRO G_TYPE_INT ##### -->
1227 <!-- ##### MACRO G_TYPE_UINT ##### -->
1234 <!-- ##### MACRO G_TYPE_LONG ##### -->
1241 <!-- ##### MACRO G_TYPE_ULONG ##### -->
1248 <!-- ##### MACRO G_TYPE_INT64 ##### -->
1255 <!-- ##### MACRO G_TYPE_UINT64 ##### -->
1262 <!-- ##### MACRO G_TYPE_ENUM ##### -->
1269 <!-- ##### MACRO G_TYPE_FLAGS ##### -->
1276 <!-- ##### MACRO G_TYPE_FLOAT ##### -->
1283 <!-- ##### MACRO G_TYPE_DOUBLE ##### -->
1290 <!-- ##### MACRO G_TYPE_STRING ##### -->
1297 <!-- ##### MACRO G_TYPE_POINTER ##### -->
1304 <!-- ##### MACRO G_TYPE_BOXED ##### -->
1311 <!-- ##### MACRO G_TYPE_PARAM ##### -->
1318 <!-- ##### MACRO G_TYPE_OBJECT ##### -->
1325 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_FIRST ##### -->
1332 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_LAST ##### -->
1339 <!-- ##### MACRO G_TYPE_RESERVED_BSE_FIRST ##### -->
1346 <!-- ##### MACRO G_TYPE_RESERVED_BSE_LAST ##### -->
1353 <!-- ##### MACRO G_TYPE_RESERVED_USER_FIRST ##### -->