Trivial s/foo/foo_/ fixes to make <glib.h> includable with -Wshadow
[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_interface_prerequisites ##### -->
734 <para>
735
736 </para>
737
738 @interface_type: 
739 @n_prerequisites: 
740 @Returns: 
741
742
743 <!-- ##### FUNCTION g_type_set_qdata ##### -->
744 <para>
745
746 </para>
747
748 @type: 
749 @quark: 
750 @data: 
751
752
753 <!-- ##### FUNCTION g_type_get_qdata ##### -->
754 <para>
755
756 </para>
757
758 @type: 
759 @quark: 
760 @Returns: 
761
762
763 <!-- ##### FUNCTION g_type_query ##### -->
764 <para>
765
766 </para>
767
768 @type: 
769 @query: 
770
771
772 <!-- ##### STRUCT GTypeQuery ##### -->
773 <para>
774
775 </para>
776
777 @type: 
778 @type_name: 
779 @class_size: 
780 @instance_size: 
781
782 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
783 <para>
784 A callback function used by the type system to do base initialization
785 of the class structures of derived types. It is called as part of the
786 initialization process of all derived classes and should reallocate
787 or reset all dynamic class members copied over from the parent class.
788 Therefore class members, e.g. strings, that are not sufficiently
789 handled by a plain memory copy of the parent class into the derived class
790 have to be altered. See GClassInitFunc() for a discussion of the class
791 intialization process.
792 </para>
793
794 @g_class: The #GTypeClass structure to initialize.
795
796
797 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
798 <para>
799 A callback function used by the type system to finalize those portions
800 of a derived types class structure that were setup from the corresponding
801 GBaseInitFunc() function. Class finalization basically works the inverse
802 way in which class intialization is performed.
803 See GClassInitFunc() for a discussion of the class intialization process.
804 </para>
805
806 @g_class: The #GTypeClass structure to finalize.
807
808
809 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
810 <para>
811 A callback function used by the type system to initialize the class
812 of a specific type. This function should initialize all static class
813 members.
814 The initialization process of a class involves:
815 <variablelist>
816   <varlistentry><term></term><listitem><para>
817         1 - Copying common members from the parent class over to the
818         derived class structure.
819   </para></listitem></varlistentry>
820   <varlistentry><term></term><listitem><para>
821         2 -  Zero initialization of the remaining members not copied
822         over from the parent class.
823   </para></listitem></varlistentry>
824   <varlistentry><term></term><listitem><para>
825         3 - Invocation of the GBaseInitFunc() initializers of all parent
826         types and the class' type.
827   </para></listitem></varlistentry>
828   <varlistentry><term></term><listitem><para>
829         4 - Invocation of the class' GClassInitFunc() initializer.
830   </para></listitem></varlistentry>
831 </variablelist>
832 Since derived classes are partially initialized through a memory copy
833 of the parent class, the general rule is that GBaseInitFunc() and
834 GBaseFinalizeFunc() should take care of necessary reinitialization
835 and release of those class members that were introduced by the type
836 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
837 GClassInitFunc() should only care about initializing static
838 class members, while dynamic class members (such as allocated strings
839 or reference counted resources) are better handled by a GBaseInitFunc()
840 for this type, so proper initialization of the dynamic class members
841 is performed for class initialization of derived types as well.
842 An example may help to correspond the intend of the different class
843 initializers:
844
845 <programlisting>
846 typedef struct {
847   GObjectClass parent_class;
848   gint         static_integer;
849   gchar       *dynamic_string;
850 } TypeAClass;
851 static void
852 type_a_base_class_init (TypeAClass *class)
853 {
854   class->dynamic_string = g_strdup ("some string");
855 }
856 static void
857 type_a_base_class_finalize (TypeAClass *class)
858 {
859   g_free (class->dynamic_string);
860 }
861 static void
862 type_a_class_init (TypeAClass *class)
863 {
864   class->static_integer = 42;
865 }
866
867 typedef struct {
868   TypeAClass   parent_class;
869   gfloat       static_float;
870   GString     *dynamic_gstring;
871 } TypeBClass;
872 static void
873 type_b_base_class_init (TypeBClass *class)
874 {
875   class->dynamic_gstring = g_string_new ("some other string");
876 }
877 static void
878 type_b_base_class_finalize (TypeBClass *class)
879 {
880   g_string_free (class->dynamic_gstring);
881 }
882 static void
883 type_b_class_init (TypeBClass *class)
884 {
885   class->static_float = 3.14159265358979323846;
886 }
887 </programlisting>
888 Initialization of TypeBClass will first cause initialization of
889 TypeAClass (derived classes reference their parent classes, see
890 g_type_class_ref() on this).
891 Initialization of TypeAClass roughly involves zero-initializing its fields,
892 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
893 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
894 type_a_class_init() to initialize its static members (static_integer).
895 The first step in the initialization process of TypeBClass is then
896 a plain memory copy of the contents of TypeAClass into TypeBClass and 
897 zero-initialization of the remaining fields in TypeBClass.
898 The dynamic members of TypeAClass within TypeBClass now need
899 reinitialization which is performed by calling type_a_base_class_init()
900 with an argument of TypeBClass.
901 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
902 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
903 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
904 is called to complete the initialization process with the static members
905 (static_float).
906 Corresponding finalization counter parts to the GBaseInitFunc() functions
907 have to be provided to release allocated resources at class finalization
908 time.
909 </para>
910
911 @g_class:       The #GTypeClass structure to initialize.
912 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
913
914
915 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
916 <para>
917 A callback function used by the type system to finalize a class.
918 This function is rarely needed, as dynamically allocated class resources
919 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
920 Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
921 structure of a static type is invalid, because classes of static types
922 will never be finalized (they are artificially kept alive when their
923 reference count drops to zero).
924 </para>
925
926 @g_class:       The #GTypeClass structure to finalize.
927 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
928
929
930 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
931 <para>
932 A callback function used by the type system to initialize a new
933 instance of a type. This function initializes all instance members and
934 allocates any resources required by it.
935 Initialization of a derived instance involves calling all its parent
936 types instance initializers, therefore the class member of the instance
937 is altered during its initialization to always point to the class that
938 belongs to the type the current initializer was introduced for.
939 </para>
940
941 @instance:      The instance to initialize.
942 @g_class:       The class of the type the instance is created for.
943
944
945 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
946 <para>
947 A callback function used by the type system to initialize a new
948 interface.  This function should initialize all internal data and
949 allocate any resources required by the interface.
950 </para>
951
952 @g_iface:       The interface structure to initialize.
953 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
954
955
956 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
957 <para>
958 A callback function used by the type system to finalize an interface.
959 This function should destroy any internal data and release any resources
960 allocated by the corresponding GInterfaceInitFunc() function.
961 </para>
962
963 @g_iface:       The interface structure to finalize.
964 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
965
966
967 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
968 <para>
969
970 </para>
971
972 @cache_data: 
973 @g_class: 
974 @Returns: 
975
976
977 <!-- ##### ENUM GTypeFlags ##### -->
978 <para>
979 Bit masks used to check or determine characteristics of a type.
980 </para>
981
982 @G_TYPE_FLAG_ABSTRACT:  Indicates an abstract type. No instances can be
983                         created for an abstract type.
984 @G_TYPE_FLAG_VALUE_ABSTRACT: 
985
986 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
987 <para>
988 Bit masks used to check or determine specific characteristics of a
989 fundamental type.
990 </para>
991
992 @G_TYPE_FLAG_CLASSED:           Indicates a classed type.
993 @G_TYPE_FLAG_INSTANTIATABLE:    Indicates an instantiable type (implies classed).
994 @G_TYPE_FLAG_DERIVABLE:                 Indicates a flat derivable type.
995 @G_TYPE_FLAG_DEEP_DERIVABLE:    Indicates a deep derivable type (implies derivable).
996
997 <!-- ##### FUNCTION g_type_register_static ##### -->
998 <para>
999 Registers @type_name as the name of a new static type derived from
1000 @parent_type.  The type system uses the information contained in the
1001 #GTypeInfo structure pointed to by @info to manage the type and its
1002 instances (if not abstract).  The value of @flags determines the nature
1003 (e.g. abstract or not) of the type.
1004 </para>
1005
1006 @parent_type:   Type which this type will be derived from.
1007 @type_name:     0-terminated string used as the name of the new type.
1008 @info:          The #GTypeInfo structure for this type.
1009 @flags:                 Bitwise combination of #GTypeFlags values.
1010 @Returns:       The new type identifier.
1011
1012
1013 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1014 <para>
1015 Registers @type_name as the name of a new dynamic type derived from
1016 @parent_type.  The type system uses the information contained in the
1017 #GTypePlugin structure pointed to by @plugin to manage the type and its
1018 instances (if not abstract).  The value of @flags determines the nature
1019 (e.g. abstract or not) of the type.
1020 </para>
1021
1022 @parent_type:   Type which this type will be derived from.
1023 @type_name:     0-terminated string used as the name of the new type.
1024 @plugin:        The #GTypePlugin structure to retrieve the #GTypeInfo from.
1025 @flags:                 Bitwise combination of #GTypeFlags values.
1026 @Returns:       The new type identifier or #G_TYPE_INVALID if registration failed.
1027
1028
1029 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1030 <para>
1031 Registers @type_id as the predefined identifier and @type_name as the
1032 name of a fundamental type.  The type system uses the information
1033 contained in the #GTypeInfo structure pointed to by @info and the 
1034 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1035 type and its instances.  The value of @flags determines additional
1036 characteristics of the fundamental type.
1037 </para>
1038
1039 @type_id:       A predefined #GTypeFundamentals value.
1040 @type_name:     0-terminated string used as the name of the new type.
1041 @info:          The #GTypeInfo structure for this type.
1042 @finfo:                 The #GTypeFundamentalInfo structure for this type.
1043 @flags:                 Bitwise combination of #GTypeFlags values.
1044 @Returns:       The predefined type identifier.
1045
1046
1047 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1048 <para>
1049 Adds the static @interface_type to @instantiable_type.  The information
1050 contained in the #GTypeInterfaceInfo structure pointed to by @info
1051 is used to manage the relationship.
1052 </para>
1053
1054 @instance_type:          #GType value of an instantiable type.
1055 @interface_type: #GType value of an interface type.
1056 @info:           The #GInterfaceInfo structure for this
1057                  (@instance_type, @interface_type) combination.
1058
1059
1060 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1061 <para>
1062 </para>
1063
1064 @instance_type: 
1065 @interface_type: 
1066 @plugin: 
1067
1068
1069 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1070 <para>
1071
1072 </para>
1073
1074 @interface_type: 
1075 @prerequisite_type: 
1076
1077
1078 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1079 <para>
1080 Returns the #GTypePlugin structure for @type or
1081 %NULL if @type does not have a #GTypePlugin structure.
1082 </para>
1083
1084 @type:          The #GType to retrieve the plugin for.
1085 @Returns:       The corresponding plugin if @type is a dynamic type,
1086                 %NULL otherwise.
1087
1088
1089 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1090 <para>
1091 </para>
1092
1093 @instance_type: 
1094 @implementation_type: 
1095 @Returns: 
1096
1097
1098 <!-- ##### FUNCTION g_type_fundamental_next ##### -->
1099 <para>
1100 Returns the next free fundamental type id which can be used to
1101 register a new fundamental type with g_type_register_fundamental().
1102 The returned type ID represents the highest currently registered
1103 fundamental type identifier.
1104
1105 </para>
1106
1107 @Returns: The nextmost fundamental type ID to be registered,
1108           or 0 if the type system ran out of fundamental type IDs.
1109
1110
1111 <!-- ##### FUNCTION g_type_fundamental ##### -->
1112 <para>
1113 Internal function, used to extract the fundamental type ID portion.
1114 use G_TYPE_FUNDAMENTAL() instead.
1115 </para>
1116
1117 @type_id: valid type ID
1118 @Returns: fundamental type ID
1119
1120
1121 <!-- ##### FUNCTION g_type_create_instance ##### -->
1122 <para>
1123 Creates and initializes an instance of @type if @type is valid and can
1124 be instantiated. The type system only performs basic allocation and
1125 structure setups for instances, actual instance creation should happen
1126 through functions supplied by the type's fundamental type implementation.
1127 So use of g_type_create_instance() is reserved for implementators of
1128 fundamental types only. E.g. instances of the #GObject hierarchy
1129 should be created via g_object_new() and <emphasis>never</emphasis>
1130 directly through g_type_create_instance() which doesn't handle
1131 things like singleton objects or object construction.
1132 Note: Do <emphasis>not</emphasis> use this function, unless you're
1133 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1134 use this function but g_object_new() instead.
1135 </para>
1136
1137 @type:    An instantiabtable type to create an instance for.
1138 @Returns: An allocated and initialized instance, subject to further
1139           treatment by the fundamental type implementation.
1140
1141
1142 <!-- ##### FUNCTION g_type_free_instance ##### -->
1143 <para>
1144 </para>
1145
1146 @instance: 
1147
1148
1149 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1150 <para>
1151
1152 </para>
1153
1154 @cache_data: 
1155 @cache_func: 
1156
1157
1158 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1159 <para>
1160
1161 </para>
1162
1163 @cache_data: 
1164 @cache_func: 
1165
1166
1167 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1168 <para>
1169
1170 </para>
1171
1172 @g_class: 
1173
1174
1175 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1176 <para>
1177 Returns the location of the #GTypeValueTable associated with @type.
1178 <emphasis>Note, this function should only be used from source code
1179 that implements or has internal knowledge of the implementation of
1180 @type.</emphasis>
1181 </para>
1182
1183 @type:    A #GType value.
1184 @Returns: Location of the #GTypeValueTable associated with @type or
1185           %NULL if there is no #GTypeValueTable associated with @type.
1186
1187
1188 <!-- ##### MACRO G_TYPE_INVALID ##### -->
1189 <para>
1190
1191 </para>
1192
1193
1194
1195 <!-- ##### MACRO G_TYPE_NONE ##### -->
1196 <para>
1197
1198 </para>
1199
1200
1201
1202 <!-- ##### MACRO G_TYPE_INTERFACE ##### -->
1203 <para>
1204
1205 </para>
1206
1207
1208
1209 <!-- ##### MACRO G_TYPE_CHAR ##### -->
1210 <para>
1211
1212 </para>
1213
1214
1215
1216 <!-- ##### MACRO G_TYPE_UCHAR ##### -->
1217 <para>
1218
1219 </para>
1220
1221
1222
1223 <!-- ##### MACRO G_TYPE_BOOLEAN ##### -->
1224 <para>
1225
1226 </para>
1227
1228
1229
1230 <!-- ##### MACRO G_TYPE_INT ##### -->
1231 <para>
1232
1233 </para>
1234
1235
1236
1237 <!-- ##### MACRO G_TYPE_UINT ##### -->
1238 <para>
1239
1240 </para>
1241
1242
1243
1244 <!-- ##### MACRO G_TYPE_LONG ##### -->
1245 <para>
1246
1247 </para>
1248
1249
1250
1251 <!-- ##### MACRO G_TYPE_ULONG ##### -->
1252 <para>
1253
1254 </para>
1255
1256
1257
1258 <!-- ##### MACRO G_TYPE_INT64 ##### -->
1259 <para>
1260
1261 </para>
1262
1263
1264
1265 <!-- ##### MACRO G_TYPE_UINT64 ##### -->
1266 <para>
1267
1268 </para>
1269
1270
1271
1272 <!-- ##### MACRO G_TYPE_ENUM ##### -->
1273 <para>
1274
1275 </para>
1276
1277
1278
1279 <!-- ##### MACRO G_TYPE_FLAGS ##### -->
1280 <para>
1281
1282 </para>
1283
1284
1285
1286 <!-- ##### MACRO G_TYPE_FLOAT ##### -->
1287 <para>
1288
1289 </para>
1290
1291
1292
1293 <!-- ##### MACRO G_TYPE_DOUBLE ##### -->
1294 <para>
1295
1296 </para>
1297
1298
1299
1300 <!-- ##### MACRO G_TYPE_STRING ##### -->
1301 <para>
1302
1303 </para>
1304
1305
1306
1307 <!-- ##### MACRO G_TYPE_POINTER ##### -->
1308 <para>
1309
1310 </para>
1311
1312
1313
1314 <!-- ##### MACRO G_TYPE_BOXED ##### -->
1315 <para>
1316
1317 </para>
1318
1319
1320
1321 <!-- ##### MACRO G_TYPE_PARAM ##### -->
1322 <para>
1323
1324 </para>
1325
1326
1327
1328 <!-- ##### MACRO G_TYPE_OBJECT ##### -->
1329 <para>
1330
1331 </para>
1332
1333
1334
1335 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_FIRST ##### -->
1336 <para>
1337
1338 </para>
1339
1340
1341
1342 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_LAST ##### -->
1343 <para>
1344
1345 </para>
1346
1347
1348
1349 <!-- ##### MACRO G_TYPE_RESERVED_BSE_FIRST ##### -->
1350 <para>
1351
1352 </para>
1353
1354
1355
1356 <!-- ##### MACRO G_TYPE_RESERVED_BSE_LAST ##### -->
1357 <para>
1358
1359 </para>
1360
1361
1362
1363 <!-- ##### MACRO G_TYPE_RESERVED_USER_FIRST ##### -->
1364 <para>
1365
1366 </para>
1367
1368
1369