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 the fundamental type which is the ancestor of @type.
51 Fundamental types are types that serve as fundaments for the derived types,
52 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 ##### -->
106 Returns %TRUE if @type is a value type which can be used for
110 @type: A #GType value.
113 <!-- ##### MACRO G_TYPE_HAS_VALUE_TABLE ##### -->
115 Returns %TRUE if @type has a #GTypeValueTable.
118 @type: A #GType value.
121 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
123 Returns %TRUE if @type is a classed type.
126 @type: A #GType value.
129 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
131 Returns %TRUE if @type can be instantiated. Instantiation is the
132 process of creating an instance (object) of this type.
135 @type: A #GType value.
138 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
140 Returns %TRUE if @type is a derivable type. A derivable type can
141 be used as the base class of a flat (single-level) class hierarchy.
144 @type: A #GType value.
147 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
149 Returns %TRUE if @type is a deep derivable type. A deep derivable type
150 can be used as the base class of a deep (multi-level) class hierarchy.
153 @type: A #GType value.
156 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
158 Returns %TRUE if @type is an interface type.
159 Interface types are types that provide pure APIs, the implementation
160 of which is provided by another type (which is then said to conform
161 to the interface). GLib interfaces are somewhat analogous to Java
162 interfaces and C++ classes containing only pure virtual functions,
163 with the difference that GType interfaces are not derivable (but see
164 g_type_interface_add_prerequisite() for an alternative).
167 @type: A #GType value.
170 <!-- ##### STRUCT GTypeInterface ##### -->
172 An opaque structure used as the base of all interface types.
176 <!-- ##### STRUCT GTypeInstance ##### -->
178 An opaque structure used as the base of all type instances.
182 <!-- ##### STRUCT GTypeClass ##### -->
188 <!-- ##### STRUCT GTypeInfo ##### -->
190 This structure is used to provide the type system with the information
191 required to initialize and destruct (finalize) a type's class and
193 The initialized structure is passed to the g_type_register_static() function
194 (or is copied into the provided #GTypeInfo structure in the
195 g_type_plugin_complete_type_info()). The type system will perform a deep
196 copy of this structure, so it's memory does not need to be persistent
197 across invocation of g_type_register_static().
200 @class_size: Size of the class structure (required for interface, classed and instantiatable types).
201 @base_init: Location of the base initialization function (optional).
202 @base_finalize: Location of the base finalization function (optional).
203 @class_init: Location of the class initialization function (optional, for classed and instantiatable types only).
204 @class_finalize: Location of the class finalization function (optional).
205 @class_data: User-supplied data passed to the class init/finalize functions.
206 @instance_size: Size of the instance (object) structure (required for instantiatable types only).
207 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
208 @instance_init: Location of the instance initialization function (optional, for instantiatable types only).
209 @value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usually only
210 useful for fundamental types).
212 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
214 A structure that provides information to the type system which is
215 used specifically for managing fundamental types.
220 <!-- ##### STRUCT GInterfaceInfo ##### -->
222 A structure that provides information to the type system which is
223 used specifically for managing interface types.
226 @interface_init: Location of the function that initializes the interface.
227 @interface_finalize: Location of the function that finalizes the interface.
228 @interface_data: Location of user data passed to the @interface_init and
229 @interface_finalize functions (optional).
231 <!-- ##### STRUCT GTypeValueTable ##### -->
233 The #GTypeValueTable provides the functions required by the #GValue implementation,
234 to serve as a container for values of a type.
237 @value_init: Default initialize @values contents by poking values
238 directly into the value->data array. The data array of
239 the #GValue passed into this function was zero-filled
240 with <function>memset()</function>, so no care has to
242 old contents. E.g. for the implementation of a string
243 value that may never be %NULL, the implementation might
247 value->data[0].v_pointer = g_strdup ("");
250 @value_free: Free any old contents that might be left in the
251 data array of the passed in @value. No resources may
252 remain allocated through the #GValue contents after
253 this function returns. E.g. for our above string type:
256 /* only free strings without a specific flag for static storage */
257 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
258 g_free (value->data[0].v_pointer);
261 @value_copy: @dest_value is a #GValue with zero-filled data section
262 and @src_value is a properly setup #GValue of same or
264 The purpose of this function is to copy the contents of
265 @src_value into @dest_value in a way, that even after
266 @src_value has been freed, the contents of @dest_value
267 remain valid. String type example:
270 dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
273 @value_peek_pointer: If the value contents fit into a pointer, such as objects
274 or strings, return this pointer, so the caller can peek at
275 the current contents. To extend on our above string example:
278 return value->data[0].v_pointer;
281 @collect_format: A string format describing how to collect the contents of
282 this value, bit-by-bit. Each character in the format represents
283 an argument to be collected, the characters themselves indicate
284 the type of the argument. Currently supported arguments are:
286 <varlistentry><term></term><listitem><para>
287 'i' - Integers. passed as collect_values[].v_int.
288 </para></listitem></varlistentry>
289 <varlistentry><term></term><listitem><para>
290 'l' - Longs. passed as collect_values[].v_long.
291 </para></listitem></varlistentry>
292 <varlistentry><term></term><listitem><para>
293 'd' - Doubles. passed as collect_values[].v_double.
294 </para></listitem></varlistentry>
295 <varlistentry><term></term><listitem><para>
296 'p' - Pointers. passed as collect_values[].v_pointer.
297 </para></listitem></varlistentry>
299 It should be noted, that for variable argument list construction,
300 ANSI C promotes every type smaller than an integer to an int, and
301 floats to doubles. So for collection of short int or char, 'i'
302 needs to be used, and for collection of floats 'd'.
303 @collect_value: The collect_value() function is responsible for converting the
304 values collected from a variable argument list into contents
305 suitable for storage in a GValue. This function should setup
306 @value similar to value_init(), e.g. for a string value that
307 does not allow %NULL pointers, it needs to either spew an error,
308 or do an implicit conversion by storing an empty string.
309 The @value passed in to this function has a zero-filled data
310 array, so just like for value_init() it is guaranteed to not
311 contain any old contents that might need freeing.
312 @n_collect_values is exactly the string length of @collect_format,
313 and @collect_values is an array of unions #GTypeCValue with
314 length @n_collect_values, containing the collected values
315 according to @collect_format.
316 @collect_flags is an argument provided as a hint by the caller,
317 which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
318 that the collected value contents may be considered "static"
319 for the duration of the @value lifetime.
320 Thus an extra copy of the contents stored in @collect_values is
321 not required for assignment to @value.
322 For our above string example, we continue with:
325 if (!collect_values[0].v_pointer)
326 value->data[0].v_pointer = g_strdup ("");
327 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
329 value->data[0].v_pointer = collect_values[0].v_pointer;
330 /* keep a flag for the value_free() implementation to not free this string */
331 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
334 value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
339 It should be noted, that it is generally a bad idea to follow the
340 #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
341 reentrancy requirements and reference count assertions performed
342 by the #GSignal code, reference counts should always be incremented
343 for reference counted contents stored in the value->data array.
344 To deviate from our string example for a moment, and taking a look
345 at an exemplary implementation for collect_value() of #GObject:
348 if (collect_values[0].v_pointer)
350 GObject *object = G_OBJECT (collect_values[0].v_pointer);
352 /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
353 value->data[0].v_pointer = g_object_ref (object);
357 return g_strdup_printf ("Object passed as invalid NULL pointer");
360 The reference count for valid objects is always incremented,
361 regardless of @collect_flags. For invalid objects, the example
362 returns a newly allocated string without altering @value.
363 Upon success, collect_value() needs to return %NULL, if however
364 a malicious condition occurred, collect_value() may spew an
365 error by returning a newly allocated non-%NULL string, giving
366 a suitable description of the error condition.
367 The calling code makes no assumptions about the @value
368 contents being valid upon error returns, @value
369 is simply thrown away without further freeing. As such, it is
370 a good idea to not allocate #GValue contents, prior to returning
371 an error, however, collect_values() is not obliged to return
372 a correctly setup @value for error returns, simply because
373 any non-%NULL return is considered a fatal condition so further
374 program behaviour is undefined.
375 @lcopy_format: Format description of the arguments to collect for @lcopy_value,
376 analogous to @collect_format. Usually, @lcopy_format string consists
377 only of 'p's to provide lcopy_value() with pointers to storage locations.
378 @lcopy_value: This function is responsible for storing the @value contents into
379 arguments passed through a variable argument list which got
380 collected into @collect_values according to @lcopy_format.
381 @n_collect_values equals the string length of @lcopy_format,
382 and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS.
383 In contrast to collect_value(), lcopy_value() is obliged to
384 always properly support #G_VALUE_NOCOPY_CONTENTS.
385 Similar to collect_value() the function may prematurely abort
386 by returning a newly allocated string describing an error condition.
387 To complete the string example:
390 gchar **string_p = collect_values[0].v_pointer;
393 return g_strdup_printf ("string location passed as NULL");
395 if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
396 *string_p = value->data[0].v_pointer;
398 *string_p = g_strdup (value->data[0].v_pointer);
402 And an exemplary version of lcopy_value() for
403 reference-counted types:
406 GObject **object_p = collect_values[0].v_pointer;
409 return g_strdup_printf ("object location passed as NULL");
410 if (!value->data[0].v_pointer)
412 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) /* always honour */
413 *object_p = value->data[0].v_pointer;
415 *object_p = g_object_ref (value->data[0].v_pointer);
420 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
422 Returns the type identifier from a given @instance structure.
425 @instance: Location of a valid #GTypeInstance structure.
428 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
430 Returns the type identifier from a given @class structure.
433 @g_class: Location of a valid #GTypeClass structure.
436 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
438 Returns the type identifier from a given @interface structure.
441 @g_iface: Location of a valid #GTypeInterface structure.
444 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
446 Returns the class structure of a given @instance, casted
447 to a specified anchestor type @g_type of the instance.
450 @instance: Location of the #GTypeInstance structure.
451 @g_type: The anchestor type of the class to be returned.
452 @c_type: The corresponding C type of @g_type.
455 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
457 Returns the interface structure for interface @g_type of a given @instance.
460 @instance: Location of the #GTypeInstance structure.
461 @g_type: The interface type to be returned.
462 @c_type: The corresponding C type of @g_type.
465 <!-- ##### MACRO G_TYPE_INSTANCE_GET_PRIVATE ##### -->
467 Gets the private structure for a particular type.
468 The private structure must have been registered in the
469 class_init function with g_type_class_add_private().
472 @instance: the instance of a type deriving from @private_type.
473 @g_type: the type identifying which private data to retrieve.
474 @c_type: The C type for the private structure.
476 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
484 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
494 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
503 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
513 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
522 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
530 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
539 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
546 <!-- ##### FUNCTION g_type_init ##### -->
548 Prior to any use of the type system, g_type_init() has to be called to initialize
549 the type system and assorted other code portions (such as the various fundamental
550 type implementations or the signal system).
555 <!-- ##### ENUM GTypeDebugFlags ##### -->
557 The <type>GTypeDebugFlags</type> enumeration values can be passed to
558 g_type_init_with_debug_flags() to trigger debugging messages during runtime.
559 Note that the messages can also be triggered by setting the
560 <envar>GOBJECT_DEBUG</envar> environment variable to a ':'-separated list of
561 "objects" and "signals".
565 @G_TYPE_DEBUG_NONE: Print no messages.
566 @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping.
567 @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions.
570 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
572 Similar to g_type_init(), but additionally sets debug flags.
575 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
578 <!-- ##### FUNCTION g_type_name ##### -->
580 Returns the unique name that is assigned to a type ID (this is the preferred method
581 to find out whether a specific type has been registered for the passed in ID yet).
584 @type: Type to return name for.
585 @Returns: Static type name or %NULL.
588 <!-- ##### FUNCTION g_type_qname ##### -->
590 Return the corresponding quark of the type IDs name.
593 @type: Type to return quark of type name for.
594 @Returns: The type names quark or 0.
597 <!-- ##### FUNCTION g_type_from_name ##### -->
599 Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
600 (this is the preferred method to find out by name whether a specific type has been registered yet).
603 @name: Type name to lookup.
604 @Returns: Corresponding type ID or 0.
607 <!-- ##### FUNCTION g_type_parent ##### -->
609 Return the direct parent type of the passed in type.
610 If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
613 @type: The derived type.
614 @Returns: The parent type.
617 <!-- ##### FUNCTION g_type_depth ##### -->
619 Returns the length of the ancestry of the passed in type. This includes the
620 type itself, so that e.g. a fundamental type has depth 1.
623 @type: A #GType value.
624 @Returns: The depth of @type.
627 <!-- ##### FUNCTION g_type_next_base ##### -->
629 Given a @leaf_type and a @root_type which is contained in its anchestry, return
630 the type that @root_type is the immediate parent of.
631 In other words, this function determines the type that is derived directly from
632 @root_type which is also a base class of @leaf_type. Given a root type and a
633 leaf type, this function can be used to determine the types and order in which
634 the leaf type is descended from the root type.
637 @leaf_type: Descendant of @root_type and the type to be returned.
638 @root_type: Immediate parent of the returned type.
639 @Returns: Immediate child of @root_type and anchestor of @leaf_type.
642 <!-- ##### FUNCTION g_type_is_a ##### -->
644 If @is_a_type is a derivable type, check whether @type is a descendant of @is_a_type.
645 If @is_a_type is an interface, check whether @type conforms to it.
648 @type: Type to check anchestry for.
649 @is_a_type: Possible anchestor of @type or interface @type could conform to.
650 @Returns: %TRUE if @type is_a @is_a_type holds true.
653 <!-- ##### FUNCTION g_type_class_ref ##### -->
655 Increments the reference count of the class structure belonging to
656 @type. This function will demand-create the class if it doesn't
660 @type: Type ID of a classed type.
661 @Returns: The #GTypeClass structure for the given type ID.
664 <!-- ##### FUNCTION g_type_class_peek ##### -->
666 This function is essentially the same as g_type_class_ref(), except that
667 the classes reference count isn't incremented. Therefore, this function
668 may return %NULL if the class of the type passed in does not currently
669 exist (hasn't been referenced before).
672 @type: Type ID of a classed type.
673 @Returns: The #GTypeClass structure for the given type ID or %NULL
674 if the class does not currently exist.
677 <!-- ##### FUNCTION g_type_class_unref ##### -->
679 Decrements the reference count of the class structure being passed in.
680 Once the last reference count of a class has been released, classes
681 may be finalized by the type system, so further dereferencing of a
682 class pointer after g_type_class_unref() are invalid.
685 @g_class: The #GTypeClass structure to unreference.
688 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
690 This is a convenience function, often needed in class initializers.
691 It essentially takes the immediate parent type of the class passed in,
692 and returns the class structure thereof. Since derived classes hold
693 a reference count on their parent classes as long as they are instantiated,
694 the returned class will always exist. This function is essentially
698 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
703 @g_class: The #GTypeClass structure to retrieve the parent class for.
704 @Returns: The parent class of @g_class.
707 <!-- ##### FUNCTION g_type_class_add_private ##### -->
709 Registers a private structure for a instantiatable type;
710 when an object is allocated, the private structures for
711 the type and and all of its parent types are allocated
712 sequentially in the same memory block as the public
713 structures. This function should be called in the
714 type's class_init() function. The private structure can
715 be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro.
716 The following example shows attaching a private structure
717 <structname>MyObjectPrivate</structname> to an object
718 <structname>MyObject</structname> defined in the standard GObject
722 typedef struct _MyObjectPrivate MyObjectPrivate;
724 struct _MyObjectPrivate {
728 #define MY_OBJECT_GET_PRIVATE(o) \
729 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MY_TYPE_OBJECT, MyObjectPrivate))
732 my_object_class_init (MyObjectClass *klass)
734 g_type_class_add_private (klass, sizeof (MyObjectPrivate));
738 my_object_get_some_field (MyObject *my_object)
740 MyObjectPrivate *priv = MY_OBJECT_GET_PRIVATE (my_object);
742 return priv->some_field;
746 @g_class: class structure for an instantiatable type
747 @private_size: size of private structure.
749 <!-- ##### FUNCTION g_type_interface_peek ##### -->
751 Returns the #GTypeInterface structure of an interface to which the passed in
755 @instance_class: A #GTypeClass structure.
756 @iface_type: An interface ID which this class conforms to.
757 @Returns: The #GTypeInterface structure of @iface_type, or %NULL if the
758 class is not instantiated.
761 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
763 Returns the corresponding #GTypeInterface structure of the parent type
764 of the instance type to which @g_iface belongs. This is useful when
765 deriving the implementation of an interface from the parent type and
766 then possibly overriding some methods.
769 @g_iface: A #GTypeInterface structure.
770 @Returns: The corresponding #GTypeInterface structure of the parent type
771 of the instance type to which @g_iface belongs, or %NULL if the parent type
772 doesn't conform to the interface.
775 <!-- ##### FUNCTION g_type_children ##### -->
777 Return a newly allocated and 0-terminated array of type IDs, listing the
778 child types of @type. The return value has to be g_free()ed after use.
781 @type: The parent type.
782 @n_children: Optional #guint pointer to contain the number of child types.
783 @Returns: Newly allocated and 0-terminated array of child types.
786 <!-- ##### FUNCTION g_type_interfaces ##### -->
788 Return a newly allocated and 0-terminated array of type IDs, listing the
789 interface types that @type conforms to. The return value has to be
790 g_free()ed after use.
793 @type: The type to list interface types for.
794 @n_interfaces: Optional #guint pointer to contain the number of interface types.
795 @Returns: Newly allocated and 0-terminated array of interface types.
798 <!-- ##### FUNCTION g_type_interface_prerequisites ##### -->
800 Returns the prerequisites of an interfaces type.
803 @interface_type: an interface type
804 @n_prerequisites: location to return the number of prerequisites, or %NULL
805 @Returns: a newly-allocated zero-terminated array of #GType containing
806 the prerequisites of @interface_type
810 <!-- ##### FUNCTION g_type_set_qdata ##### -->
812 Attaches arbitrary data to a type.
816 @quark: a #GQuark id to identify the data
820 <!-- ##### FUNCTION g_type_get_qdata ##### -->
822 Obtains data which has previously been attached to @type
823 with g_type_set_qdata().
827 @quark: a #GQuark id to identify the data
828 @Returns: the data, or %NULL if no data was found
831 <!-- ##### FUNCTION g_type_query ##### -->
833 Queries the type system for information about a specific type.
834 This function will fill in a user-provided structure to hold type-specific
835 information. If an invalid #GType is passed in, the @type member of the
836 #GTypeQuery is 0. All members filled into the #GTypeQuery structure should
837 be considered constant and have to be left untouched.
840 @type: the #GType value of a static, classed type.
841 @query: A user provided structure that is filled in with constant values
845 <!-- ##### STRUCT GTypeQuery ##### -->
847 A structure holding information for a specific type. It is
848 filled in by the g_type_query() function.
851 @type: the #GType value of the type.
852 @type_name: the name of the type.
853 @class_size: the size of the class structure.
854 @instance_size: the size of the instance structure.
856 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
858 A callback function used by the type system to do base initialization
859 of the class structures of derived types. It is called as part of the
860 initialization process of all derived classes and should reallocate
861 or reset all dynamic class members copied over from the parent class.
862 Therefore class members, e.g. strings, that are not sufficiently
863 handled by a plain memory copy of the parent class into the derived class
864 have to be altered. See GClassInitFunc() for a discussion of the class
865 intialization process.
868 @g_class: The #GTypeClass structure to initialize.
871 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
873 A callback function used by the type system to finalize those portions
874 of a derived types class structure that were setup from the corresponding
875 GBaseInitFunc() function. Class finalization basically works the inverse
876 way in which class intialization is performed.
877 See GClassInitFunc() for a discussion of the class intialization process.
880 @g_class: The #GTypeClass structure to finalize.
883 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
885 A callback function used by the type system to initialize the class
886 of a specific type. This function should initialize all static class
888 The initialization process of a class involves:
890 <varlistentry><term></term><listitem><para>
891 1 - Copying common members from the parent class over to the
892 derived class structure.
893 </para></listitem></varlistentry>
894 <varlistentry><term></term><listitem><para>
895 2 - Zero initialization of the remaining members not copied
896 over from the parent class.
897 </para></listitem></varlistentry>
898 <varlistentry><term></term><listitem><para>
899 3 - Invocation of the GBaseInitFunc() initializers of all parent
900 types and the class' type.
901 </para></listitem></varlistentry>
902 <varlistentry><term></term><listitem><para>
903 4 - Invocation of the class' GClassInitFunc() initializer.
904 </para></listitem></varlistentry>
906 Since derived classes are partially initialized through a memory copy
907 of the parent class, the general rule is that GBaseInitFunc() and
908 GBaseFinalizeFunc() should take care of necessary reinitialization
909 and release of those class members that were introduced by the type
910 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
911 GClassInitFunc() should only care about initializing static
912 class members, while dynamic class members (such as allocated strings
913 or reference counted resources) are better handled by a GBaseInitFunc()
914 for this type, so proper initialization of the dynamic class members
915 is performed for class initialization of derived types as well.
916 An example may help to correspond the intend of the different class
921 GObjectClass parent_class;
923 gchar *dynamic_string;
926 type_a_base_class_init (TypeAClass *class)
928 class->dynamic_string = g_strdup ("some string");
931 type_a_base_class_finalize (TypeAClass *class)
933 g_free (class->dynamic_string);
936 type_a_class_init (TypeAClass *class)
938 class->static_integer = 42;
942 TypeAClass parent_class;
944 GString *dynamic_gstring;
947 type_b_base_class_init (TypeBClass *class)
949 class->dynamic_gstring = g_string_new ("some other string");
952 type_b_base_class_finalize (TypeBClass *class)
954 g_string_free (class->dynamic_gstring);
957 type_b_class_init (TypeBClass *class)
959 class->static_float = 3.14159265358979323846;
962 Initialization of TypeBClass will first cause initialization of
963 TypeAClass (derived classes reference their parent classes, see
964 g_type_class_ref() on this).
965 Initialization of TypeAClass roughly involves zero-initializing its fields,
966 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
967 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
968 type_a_class_init() to initialize its static members (static_integer).
969 The first step in the initialization process of TypeBClass is then
970 a plain memory copy of the contents of TypeAClass into TypeBClass and
971 zero-initialization of the remaining fields in TypeBClass.
972 The dynamic members of TypeAClass within TypeBClass now need
973 reinitialization which is performed by calling type_a_base_class_init()
974 with an argument of TypeBClass.
975 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
976 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
977 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
978 is called to complete the initialization process with the static members
980 Corresponding finalization counter parts to the GBaseInitFunc() functions
981 have to be provided to release allocated resources at class finalization
985 @g_class: The #GTypeClass structure to initialize.
986 @class_data: The @class_data member supplied via the #GTypeInfo structure.
989 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
991 A callback function used by the type system to finalize a class.
992 This function is rarely needed, as dynamically allocated class resources
993 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
994 Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
995 structure of a static type is invalid, because classes of static types
996 will never be finalized (they are artificially kept alive when their
997 reference count drops to zero).
1000 @g_class: The #GTypeClass structure to finalize.
1001 @class_data: The @class_data member supplied via the #GTypeInfo structure.
1004 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
1006 A callback function used by the type system to initialize a new
1007 instance of a type. This function initializes all instance members and
1008 allocates any resources required by it.
1009 Initialization of a derived instance involves calling all its parent
1010 types instance initializers, therefore the class member of the instance
1011 is altered during its initialization to always point to the class that
1012 belongs to the type the current initializer was introduced for.
1015 @instance: The instance to initialize.
1016 @g_class: The class of the type the instance is created for.
1019 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
1021 A callback function used by the type system to initialize a new
1022 interface. This function should initialize all internal data and
1023 allocate any resources required by the interface.
1026 @g_iface: The interface structure to initialize.
1027 @iface_data: The @class_data supplied via the #GTypeInfo structure.
1030 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
1032 A callback function used by the type system to finalize an interface.
1033 This function should destroy any internal data and release any resources
1034 allocated by the corresponding GInterfaceInitFunc() function.
1037 @g_iface: The interface structure to finalize.
1038 @iface_data: The @class_data supplied via the #GTypeInfo structure.
1041 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
1051 <!-- ##### ENUM GTypeFlags ##### -->
1053 Bit masks used to check or determine characteristics of a type.
1056 @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
1057 created for an abstract type.
1058 @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
1059 that introduces a value table, but can't be used for
1062 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
1064 Bit masks used to check or determine specific characteristics of a
1068 @G_TYPE_FLAG_CLASSED: Indicates a classed type.
1069 @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed).
1070 @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type.
1071 @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable).
1073 <!-- ##### FUNCTION g_type_register_static ##### -->
1075 Registers @type_name as the name of a new static type derived from
1076 @parent_type. The type system uses the information contained in the
1077 #GTypeInfo structure pointed to by @info to manage the type and its
1078 instances (if not abstract). The value of @flags determines the nature
1079 (e.g. abstract or not) of the type.
1082 @parent_type: Type which this type will be derived from.
1083 @type_name: 0-terminated string used as the name of the new type.
1084 @info: The #GTypeInfo structure for this type.
1085 @flags: Bitwise combination of #GTypeFlags values.
1086 @Returns: The new type identifier.
1089 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1091 Registers @type_name as the name of a new dynamic type derived from
1092 @parent_type. The type system uses the information contained in the
1093 #GTypePlugin structure pointed to by @plugin to manage the type and its
1094 instances (if not abstract). The value of @flags determines the nature
1095 (e.g. abstract or not) of the type.
1098 @parent_type: Type which this type will be derived from.
1099 @type_name: 0-terminated string used as the name of the new type.
1100 @plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from.
1101 @flags: Bitwise combination of #GTypeFlags values.
1102 @Returns: The new type identifier or #G_TYPE_INVALID if registration failed.
1105 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1107 Registers @type_id as the predefined identifier and @type_name as the
1108 name of a fundamental type. The type system uses the information
1109 contained in the #GTypeInfo structure pointed to by @info and the
1110 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1111 type and its instances. The value of @flags determines additional
1112 characteristics of the fundamental type.
1115 @type_id: A predefined #GTypeFundamentals value.
1116 @type_name: 0-terminated string used as the name of the new type.
1117 @info: The #GTypeInfo structure for this type.
1118 @finfo: The #GTypeFundamentalInfo structure for this type.
1119 @flags: Bitwise combination of #GTypeFlags values.
1120 @Returns: The predefined type identifier.
1123 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1125 Adds the static @interface_type to @instantiable_type. The information
1126 contained in the #GTypeInterfaceInfo structure pointed to by @info
1127 is used to manage the relationship.
1130 @instance_type: #GType value of an instantiable type.
1131 @interface_type: #GType value of an interface type.
1132 @info: The #GInterfaceInfo structure for this
1133 (@instance_type, @interface_type) combination.
1136 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1138 Adds the dynamic @interface_type to @instantiable_type. The information
1139 contained in the #GTypePlugin structure pointed to by @plugin
1140 is used to manage the relationship.
1143 @instance_type: the #GType value of an instantiable type.
1144 @interface_type: the #GType value of an interface type.
1145 @plugin: the #GTypePlugin structure to retrieve the #GInterfaceInfo from.
1148 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1150 Adds @prerequisite_type to the list of prerequisites of @interface_type.
1151 This means that any type implementing @interface_type must also implement
1152 @prerequisite_type. Prerequisites can be thought of as an alternative to
1153 interface derivation (which GType doesn't support). An interface can have
1154 at most one instantiatable prerequisite type.
1157 @interface_type: #GType value of an interface type.
1158 @prerequisite_type: #GType value of an interface or instantiatable type.
1161 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1163 Returns the #GTypePlugin structure for @type or
1164 %NULL if @type does not have a #GTypePlugin structure.
1167 @type: The #GType to retrieve the plugin for.
1168 @Returns: The corresponding plugin if @type is a dynamic type,
1172 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1174 Returns the #GTypePlugin structure for the dynamic interface
1175 @interface_type which has been added to @instance_type, or
1176 %NULL if @interface_type has not been added to @instance_type or does
1177 not have a #GTypePlugin structure. See g_type_add_interface_dynamic().
1180 @instance_type: the #GType value of an instantiatable type.
1181 @interface_type: the #GType value of an interface type.
1182 @Returns: the #GTypePlugin for the dynamic interface @interface_type
1186 <!-- ##### FUNCTION g_type_fundamental_next ##### -->
1188 Returns the next free fundamental type id which can be used to
1189 register a new fundamental type with g_type_register_fundamental().
1190 The returned type ID represents the highest currently registered
1191 fundamental type identifier.
1195 @Returns: The nextmost fundamental type ID to be registered,
1196 or 0 if the type system ran out of fundamental type IDs.
1199 <!-- ##### FUNCTION g_type_fundamental ##### -->
1201 Internal function, used to extract the fundamental type ID portion.
1202 use G_TYPE_FUNDAMENTAL() instead.
1205 @type_id: valid type ID
1206 @Returns: fundamental type ID
1209 <!-- ##### FUNCTION g_type_create_instance ##### -->
1211 Creates and initializes an instance of @type if @type is valid and can
1212 be instantiated. The type system only performs basic allocation and
1213 structure setups for instances, actual instance creation should happen
1214 through functions supplied by the type's fundamental type implementation.
1215 So use of g_type_create_instance() is reserved for implementators of
1216 fundamental types only. E.g. instances of the #GObject hierarchy
1217 should be created via g_object_new() and <emphasis>never</emphasis>
1218 directly through g_type_create_instance() which doesn't handle
1219 things like singleton objects or object construction.
1220 Note: Do <emphasis>not</emphasis> use this function, unless you're
1221 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1222 use this function but g_object_new() instead.
1225 @type: An instantiatable type to create an instance for.
1226 @Returns: An allocated and initialized instance, subject to further
1227 treatment by the fundamental type implementation.
1230 <!-- ##### FUNCTION g_type_free_instance ##### -->
1232 Frees an instance of a type, returning it to the instance pool for the type,
1236 Like g_type_create_i * gobject/tmpl/gtype.sgml:
1237 * gobject/tmpl/enumerations_flags.sgml: Add docs.
1238 nstance(), this function is reserved for implementors of
1242 @instance: an instance of a type.
1245 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1254 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1263 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1271 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1273 Returns the location of the #GTypeValueTable associated with @type.
1274 <emphasis>Note, this function should only be used from source code
1275 that implements or has internal knowledge of the implementation of
1279 @type: A #GType value.
1280 @Returns: Location of the #GTypeValueTable associated with @type or
1281 %NULL if there is no #GTypeValueTable associated with @type.
1284 <!-- ##### MACRO G_TYPE_INVALID ##### -->
1286 An invalid #GType, used as error return value in some functions which return
1292 <!-- ##### MACRO G_TYPE_NONE ##### -->
1294 A fundamental type which is used as a replacement for the C
1295 <literal>void</literal> return type.
1300 <!-- ##### MACRO G_TYPE_INTERFACE ##### -->
1302 The fundamental type from which all interfaces are derived.
1307 <!-- ##### MACRO G_TYPE_CHAR ##### -->
1309 The fundamental type corresponding to #gchar.
1314 <!-- ##### MACRO G_TYPE_UCHAR ##### -->
1316 The fundamental type corresponding to #guchar.
1321 <!-- ##### MACRO G_TYPE_BOOLEAN ##### -->
1323 The fundamental type corresponding to #gboolean.
1328 <!-- ##### MACRO G_TYPE_INT ##### -->
1330 The fundamental type corresponding to #gint.
1335 <!-- ##### MACRO G_TYPE_UINT ##### -->
1337 The fundamental type corresponding to #guint.
1342 <!-- ##### MACRO G_TYPE_LONG ##### -->
1344 The fundamental type corresponding to #glong.
1349 <!-- ##### MACRO G_TYPE_ULONG ##### -->
1351 The fundamental type corresponding to #gulong.
1356 <!-- ##### MACRO G_TYPE_INT64 ##### -->
1358 The fundamental type corresponding to #gint64.
1363 <!-- ##### MACRO G_TYPE_UINT64 ##### -->
1365 The fundamental type corresponding to #guint64.
1370 <!-- ##### MACRO G_TYPE_ENUM ##### -->
1372 The fundamental type from which all enumeration types are derived.
1377 <!-- ##### MACRO G_TYPE_FLAGS ##### -->
1379 The fundamental type from which all flags types are derived.
1384 <!-- ##### MACRO G_TYPE_FLOAT ##### -->
1386 The fundamental type corresponding to #gfloat.
1391 <!-- ##### MACRO G_TYPE_DOUBLE ##### -->
1393 The fundamental type corresponding to #gdouble.
1398 <!-- ##### MACRO G_TYPE_STRING ##### -->
1400 The fundamental type corresponding to nul-terminated C strings.
1405 <!-- ##### MACRO G_TYPE_POINTER ##### -->
1407 The fundamental type corresponding to #gpointer.
1412 <!-- ##### MACRO G_TYPE_BOXED ##### -->
1414 The fundamental type from which all boxed types are derived.
1419 <!-- ##### MACRO G_TYPE_PARAM ##### -->
1421 The fundamental type from which all #GParamSpec types are derived.
1426 <!-- ##### MACRO G_TYPE_OBJECT ##### -->
1428 The fundamental type for #GObject.
1433 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_FIRST ##### -->
1440 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_LAST ##### -->
1447 <!-- ##### MACRO G_TYPE_RESERVED_BSE_FIRST ##### -->
1454 <!-- ##### MACRO G_TYPE_RESERVED_BSE_LAST ##### -->
1461 <!-- ##### MACRO G_TYPE_RESERVED_USER_FIRST ##### -->
1469 sgml-parent-document: ("../gobject-docs.sgml" "book" "refsect2" "")