Patch from Havoc Pennington to add functions for setting and getting a
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / gtype.sgml
1 <!-- ##### SECTION Title ##### -->
2 GType
3
4 <!-- ##### SECTION Short_Description ##### -->
5 The GLib Runtime type identification and management system
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
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
13 type system.
14 </para>
15 <para>
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.
34 </para>
35
36 <!-- ##### SECTION See_Also ##### -->
37 <para>
38
39 </para>
40
41 <!-- ##### TYPEDEF GType ##### -->
42 <para>
43 A numerical value which represents the unique identifier of a registered
44 type.
45 </para>
46
47
48 <!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
49 <para>
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.
53 </para>
54
55 @type: A #GType value.
56
57
58 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_MAX ##### -->
59 <para>
60 An integer constant that represents the number of identifiers reserved
61 for types that are assigned at compile-time.
62 </para>
63
64
65
66 <!-- ##### MACRO G_TYPE_MAKE_FUNDAMENTAL ##### -->
67 <para>
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 
70 types.
71 </para>
72
73 @x: the fundamental type number.
74
75
76 <!-- ##### MACRO G_TYPE_IS_ABSTRACT ##### -->
77 <para>
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
80 derived classes.
81 </para>
82
83 @type: A #GType value.
84
85
86 <!-- ##### MACRO G_TYPE_IS_DERIVED ##### -->
87 <para>
88 Returns %TRUE if @type is derived (or in object-oriented terminology:
89 inherited) from another type (this holds true for all non-fundamental
90 types).
91 </para>
92
93 @type: A #GType value.
94
95
96 <!-- ##### MACRO G_TYPE_IS_FUNDAMENTAL ##### -->
97 <para>
98 Returns %TRUE if @type is a fundamental type.
99 </para>
100
101 @type: A #GType value.
102
103
104 <!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
105 <para>
106
107 </para>
108
109 @type: A #GType value.
110
111
112 <!-- ##### MACRO G_TYPE_HAS_VALUE_TABLE ##### -->
113 <para>
114 Returns %TRUE if @type has a #GTypeValueTable.
115 </para>
116
117 @type: A #GType value.
118
119
120 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
121 <para>
122 Returns %TRUE if @type is a classed type.
123 </para>
124
125 @type: A #GType value.
126
127
128 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
129 <para>
130 Returns %TRUE if @type can be instantiated.  Instantiation is the
131 process of creating an instance (object) of this type.
132 </para>
133
134 @type: A #GType value.
135
136
137 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
138 <para>
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.
141 </para>
142
143 @type: A #GType value.
144
145
146 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
147 <para>
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.
150 </para>
151
152 @type: A #GType value.
153
154
155 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
156 <para>
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).
164 </para>
165
166 @type: A #GType value.
167
168
169 <!-- ##### STRUCT GTypeInterface ##### -->
170 <para>
171 An opaque structure used as the base of all interface types.
172 </para>
173
174
175 <!-- ##### STRUCT GTypeInstance ##### -->
176 <para>
177 An opaque structure used as the base of all type instances.
178 </para>
179
180
181 <!-- ##### STRUCT GTypeInfo ##### -->
182 <para>
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
185 instances thereof.
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().
191 </para>
192
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).
204
205 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
206 <para>
207 A structure that provides information to the type system which is
208 used specifically for managing fundamental types.  
209 </para>
210
211 @type_flags: 
212
213 <!-- ##### STRUCT GInterfaceInfo ##### -->
214 <para>
215 A structure that provides information to the type system which is
216 used specifically for managing interface types.
217 </para>
218
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).
223
224 <!-- ##### STRUCT GTypeValueTable ##### -->
225 <para>
226 The #GTypeValueTable provides the functions required by the #GValue implementation,
227 to serve as a container for values of a type.
228 </para>
229
230 @value_init:            Default initialize @values contents by poking values
231                         directly into the value-&gt;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
234                         be taken to free any
235                         old contents. E.g. for the implementation of a string
236                         value that may never be %NULL, the implementation might
237                         look like:
238 <programlisting>
239 {
240   value-&gt;data[0].v_pointer = g_strdup ("");
241 }
242 </programlisting>
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:
247 <programlisting>
248 {
249   /* only free strings without a specific flag for static storage */
250   if (!(value-&gt;data[1].v_uint &amp; G_VALUE_NOCOPY_CONTENTS))
251     g_free (value-&gt;data[0].v_pointer);
252 }
253 </programlisting>
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
256                         derived type.
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:
261 <programlisting>
262 {
263   dest_value-&gt;data[0].v_pointer = g_strdup (src_value-&gt;data[0].v_pointer);
264 }
265 </programlisting>
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:
269 <programlisting>
270 {
271   return value-&gt;data[0].v_pointer;
272 }
273 </programlisting>
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:
278 <variablelist>
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>
291 </variablelist>
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:
316 <programlisting>
317 {
318   if (!collect_values[0].v_pointer)
319     value->data[0].v_pointer = g_strdup ("");
320   else if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS)
321     {
322       value-&gt;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-&gt;data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
325     }
326   else
327     value-&gt;data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
328
329   return NULL;
330 }
331 </programlisting>
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-&gt;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:
339 <programlisting>
340 {
341   if (collect_values[0].v_pointer)
342     {
343       GObject *object = G_OBJECT (collect_values[0].v_pointer);
344
345       /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
346       value-&gt;data[0].v_pointer = g_object_ref (object);
347       return NULL;
348     }
349   else
350     return g_strdup_printf ("Object passed as invalid NULL pointer");
351 }
352 </programlisting>
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:
381 <programlisting>
382 {
383   gchar **string_p = collect_values[0].v_pointer;
384
385   if (!string_p)
386     return g_strdup_printf ("string location passed as NULL");
387
388   if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS)
389     *string_p = value-&gt;data[0].v_pointer;
390   else
391     *string_p = g_strdup (value-&gt;data[0].v_pointer);
392
393 }
394 </programlisting>
395                         And an exemplary version of lcopy_value() for
396                         reference-counted types:
397 <programlisting>
398 {
399   GObject **object_p = collect_values[0].v_pointer;
400
401   if (!object_p)
402     return g_strdup_printf ("object location passed as NULL");
403   if (!value-&gt;data[0].v_pointer)
404     *object_p = NULL;
405   else if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS) /* always honour */
406     *object_p = value-&gt;data[0].v_pointer;
407   else
408     *object_p = g_object_ref (value-&gt;data[0].v_pointer);
409   return NULL;
410 }
411 </programlisting>
412
413 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
414 <para>
415 Returns the type identifier from a given @instance structure.
416 </para>
417
418 @instance: Location of a valid #GTypeInstance structure.
419
420
421 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
422 <para>
423 Returns the type identifier from a given @class structure.
424 </para>
425
426 @g_class: Location of a valid #GTypeClass structure.
427
428
429 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
430 <para>
431 Returns the type identifier from a given @interface structure.
432 </para>
433
434 @g_iface: Location of a valid #GTypeInterface structure.
435
436
437 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
438 <para>
439 Returns the class structure of a given @instance, casted
440 to a specified anchestor type @g_type of the instance.
441 </para>
442
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.
446
447
448 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
449 <para>
450
451 </para>
452
453 @instance: 
454 @g_type: 
455 @c_type: 
456
457
458 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
459 <para>
460
461 </para>
462
463 @instance: 
464
465
466 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
467 <para>
468
469 </para>
470
471 @instance: 
472 @g_type: 
473 @c_type: 
474
475
476 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
477 <para>
478
479 </para>
480
481 @instance: 
482 @g_type: 
483
484
485 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
486 <para>
487
488 </para>
489
490 @g_class: 
491 @g_type: 
492 @c_type: 
493
494
495 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
496 <para>
497
498 </para>
499
500 @g_class: 
501 @g_type: 
502
503
504 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
505 <para>
506
507 </para>
508
509 @value: 
510
511
512 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
513 <para>
514
515 </para>
516
517 @value: 
518 @g_type: 
519
520
521 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
522 <para>
523
524 </para>
525
526
527
528 <!-- ##### FUNCTION g_type_init ##### -->
529 <para>
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).
533 </para>
534
535
536
537 <!-- ##### ENUM GTypeDebugFlags ##### -->
538 <para>
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".
544
545 </para>
546
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.
550 @G_TYPE_DEBUG_MASK: 
551
552 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
553 <para>
554 Similar to g_type_init(), but additionally sets debug flags.
555 </para>
556
557 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
558
559
560 <!-- ##### FUNCTION g_type_name ##### -->
561 <para>
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).
564 </para>
565
566 @type:          Type to return name for.
567 @Returns:       Static type name or %NULL.
568
569
570 <!-- ##### FUNCTION g_type_qname ##### -->
571 <para>
572 Return the corresponding quark of the type IDs name.
573 </para>
574
575 @type:    Type to return quark of type name for.
576 @Returns: The type names quark or 0.
577
578
579 <!-- ##### FUNCTION g_type_from_name ##### -->
580 <para>
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).
583 </para>
584
585 @name:    Type name to lookup.
586 @Returns: Corresponding type ID or 0.
587
588
589 <!-- ##### FUNCTION g_type_parent ##### -->
590 <para>
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.
593 </para>
594
595 @type:    The derived type.
596 @Returns: The parent type.
597
598
599 <!-- ##### FUNCTION g_type_depth ##### -->
600 <para>
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.
603 </para>
604
605 @type:    A #GType value.
606 @Returns: The depth of @type.
607
608
609 <!-- ##### FUNCTION g_type_next_base ##### -->
610 <para>
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.
617 </para>
618
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.
622
623
624 <!-- ##### FUNCTION g_type_is_a ##### -->
625 <para>
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.
628 </para>
629
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.
633
634
635 <!-- ##### FUNCTION g_type_class_ref ##### -->
636 <para>
637 Increments the reference count of the class structure belonging to
638 @type. This function will demand-create the class if it doesn't
639 exist already.
640 </para>
641
642 @type:    Type ID of a classed type.
643 @Returns: The #GTypeClass structure for the given type ID.
644
645
646 <!-- ##### FUNCTION g_type_class_peek ##### -->
647 <para>
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).
652 </para>
653
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.
657
658
659 <!-- ##### FUNCTION g_type_class_unref ##### -->
660 <para>
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.
665 </para>
666
667 @g_class:       The #GTypeClass structure to unreference.
668
669
670 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
671 <para>
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
677 equivalent to:
678
679 <programlisting>
680 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
681 </programlisting>
682
683 </para>
684
685 @g_class: The #GTypeClass structure to retrieve the parent class for.
686 @Returns: The parent class of @g_class.
687
688
689 <!-- ##### FUNCTION g_type_interface_peek ##### -->
690 <para>
691 Returns the #GTypeInterface structure of an interface to which the passed in 
692 class conforms.
693 </para>
694
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.
699
700
701 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
702 <para>
703
704 </para>
705
706 @g_iface: 
707 @Returns: 
708
709
710 <!-- ##### FUNCTION g_type_children ##### -->
711 <para>
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.
714 </para>
715
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.
719
720
721 <!-- ##### FUNCTION g_type_interfaces ##### -->
722 <para>
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.
726 </para>
727
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.
731
732
733 <!-- ##### FUNCTION g_type_set_qdata ##### -->
734 <para>
735
736 </para>
737
738 @type: 
739 @quark: 
740 @data: 
741
742
743 <!-- ##### FUNCTION g_type_get_qdata ##### -->
744 <para>
745
746 </para>
747
748 @type: 
749 @quark: 
750 @Returns: 
751
752
753 <!-- ##### FUNCTION g_type_query ##### -->
754 <para>
755
756 </para>
757
758 @type: 
759 @query: 
760
761
762 <!-- ##### STRUCT GTypeQuery ##### -->
763 <para>
764
765 </para>
766
767 @type: 
768 @type_name: 
769 @class_size: 
770 @instance_size: 
771
772 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
773 <para>
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.
782 </para>
783
784 @g_class: The #GTypeClass structure to initialize.
785
786
787 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
788 <para>
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.
794 </para>
795
796 @g_class: The #GTypeClass structure to finalize.
797
798
799 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
800 <para>
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
803 members.
804 The initialization process of a class involves:
805 <variablelist>
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>
821 </variablelist>
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
833 initializers:
834
835 <programlisting>
836 typedef struct {
837   GObjectClass parent_class;
838   gint         static_integer;
839   gchar       *dynamic_string;
840 } TypeAClass;
841 static void
842 type_a_base_class_init (TypeAClass *class)
843 {
844   class->dynamic_string = g_strdup ("some string");
845 }
846 static void
847 type_a_base_class_finalize (TypeAClass *class)
848 {
849   g_free (class->dynamic_string);
850 }
851 static void
852 type_a_class_init (TypeAClass *class)
853 {
854   class->static_integer = 42;
855 }
856
857 typedef struct {
858   TypeAClass   parent_class;
859   gfloat       static_float;
860   GString     *dynamic_gstring;
861 } TypeBClass;
862 static void
863 type_b_base_class_init (TypeBClass *class)
864 {
865   class->dynamic_gstring = g_string_new ("some other string");
866 }
867 static void
868 type_b_base_class_finalize (TypeBClass *class)
869 {
870   g_string_free (class->dynamic_gstring);
871 }
872 static void
873 type_b_class_init (TypeBClass *class)
874 {
875   class->static_float = 3.14159265358979323846;
876 }
877 </programlisting>
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
895 (static_float).
896 Corresponding finalization counter parts to the GBaseInitFunc() functions
897 have to be provided to release allocated resources at class finalization
898 time.
899 </para>
900
901 @g_class:       The #GTypeClass structure to initialize.
902 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
903
904
905 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
906 <para>
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).
914 </para>
915
916 @g_class:       The #GTypeClass structure to finalize.
917 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
918
919
920 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
921 <para>
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.
929 </para>
930
931 @instance:      The instance to initialize.
932 @g_class:       The class of the type the instance is created for.
933
934
935 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
936 <para>
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.
940 </para>
941
942 @g_iface:       The interface structure to initialize.
943 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
944
945
946 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
947 <para>
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.
951 </para>
952
953 @g_iface:       The interface structure to finalize.
954 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
955
956
957 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
958 <para>
959
960 </para>
961
962 @cache_data: 
963 @g_class: 
964 @Returns: 
965
966
967 <!-- ##### ENUM GTypeFlags ##### -->
968 <para>
969 Bit masks used to check or determine characteristics of a type.
970 </para>
971
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: 
975
976 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
977 <para>
978 Bit masks used to check or determine specific characteristics of a
979 fundamental type.
980 </para>
981
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).
986
987 <!-- ##### FUNCTION g_type_register_static ##### -->
988 <para>
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.
994 </para>
995
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.
1001
1002
1003 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1004 <para>
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.
1010 </para>
1011
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.
1017
1018
1019 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1020 <para>
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.
1027 </para>
1028
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.
1035
1036
1037 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1038 <para>
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.
1042 </para>
1043
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.
1048
1049
1050 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1051 <para>
1052 </para>
1053
1054 @instance_type: 
1055 @interface_type: 
1056 @plugin: 
1057
1058
1059 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1060 <para>
1061
1062 </para>
1063
1064 @interface_type: 
1065 @prerequisite_type: 
1066
1067
1068 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1069 <para>
1070 Returns the #GTypePlugin structure for @type or
1071 %NULL if @type does not have a #GTypePlugin structure.
1072 </para>
1073
1074 @type:          The #GType to retrieve the plugin for.
1075 @Returns:       The corresponding plugin if @type is a dynamic type,
1076                 %NULL otherwise.
1077
1078
1079 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1080 <para>
1081 </para>
1082
1083 @instance_type: 
1084 @implementation_type: 
1085 @Returns: 
1086
1087
1088 <!-- ##### FUNCTION g_type_fundamental_next ##### -->
1089 <para>
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.
1094
1095 </para>
1096
1097 @Returns: The nextmost fundamental type ID to be registered,
1098           or 0 if the type system ran out of fundamental type IDs.
1099
1100
1101 <!-- ##### FUNCTION g_type_fundamental ##### -->
1102 <para>
1103 Internal function, used to extract the fundamental type ID portion.
1104 use G_TYPE_FUNDAMENTAL() instead.
1105 </para>
1106
1107 @type_id: valid type ID
1108 @Returns: fundamental type ID
1109
1110
1111 <!-- ##### FUNCTION g_type_create_instance ##### -->
1112 <para>
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.
1125 </para>
1126
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.
1130
1131
1132 <!-- ##### FUNCTION g_type_free_instance ##### -->
1133 <para>
1134 </para>
1135
1136 @instance: 
1137
1138
1139 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1140 <para>
1141
1142 </para>
1143
1144 @cache_data: 
1145 @cache_func: 
1146
1147
1148 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1149 <para>
1150
1151 </para>
1152
1153 @cache_data: 
1154 @cache_func: 
1155
1156
1157 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1158 <para>
1159
1160 </para>
1161
1162 @g_class: 
1163
1164
1165 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1166 <para>
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
1170 @type.</emphasis>
1171 </para>
1172
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.
1176
1177
1178 <!-- ##### MACRO G_TYPE_INVALID ##### -->
1179 <para>
1180
1181 </para>
1182
1183
1184
1185 <!-- ##### MACRO G_TYPE_NONE ##### -->
1186 <para>
1187
1188 </para>
1189
1190
1191
1192 <!-- ##### MACRO G_TYPE_INTERFACE ##### -->
1193 <para>
1194
1195 </para>
1196
1197
1198
1199 <!-- ##### MACRO G_TYPE_CHAR ##### -->
1200 <para>
1201
1202 </para>
1203
1204
1205
1206 <!-- ##### MACRO G_TYPE_UCHAR ##### -->
1207 <para>
1208
1209 </para>
1210
1211
1212
1213 <!-- ##### MACRO G_TYPE_BOOLEAN ##### -->
1214 <para>
1215
1216 </para>
1217
1218
1219
1220 <!-- ##### MACRO G_TYPE_INT ##### -->
1221 <para>
1222
1223 </para>
1224
1225
1226
1227 <!-- ##### MACRO G_TYPE_UINT ##### -->
1228 <para>
1229
1230 </para>
1231
1232
1233
1234 <!-- ##### MACRO G_TYPE_LONG ##### -->
1235 <para>
1236
1237 </para>
1238
1239
1240
1241 <!-- ##### MACRO G_TYPE_ULONG ##### -->
1242 <para>
1243
1244 </para>
1245
1246
1247
1248 <!-- ##### MACRO G_TYPE_INT64 ##### -->
1249 <para>
1250
1251 </para>
1252
1253
1254
1255 <!-- ##### MACRO G_TYPE_UINT64 ##### -->
1256 <para>
1257
1258 </para>
1259
1260
1261
1262 <!-- ##### MACRO G_TYPE_ENUM ##### -->
1263 <para>
1264
1265 </para>
1266
1267
1268
1269 <!-- ##### MACRO G_TYPE_FLAGS ##### -->
1270 <para>
1271
1272 </para>
1273
1274
1275
1276 <!-- ##### MACRO G_TYPE_FLOAT ##### -->
1277 <para>
1278
1279 </para>
1280
1281
1282
1283 <!-- ##### MACRO G_TYPE_DOUBLE ##### -->
1284 <para>
1285
1286 </para>
1287
1288
1289
1290 <!-- ##### MACRO G_TYPE_STRING ##### -->
1291 <para>
1292
1293 </para>
1294
1295
1296
1297 <!-- ##### MACRO G_TYPE_POINTER ##### -->
1298 <para>
1299
1300 </para>
1301
1302
1303
1304 <!-- ##### MACRO G_TYPE_BOXED ##### -->
1305 <para>
1306
1307 </para>
1308
1309
1310
1311 <!-- ##### MACRO G_TYPE_PARAM ##### -->
1312 <para>
1313
1314 </para>
1315
1316
1317
1318 <!-- ##### MACRO G_TYPE_OBJECT ##### -->
1319 <para>
1320
1321 </para>
1322
1323
1324
1325 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_FIRST ##### -->
1326 <para>
1327
1328 </para>
1329
1330
1331
1332 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_LAST ##### -->
1333 <para>
1334
1335 </para>
1336
1337
1338
1339 <!-- ##### MACRO G_TYPE_RESERVED_BSE_FIRST ##### -->
1340 <para>
1341
1342 </para>
1343
1344
1345
1346 <!-- ##### MACRO G_TYPE_RESERVED_BSE_LAST ##### -->
1347 <para>
1348
1349 </para>
1350
1351
1352
1353 <!-- ##### MACRO G_TYPE_RESERVED_USER_FIRST ##### -->
1354 <para>
1355
1356 </para>
1357
1358
1359