Apply patches by Stefan Kost to document naming restrictions. (#167614)
[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 <para>
36 A final word about type names.
37 Such an identifier needs to be at least three characters long. There is no
38 upper length limit. The first character needs to be a letter (a-z or A-Z)
39 or an underscore '_'. Subsequent characters can be letters, numbers or
40 any of '-_+'.
41 </para>
42 <!-- ##### SECTION See_Also ##### -->
43 <para>
44
45 </para>
46
47 <!-- ##### TYPEDEF GType ##### -->
48 <para>
49 A numerical value which represents the unique identifier of a registered
50 type.
51 </para>
52
53
54 <!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
55 <para>
56 Returns the fundamental type which is the ancestor of @type.
57 Fundamental types are types that serve as fundaments for the derived types, 
58 thus they are the roots of distinct inheritance hierarchies.
59 </para>
60
61 @type: A #GType value.
62
63
64 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_MAX ##### -->
65 <para>
66 An integer constant that represents the number of identifiers reserved
67 for types that are assigned at compile-time.
68 </para>
69
70
71
72 <!-- ##### MACRO G_TYPE_MAKE_FUNDAMENTAL ##### -->
73 <para>
74 Returns the type ID for the fundamental type number @x.
75 Use g_type_fundamental_next() instead of this macro to create new fundamental 
76 types.
77 </para>
78
79 @x: the fundamental type number.
80
81
82 <!-- ##### MACRO G_TYPE_IS_ABSTRACT ##### -->
83 <para>
84 Returns %TRUE if @type is an abstract type.  An abstract type can not be
85 instantiated and is normally used as an abstract base class for
86 derived classes.
87 </para>
88
89 @type: A #GType value.
90
91
92 <!-- ##### MACRO G_TYPE_IS_DERIVED ##### -->
93 <para>
94 Returns %TRUE if @type is derived (or in object-oriented terminology:
95 inherited) from another type (this holds true for all non-fundamental
96 types).
97 </para>
98
99 @type: A #GType value.
100
101
102 <!-- ##### MACRO G_TYPE_IS_FUNDAMENTAL ##### -->
103 <para>
104 Returns %TRUE if @type is a fundamental type.
105 </para>
106
107 @type: A #GType value.
108
109
110 <!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
111 <para>
112 Returns %TRUE if @type is a value type which can be used for
113 g_value_init(). 
114 </para>
115
116 @type: A #GType value.
117
118
119 <!-- ##### MACRO G_TYPE_HAS_VALUE_TABLE ##### -->
120 <para>
121 Returns %TRUE if @type has a #GTypeValueTable.
122 </para>
123
124 @type: A #GType value.
125
126
127 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
128 <para>
129 Returns %TRUE if @type is a classed type.
130 </para>
131
132 @type: A #GType value.
133
134
135 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
136 <para>
137 Returns %TRUE if @type can be instantiated.  Instantiation is the
138 process of creating an instance (object) of this type.
139 </para>
140
141 @type: A #GType value.
142
143
144 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
145 <para>
146 Returns %TRUE if @type is a derivable type.  A derivable type can
147 be used as the base class of a flat (single-level) class hierarchy.
148 </para>
149
150 @type: A #GType value.
151
152
153 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
154 <para>
155 Returns %TRUE if @type is a deep derivable type.  A deep derivable type
156 can be used as the base class of a deep (multi-level) class hierarchy.
157 </para>
158
159 @type: A #GType value.
160
161
162 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
163 <para>
164 Returns %TRUE if @type is an interface type.
165 Interface types are types that provide pure APIs, the implementation
166 of which is provided by another type (which is then said to conform
167 to the interface).  GLib interfaces are somewhat analogous to Java
168 interfaces and C++ classes containing only pure virtual functions, 
169 with the difference that GType interfaces are not derivable (but see
170 g_type_interface_add_prerequisite() for an alternative).
171 </para>
172
173 @type: A #GType value.
174
175
176 <!-- ##### STRUCT GTypeInterface ##### -->
177 <para>
178 An opaque structure used as the base of all interface types.
179 </para>
180
181
182 <!-- ##### STRUCT GTypeInstance ##### -->
183 <para>
184 An opaque structure used as the base of all type instances.
185 </para>
186
187
188 <!-- ##### STRUCT GTypeClass ##### -->
189 <para>
190 An opaque structure used as the base of all classes.
191 </para>
192
193
194 <!-- ##### STRUCT GTypeInfo ##### -->
195 <para>
196 This structure is used to provide the type system with the information
197 required to initialize and destruct (finalize) a type's class and
198 instances thereof.
199 The initialized structure is passed to the g_type_register_static() function
200 (or is copied into the provided #GTypeInfo structure in the
201 g_type_plugin_complete_type_info()). The type system will perform a deep
202 copy of this structure, so it's memory does not need to be persistent
203 across invocation of g_type_register_static().
204 </para>
205
206 @class_size:     Size of the class structure (required for interface, classed and instantiatable types).
207 @base_init:      Location of the base initialization function (optional).
208 @base_finalize:  Location of the base finalization function (optional).
209 @class_init:     Location of the class initialization function for
210   classed and types. Location of the default vtable inititalization
211   function for interface types. (optional) This function is used both
212   to fill in virtual functions in the class or default vtable, and
213   to do type-specific setup such as registering signals and object
214   properties.
215 @class_finalize: Location of the class finalization function for
216   classed and types. Location fo the default vtable finalization
217   function for interface types. (optional)
218 @class_data:     User-supplied data passed to the class init/finalize functions.
219 @instance_size:  Size of the instance (object) structure (required for instantiatable types only).
220 @n_preallocs:    Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
221 @instance_init:  Location of the instance initialization function (optional, for instantiatable types only).
222 @value_table:    A #GTypeValueTable function table for generic handling of GValues of this type (usually only
223                  useful for fundamental types).
224
225 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
226 <para>
227 A structure that provides information to the type system which is
228 used specifically for managing fundamental types.  
229 </para>
230
231 @type_flags: 
232
233 <!-- ##### STRUCT GInterfaceInfo ##### -->
234 <para>
235 A structure that provides information to the type system which is
236 used specifically for managing interface types.
237 </para>
238
239 @interface_init:        Location of the function that initializes the interface.
240 @interface_finalize:    Location of the function that finalizes the interface.
241 @interface_data:        Location of user data passed to the @interface_init and
242                         @interface_finalize functions (optional).
243
244 <!-- ##### STRUCT GTypeValueTable ##### -->
245 <para>
246 The #GTypeValueTable provides the functions required by the #GValue implementation,
247 to serve as a container for values of a type.
248 </para>
249
250 @value_init:            Default initialize @values contents by poking values
251                         directly into the value-&gt;data array. The data array of
252                         the #GValue passed into this function was zero-filled
253                         with <function>memset()</function>, so no care has to
254                         be taken to free any
255                         old contents. E.g. for the implementation of a string
256                         value that may never be %NULL, the implementation might
257                         look like:
258 <programlisting>
259 {
260   value-&gt;data[0].v_pointer = g_strdup ("");
261 }
262 </programlisting>
263 @value_free:            Free any old contents that might be left in the
264                         data array of the passed in @value. No resources may
265                         remain allocated through the #GValue contents after
266                         this function returns. E.g. for our above string type:
267 <programlisting>
268 {
269   /* only free strings without a specific flag for static storage */
270   if (!(value-&gt;data[1].v_uint &amp; G_VALUE_NOCOPY_CONTENTS))
271     g_free (value-&gt;data[0].v_pointer);
272 }
273 </programlisting>
274 @value_copy:            @dest_value is a #GValue with zero-filled data section
275                         and @src_value is a properly setup #GValue of same or
276                         derived type.
277                         The purpose of this function is to copy the contents of
278                         @src_value into @dest_value in a way, that even after
279                         @src_value has been freed, the contents of @dest_value
280                         remain valid. String type example:
281 <programlisting>
282 {
283   dest_value-&gt;data[0].v_pointer = g_strdup (src_value-&gt;data[0].v_pointer);
284 }
285 </programlisting>
286 @value_peek_pointer:    If the value contents fit into a pointer, such as objects
287                         or strings, return this pointer, so the caller can peek at
288                         the current contents. To extend on our above string example:
289 <programlisting>
290 {
291   return value-&gt;data[0].v_pointer;
292 }
293 </programlisting>
294 @collect_format:        A string format describing how to collect the contents of
295                         this value, bit-by-bit. Each character in the format represents
296                         an argument to be collected, the characters themselves indicate
297                         the type of the argument. Currently supported arguments are:
298 <variablelist>
299   <varlistentry><term></term><listitem><para>
300         'i' - Integers. passed as collect_values[].v_int.
301   </para></listitem></varlistentry>
302   <varlistentry><term></term><listitem><para>
303         'l' - Longs. passed as collect_values[].v_long.
304   </para></listitem></varlistentry>
305   <varlistentry><term></term><listitem><para>
306         'd' - Doubles. passed as collect_values[].v_double.
307   </para></listitem></varlistentry>
308   <varlistentry><term></term><listitem><para>
309         'p' - Pointers. passed as collect_values[].v_pointer.
310   </para></listitem></varlistentry>
311 </variablelist>
312                         It should be noted, that for variable argument list construction,
313                         ANSI C promotes every type smaller than an integer to an int, and
314                         floats to doubles. So for collection of short int or char, 'i'
315                         needs to be used, and for collection of floats 'd'.
316 @collect_value:         The collect_value() function is responsible for converting the
317                         values collected from a variable argument list into contents
318                         suitable for storage in a GValue. This function should setup
319                         @value similar to value_init(), e.g. for a string value that
320                         does not allow %NULL pointers, it needs to either spew an error,
321                         or do an implicit conversion by storing an empty string.
322                         The @value passed in to this function has a zero-filled data
323                         array, so just like for value_init() it is guaranteed to not
324                         contain any old contents that might need freeing.
325                         @n_collect_values is exactly the string length of @collect_format,
326                         and @collect_values is an array of unions #GTypeCValue with
327                         length @n_collect_values, containing the collected values
328                         according to @collect_format.
329                         @collect_flags is an argument provided as a hint by the caller,
330                         which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
331                         that the collected value contents may be considered "static"
332                         for the duration of the @value lifetime.
333                         Thus an extra copy of the contents stored in @collect_values is
334                         not required for assignment to @value.
335                         For our above string example, we continue with:
336 <programlisting>
337 {
338   if (!collect_values[0].v_pointer)
339     value->data[0].v_pointer = g_strdup ("");
340   else if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS)
341     {
342       value-&gt;data[0].v_pointer = collect_values[0].v_pointer;
343       /* keep a flag for the value_free() implementation to not free this string */
344       value-&gt;data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
345     }
346   else
347     value-&gt;data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
348
349   return NULL;
350 }
351 </programlisting>
352                         It should be noted, that it is generally a bad idea to follow the
353                         #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
354                         reentrancy requirements and reference count assertions performed
355                         by the #GSignal code, reference counts should always be incremented
356                         for reference counted contents stored in the value-&gt;data array.
357                         To deviate from our string example for a moment, and taking a look
358                         at an exemplary implementation for collect_value() of #GObject:
359 <programlisting>
360 {
361   if (collect_values[0].v_pointer)
362     {
363       GObject *object = G_OBJECT (collect_values[0].v_pointer);
364
365       /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
366       value-&gt;data[0].v_pointer = g_object_ref (object);
367       return NULL;
368     }
369   else
370     return g_strdup_printf ("Object passed as invalid NULL pointer");
371 }
372 </programlisting>
373                         The reference count for valid objects is always incremented,
374                         regardless of @collect_flags. For invalid objects, the example
375                         returns a newly allocated string without altering @value.
376                         Upon success, collect_value() needs to return %NULL, if however
377                         a malicious condition occurred, collect_value() may spew an
378                         error by returning a newly allocated non-%NULL string, giving
379                         a suitable description of the error condition.
380                         The calling code makes no assumptions about the @value
381                         contents being valid upon error returns, @value
382                         is simply thrown away without further freeing. As such, it is
383                         a good idea to not allocate #GValue contents, prior to returning
384                         an error, however, collect_values() is not obliged to return
385                         a correctly setup @value for error returns, simply because
386                         any non-%NULL return is considered a fatal condition so further
387                         program behaviour is undefined.
388 @lcopy_format:          Format description of the arguments to collect for @lcopy_value,
389                         analogous to @collect_format. Usually, @lcopy_format string consists
390                         only of 'p's to provide lcopy_value() with pointers to storage locations.
391 @lcopy_value:           This function is responsible for storing the @value contents into
392                         arguments passed through a variable argument list which got
393                         collected into @collect_values according to @lcopy_format.
394                         @n_collect_values equals the string length of @lcopy_format,
395                         and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS.
396                         In contrast to collect_value(), lcopy_value() is obliged to
397                         always properly support #G_VALUE_NOCOPY_CONTENTS.
398                         Similar to collect_value() the function may prematurely abort
399                         by returning a newly allocated string describing an error condition.
400                         To complete the string example:
401 <programlisting>
402 {
403   gchar **string_p = collect_values[0].v_pointer;
404
405   if (!string_p)
406     return g_strdup_printf ("string location passed as NULL");
407
408   if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS)
409     *string_p = value-&gt;data[0].v_pointer;
410   else
411     *string_p = g_strdup (value-&gt;data[0].v_pointer);
412
413 }
414 </programlisting>
415                         And an exemplary version of lcopy_value() for
416                         reference-counted types:
417 <programlisting>
418 {
419   GObject **object_p = collect_values[0].v_pointer;
420
421   if (!object_p)
422     return g_strdup_printf ("object location passed as NULL");
423   if (!value-&gt;data[0].v_pointer)
424     *object_p = NULL;
425   else if (collect_flags &amp; G_VALUE_NOCOPY_CONTENTS) /* always honour */
426     *object_p = value-&gt;data[0].v_pointer;
427   else
428     *object_p = g_object_ref (value-&gt;data[0].v_pointer);
429   return NULL;
430 }
431 </programlisting>
432
433 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
434 <para>
435 Returns the type identifier from a given @instance structure. 
436 <para>
437 </para>
438 This macro should only be used in type implementations.
439 </para>
440
441 @instance: Location of a valid #GTypeInstance structure.
442
443
444 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
445 <para>
446 Returns the type identifier from a given @class structure.
447 <para>
448 </para>
449 This macro should only be used in type implementations.
450 </para>
451
452 @g_class: Location of a valid #GTypeClass structure.
453
454
455 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
456 <para>
457 Returns the type identifier from a given @interface structure.
458 <para>
459 </para>
460 This macro should only be used in type implementations.
461 </para>
462
463 @g_iface: Location of a valid #GTypeInterface structure.
464
465
466 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
467 <para>
468 Returns the class structure of a given @instance, casted
469 to a specified anchestor type @g_type of the instance.
470 <para>
471 </para>
472 This macro should only be used in type implementations.
473 </para>
474
475 @instance:      Location of the #GTypeInstance structure.
476 @g_type:        The anchestor type of the class to be returned.
477 @c_type:        The corresponding C type of @g_type.
478
479
480 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
481 <para>
482 Returns the interface structure for interface @g_type of a given @instance.
483 <para>
484 </para>
485 This macro should only be used in type implementations.
486 </para>
487
488 @instance: Location of the #GTypeInstance structure.
489 @g_type: The interface type to be returned.
490 @c_type: The corresponding C type of @g_type.
491
492
493 <!-- ##### MACRO G_TYPE_INSTANCE_GET_PRIVATE ##### -->
494 <para>
495 Gets the private structure for a particular type.
496 The private structure must have been registered in the
497 class_init function with g_type_class_add_private().
498 </para>
499 <para>
500 This macro should only be used in type implementations.
501 </para>
502
503 @instance: the instance of a type deriving from @private_type.
504 @g_type: the type identifying which private data to retrieve.
505 @c_type: The C type for the private structure.
506
507
508 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
509 <para>
510 Returns %TRUE if @instance is a valid #GTypeInstance structure,
511 otherwise emits a warning and returns %FALSE.
512 <para>
513 </para>
514 This macro should only be used in type implementations.
515 </para>
516
517 @instance: Location of a #GTypeInstance structure.
518
519
520 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
521 <para>
522 Checks that @instance is an instance of the type identified by @g_type
523 and emits a warning if this is not the case. Returns @instance casted 
524 to a pointer to @c_type.
525 </para>
526 <para>
527 This macro should only be used in type implementations.
528 </para>
529
530 @instance: Location of a #GTypeInstance structure.
531 @g_type: The type to be returned.
532 @c_type: The corresponding C type of @g_type.
533
534
535 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
536 <para>
537 Returns %TRUE if @instance is an instance of the type identified by @g_type.
538 Otherwise emits a warning and returns %FALSE.
539 </para>
540 <para>
541 This macro should only be used in type implementations.
542 </para>
543
544 @instance: Location of a #GTypeInstance structure.
545 @g_type: The type to be checked
546
547
548 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
549 <para>
550 Checks that @g_class is a class structure of the type identified by @g_type
551 and emits a warning if this is not the case. Returns @g_class casted 
552 to a pointer to @c_type.
553 </para>
554 <para>
555 This macro should only be used in type implementations.
556 </para>
557
558 @g_class: Location of a #GTypeClass structure.
559 @g_type: The type to be returned.
560 @c_type: The corresponding C type of class structure of @g_type.
561
562
563 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
564 <para>
565 Returns %TRUE if @g_class is a class structure of the type identified by 
566 @g_type. Otherwise emits a warning and returns %FALSE.
567 </para>
568 <para>
569 This macro should only be used in type implementations.
570 </para>
571
572 @g_class: Location of a #GTypeClass structure.
573 @g_type: The type to be checked.
574
575
576 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
577 <para>
578 Returns %TRUE if @value has been initialized to hold values
579 of a value type.
580 </para>
581 <para>
582 This macro should only be used in type implementations.
583 </para>
584
585 @value: a #GValue
586
587
588 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
589 <para>
590 Returns %TRUE if @value has been initialized to hold values
591 of type @g_type. 
592 </para>
593 <para>
594 This macro should only be used in type implementations.
595 </para>
596
597 @value: a #GValue
598 @g_type: The type to be checked.
599
600
601 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
602 <para>
603 A bit in the type number that's supposed to be left untouched.
604 </para>
605
606
607
608 <!-- ##### FUNCTION g_type_init ##### -->
609 <para>
610 Prior to any use of the type system, g_type_init() has to be called to initialize
611 the type system and assorted other code portions (such as the various fundamental
612 type implementations or the signal system).
613 </para>
614
615
616
617 <!-- ##### ENUM GTypeDebugFlags ##### -->
618 <para>
619 The <type>GTypeDebugFlags</type> enumeration values can be passed to
620 g_type_init_with_debug_flags() to trigger debugging messages during runtime.
621 Note that the messages can also be triggered by setting the
622 <envar>GOBJECT_DEBUG</envar> environment variable to a ':'-separated list of 
623 "objects" and "signals".
624
625 </para>
626
627 @G_TYPE_DEBUG_NONE: Print no messages.
628 @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping.
629 @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions.
630 @G_TYPE_DEBUG_MASK: 
631
632 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
633 <para>
634 Similar to g_type_init(), but additionally sets debug flags.
635 </para>
636
637 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
638
639
640 <!-- ##### FUNCTION g_type_name ##### -->
641 <para>
642 Returns the unique name that is assigned to a type ID (this is the preferred method
643 to find out whether a specific type has been registered for the passed in ID yet).
644 </para>
645
646 @type:          Type to return name for.
647 @Returns:       Static type name or %NULL.
648
649
650 <!-- ##### FUNCTION g_type_qname ##### -->
651 <para>
652 Return the corresponding quark of the type IDs name.
653 </para>
654
655 @type:    Type to return quark of type name for.
656 @Returns: The type names quark or 0.
657
658
659 <!-- ##### FUNCTION g_type_from_name ##### -->
660 <para>
661 Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
662 (this is the preferred method to find out by name whether a specific type has been registered yet).
663 </para>
664
665 @name:    Type name to lookup.
666 @Returns: Corresponding type ID or 0.
667
668
669 <!-- ##### FUNCTION g_type_parent ##### -->
670 <para>
671 Return the direct parent type of the passed in type.
672 If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
673 </para>
674
675 @type:    The derived type.
676 @Returns: The parent type.
677
678
679 <!-- ##### FUNCTION g_type_depth ##### -->
680 <para>
681 Returns the length of the ancestry of the passed in type. This includes the
682 type itself, so that e.g. a fundamental type has depth 1.
683 </para>
684
685 @type:    A #GType value.
686 @Returns: The depth of @type.
687
688
689 <!-- ##### FUNCTION g_type_next_base ##### -->
690 <para>
691 Given a @leaf_type and a @root_type which is contained in its anchestry, return
692 the type that @root_type is the immediate parent of.
693 In other words, this function determines the type that is derived directly from
694 @root_type which is also a base class of @leaf_type.  Given a root type and a
695 leaf type, this function can be used to determine the types and order in which
696 the leaf type is descended from the root type.
697 </para>
698
699 @leaf_type:     Descendant of @root_type and the type to be returned.
700 @root_type:     Immediate parent of the returned type.
701 @Returns:       Immediate child of @root_type and anchestor of @leaf_type.
702
703
704 <!-- ##### FUNCTION g_type_is_a ##### -->
705 <para>
706 If @is_a_type is a derivable type, check whether @type is a descendant of @is_a_type.
707 If @is_a_type is an interface, check whether @type conforms to it.
708 </para>
709
710 @type:      Type to check anchestry for.
711 @is_a_type: Possible anchestor of @type or interface @type could conform to.
712 @Returns:   %TRUE if @type is_a @is_a_type holds true.
713
714
715 <!-- ##### FUNCTION g_type_class_ref ##### -->
716 <para>
717 Increments the reference count of the class structure belonging to
718 @type. This function will demand-create the class if it doesn't
719 exist already.
720 </para>
721
722 @type:    Type ID of a classed type.
723 @Returns: The #GTypeClass structure for the given type ID.
724
725
726 <!-- ##### FUNCTION g_type_class_peek ##### -->
727 <para>
728 This function is essentially the same as g_type_class_ref(), except that
729 the classes reference count isn't incremented. Therefore, this function
730 may return %NULL if the class of the type passed in does not currently
731 exist (hasn't been referenced before).
732 </para>
733
734 @type:          Type ID of a classed type.
735 @Returns:       The #GTypeClass structure for the given type ID or %NULL
736                 if the class does not currently exist.
737
738
739 <!-- ##### FUNCTION g_type_class_peek_static ##### -->
740 <para>
741 A more efficient version of g_type_class_peek() which works only for
742 static types.
743 </para>
744
745 @type: Type ID of a classed type.
746 @Returns: The #GTypeClass structure for the given type ID or %NULL
747    if the class does not currently exist or is dynamically loaded.
748 @Since: 2.4
749
750
751 <!-- ##### FUNCTION g_type_class_unref ##### -->
752 <para>
753 Decrements the reference count of the class structure being passed in.
754 Once the last reference count of a class has been released, classes
755 may be finalized by the type system, so further dereferencing of a
756 class pointer after g_type_class_unref() are invalid.
757 </para>
758
759 @g_class:       The #GTypeClass structure to unreference.
760
761
762 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
763 <para>
764 This is a convenience function, often needed in class initializers.
765 It essentially takes the immediate parent type of the class passed in,
766 and returns the class structure thereof. Since derived classes hold
767 a reference count on their parent classes as long as they are instantiated,
768 the returned class will always exist. This function is essentially
769 equivalent to:
770
771 <programlisting>
772 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
773 </programlisting>
774
775 </para>
776
777 @g_class: The #GTypeClass structure to retrieve the parent class for.
778 @Returns: The parent class of @g_class.
779
780
781 <!-- ##### FUNCTION g_type_class_add_private ##### -->
782 <para>
783 Registers a private structure for a instantiatable type;
784 when an object is allocated, the private structures for
785 the type and and all of its parent types are allocated
786 sequentially in the same memory block as the public
787 structures. This function should be called in the
788 type's class_init() function. The private structure can
789 be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro.
790 The following example shows attaching a private structure
791 <structname>MyObjectPrivate</structname> to an object
792 <structname>MyObject</structname> defined in the standard GObject
793 fashion.
794 </para>
795 <programlisting>
796 typedef struct _MyObjectPrivate MyObjectPrivate;
797
798 struct _MyObjectPrivate {
799   int some_field;
800 };
801
802 &num;define MY_OBJECT_GET_PRIVATE(o)  \
803    (G_TYPE_INSTANCE_GET_PRIVATE ((o), MY_TYPE_OBJECT, MyObjectPrivate))
804
805 static void
806 my_object_class_init (MyObjectClass *klass)
807 {
808   g_type_class_add_private (klass, sizeof (MyObjectPrivate));
809 }
810
811 static int
812 my_object_get_some_field (MyObject *my_object)
813 {
814   MyObjectPrivate *priv = MY_OBJECT_GET_PRIVATE (my_object);
815
816   return priv->some_field;
817 }
818 </programlisting>
819
820 @g_class: class structure for an instantiatable type
821 @private_size: size of private structure.
822
823
824 <!-- ##### FUNCTION g_type_interface_peek ##### -->
825 <para>
826 Returns the #GTypeInterface structure of an interface to which the passed in 
827 class conforms.
828 </para>
829
830 @instance_class: A #GTypeClass structure.
831 @iface_type:     An interface ID which this class conforms to.
832 @Returns:        The #GTypeInterface structure of @iface_type, or %NULL if the
833                  class is not instantiated.
834
835
836 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
837 <para>
838 Returns the corresponding #GTypeInterface structure of the parent type
839 of the instance type to which @g_iface belongs. This is useful when 
840 deriving the implementation of an interface from the parent type and 
841 then possibly overriding some methods. 
842 </para>
843
844 @g_iface: A #GTypeInterface structure.
845 @Returns: The corresponding #GTypeInterface structure of the parent type
846    of the instance type to which @g_iface belongs, or %NULL if the parent type
847    doesn't conform to the interface.
848
849
850 <!-- ##### FUNCTION g_type_default_interface_ref ##### -->
851 <para>
852 Increments the reference count for the interface type @g_type,
853 and returns the default interface vtable for the type.
854 </para>
855 <para>  
856 If the type is not currently in use, then the default vtable
857 for the type will be created and initalized by calling
858 the base interface init and default vtable init functions for
859 the type (the @<structfield>base_init</structfield>
860 and <structfield>class_init</structfield> members of #GTypeInfo).
861 Calling g_type_default_interface_ref() is useful when you
862 want to make sure that signals and properties for an interface
863 have been installed.
864 </para>
865
866 @g_type: an interface type
867 @Returns: the default vtable for the interface; call 
868  g_type_default_interface_unref() when you are done using
869  the interface.
870 @Since: 2.4
871
872
873 <!-- ##### FUNCTION g_type_default_interface_peek ##### -->
874 <para>
875 If the interface type @g_type is currently in use, returns
876 its default interface vtable.    
877 </para>
878
879 @g_type: an interface type
880 @Returns: the default vtable for the interface; or %NULL
881  if the type is not currently in use.
882 @Since: 2.4
883
884
885 <!-- ##### FUNCTION g_type_default_interface_unref ##### -->
886 <para>
887 Decrements the reference count for the type corresponding to the
888 interface default vtable @g_iface. If the type is dynamic, then
889 when no one is using the interface and all references have
890 been released, the finalize function for the interface's default
891 vtable (the <structfield>class_finalize</structfield> member of
892 #GTypeInfo) will be called.
893 </para>
894
895 @g_iface: the default vtable structure for a interface, as
896   returned by g_type_default_interface_ref()
897 @Since: 2.4
898
899
900 <!-- ##### FUNCTION g_type_children ##### -->
901 <para>
902 Return a newly allocated and 0-terminated array of type IDs, listing the
903 child types of @type. The return value has to be g_free()ed after use.
904 </para>
905
906 @type:       The parent type.
907 @n_children: Optional #guint pointer to contain the number of child types.
908 @Returns:    Newly allocated and 0-terminated array of child types.
909
910
911 <!-- ##### FUNCTION g_type_interfaces ##### -->
912 <para>
913 Return a newly allocated and 0-terminated array of type IDs, listing the
914 interface types that @type conforms to. The return value has to be
915 g_free()ed after use.
916 </para>
917
918 @type:         The type to list interface types for.
919 @n_interfaces: Optional #guint pointer to contain the number of interface types.
920 @Returns:      Newly allocated and 0-terminated array of interface types.
921
922
923 <!-- ##### FUNCTION g_type_interface_prerequisites ##### -->
924 <para>
925 Returns the prerequisites of an interfaces type.
926 </para>
927
928 @interface_type: an interface type
929 @n_prerequisites: location to return the number of prerequisites, or %NULL
930 @Returns: a newly-allocated zero-terminated array of #GType containing 
931    the prerequisites of @interface_type
932 @Since: 2.2
933
934
935 <!-- ##### FUNCTION g_type_set_qdata ##### -->
936 <para>
937 Attaches arbitrary data to a type.
938 </para>
939
940 @type: a #GType
941 @quark: a #GQuark id to identify the data
942 @data: the data
943
944
945 <!-- ##### FUNCTION g_type_get_qdata ##### -->
946 <para>
947 Obtains data which has previously been attached to @type
948 with g_type_set_qdata().
949 </para>
950
951 @type: a #GType
952 @quark: a #GQuark id to identify the data
953 @Returns: the data, or %NULL if no data was found
954
955
956 <!-- ##### FUNCTION g_type_query ##### -->
957 <para>
958 Queries the type system for information about a specific type. 
959 This function will fill in a user-provided structure to hold type-specific 
960 information. If an invalid #GType is passed in, the @type member of the 
961 #GTypeQuery is 0. All members filled into the #GTypeQuery structure should
962 be considered constant and have to be left untouched.
963 </para>
964
965 @type: the #GType value of a static, classed type.
966 @query: A user provided structure that is filled in with constant values 
967         upon success.
968
969
970 <!-- ##### STRUCT GTypeQuery ##### -->
971 <para>
972 A structure holding information for a specific type. It is
973 filled in by the g_type_query() function.
974 </para>
975
976 @type: the #GType value of the type.
977 @type_name: the name of the type.
978 @class_size: the size of the class structure.
979 @instance_size: the size of the instance structure.
980
981 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
982 <para>
983 A callback function used by the type system to do base initialization
984 of the class structures of derived types. It is called as part of the
985 initialization process of all derived classes and should reallocate
986 or reset all dynamic class members copied over from the parent class.
987 Therefore class members, e.g. strings, that are not sufficiently
988 handled by a plain memory copy of the parent class into the derived class
989 have to be altered. See GClassInitFunc() for a discussion of the class
990 intialization process.
991 </para>
992
993 @g_class: The #GTypeClass structure to initialize.
994
995
996 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
997 <para>
998 A callback function used by the type system to finalize those portions
999 of a derived types class structure that were setup from the corresponding
1000 GBaseInitFunc() function. Class finalization basically works the inverse
1001 way in which class intialization is performed.
1002 See GClassInitFunc() for a discussion of the class intialization process.
1003 </para>
1004
1005 @g_class: The #GTypeClass structure to finalize.
1006
1007
1008 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
1009 <para>
1010 A callback function used by the type system to initialize the class
1011 of a specific type. This function should initialize all static class
1012 members.
1013 The initialization process of a class involves:
1014 <variablelist>
1015   <varlistentry><term></term><listitem><para>
1016         1 - Copying common members from the parent class over to the
1017         derived class structure.
1018   </para></listitem></varlistentry>
1019   <varlistentry><term></term><listitem><para>
1020         2 -  Zero initialization of the remaining members not copied
1021         over from the parent class.
1022   </para></listitem></varlistentry>
1023   <varlistentry><term></term><listitem><para>
1024         3 - Invocation of the GBaseInitFunc() initializers of all parent
1025         types and the class' type.
1026   </para></listitem></varlistentry>
1027   <varlistentry><term></term><listitem><para>
1028         4 - Invocation of the class' GClassInitFunc() initializer.
1029   </para></listitem></varlistentry>
1030 </variablelist>
1031 Since derived classes are partially initialized through a memory copy
1032 of the parent class, the general rule is that GBaseInitFunc() and
1033 GBaseFinalizeFunc() should take care of necessary reinitialization
1034 and release of those class members that were introduced by the type
1035 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
1036 GClassInitFunc() should only care about initializing static
1037 class members, while dynamic class members (such as allocated strings
1038 or reference counted resources) are better handled by a GBaseInitFunc()
1039 for this type, so proper initialization of the dynamic class members
1040 is performed for class initialization of derived types as well.
1041 An example may help to correspond the intend of the different class
1042 initializers:
1043
1044 <programlisting>
1045 typedef struct {
1046   GObjectClass parent_class;
1047   gint         static_integer;
1048   gchar       *dynamic_string;
1049 } TypeAClass;
1050 static void
1051 type_a_base_class_init (TypeAClass *class)
1052 {
1053   class->dynamic_string = g_strdup ("some string");
1054 }
1055 static void
1056 type_a_base_class_finalize (TypeAClass *class)
1057 {
1058   g_free (class->dynamic_string);
1059 }
1060 static void
1061 type_a_class_init (TypeAClass *class)
1062 {
1063   class->static_integer = 42;
1064 }
1065
1066 typedef struct {
1067   TypeAClass   parent_class;
1068   gfloat       static_float;
1069   GString     *dynamic_gstring;
1070 } TypeBClass;
1071 static void
1072 type_b_base_class_init (TypeBClass *class)
1073 {
1074   class->dynamic_gstring = g_string_new ("some other string");
1075 }
1076 static void
1077 type_b_base_class_finalize (TypeBClass *class)
1078 {
1079   g_string_free (class->dynamic_gstring);
1080 }
1081 static void
1082 type_b_class_init (TypeBClass *class)
1083 {
1084   class->static_float = 3.14159265358979323846;
1085 }
1086 </programlisting>
1087 Initialization of TypeBClass will first cause initialization of
1088 TypeAClass (derived classes reference their parent classes, see
1089 g_type_class_ref() on this).
1090 Initialization of TypeAClass roughly involves zero-initializing its fields,
1091 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
1092 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
1093 type_a_class_init() to initialize its static members (static_integer).
1094 The first step in the initialization process of TypeBClass is then
1095 a plain memory copy of the contents of TypeAClass into TypeBClass and 
1096 zero-initialization of the remaining fields in TypeBClass.
1097 The dynamic members of TypeAClass within TypeBClass now need
1098 reinitialization which is performed by calling type_a_base_class_init()
1099 with an argument of TypeBClass.
1100 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
1101 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
1102 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
1103 is called to complete the initialization process with the static members
1104 (static_float).
1105 Corresponding finalization counter parts to the GBaseInitFunc() functions
1106 have to be provided to release allocated resources at class finalization
1107 time.
1108 </para>
1109
1110 @g_class:       The #GTypeClass structure to initialize.
1111 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
1112
1113
1114 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
1115 <para>
1116 A callback function used by the type system to finalize a class.
1117 This function is rarely needed, as dynamically allocated class resources
1118 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
1119 Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
1120 structure of a static type is invalid, because classes of static types
1121 will never be finalized (they are artificially kept alive when their
1122 reference count drops to zero).
1123 </para>
1124
1125 @g_class:       The #GTypeClass structure to finalize.
1126 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
1127
1128
1129 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
1130 <para>
1131 A callback function used by the type system to initialize a new
1132 instance of a type. This function initializes all instance members and
1133 allocates any resources required by it.
1134 Initialization of a derived instance involves calling all its parent
1135 types instance initializers, therefore the class member of the instance
1136 is altered during its initialization to always point to the class that
1137 belongs to the type the current initializer was introduced for.
1138 </para>
1139
1140 @instance:      The instance to initialize.
1141 @g_class:       The class of the type the instance is created for.
1142
1143
1144 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
1145 <para>
1146 A callback function used by the type system to initialize a new
1147 interface.  This function should initialize all internal data and
1148 allocate any resources required by the interface.
1149 </para>
1150
1151 @g_iface:       The interface structure to initialize.
1152 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
1153
1154
1155 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
1156 <para>
1157 A callback function used by the type system to finalize an interface.
1158 This function should destroy any internal data and release any resources
1159 allocated by the corresponding GInterfaceInitFunc() function.
1160 </para>
1161
1162 @g_iface:       The interface structure to finalize.
1163 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
1164
1165
1166 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
1167 <para>
1168 A callback function which is called when the reference count of a class 
1169 drops to zero. It may use g_type_class_ref() to prevent the class from
1170 being freed. You should not call g_type_class_unref() from a 
1171 #GTypeClassCacheFunc function to prevent infinite recursion, use 
1172 g_type_class_unref_uncached() instead.
1173 </para>
1174 <para>
1175 The functions have to check the class id passed in to figure 
1176 whether they actually want to cache the class of this type, since all
1177 classes are routed through the same #GTypeClassCacheFunc chain.
1178 </para>
1179
1180 @cache_data: data that was given to the g_type_add_class_cache_func() call
1181 @g_class: The #GTypeClass structure which is unreferenced
1182 @Returns: %TRUE to stop further #GTypeClassCacheFunc<!-- -->s from being 
1183 called, %FALSE to continue.
1184
1185
1186 <!-- ##### ENUM GTypeFlags ##### -->
1187 <para>
1188 Bit masks used to check or determine characteristics of a type.
1189 </para>
1190
1191 @G_TYPE_FLAG_ABSTRACT:  Indicates an abstract type. No instances can be
1192                         created for an abstract type.
1193 @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
1194                         that introduces a value table, but can't be used for
1195                         g_value_init().
1196
1197 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
1198 <para>
1199 Bit masks used to check or determine specific characteristics of a
1200 fundamental type.
1201 </para>
1202
1203 @G_TYPE_FLAG_CLASSED:           Indicates a classed type.
1204 @G_TYPE_FLAG_INSTANTIATABLE:    Indicates an instantiable type (implies classed).
1205 @G_TYPE_FLAG_DERIVABLE:                 Indicates a flat derivable type.
1206 @G_TYPE_FLAG_DEEP_DERIVABLE:    Indicates a deep derivable type (implies derivable).
1207
1208 <!-- ##### FUNCTION g_type_register_static ##### -->
1209 <para>
1210 Registers @type_name as the name of a new static type derived from
1211 @parent_type.  The type system uses the information contained in the
1212 #GTypeInfo structure pointed to by @info to manage the type and its
1213 instances (if not abstract).  The value of @flags determines the nature
1214 (e.g. abstract or not) of the type.
1215 </para>
1216
1217 @parent_type:   Type which this type will be derived from.
1218 @type_name:     0-terminated string used as the name of the new type.
1219 @info:          The #GTypeInfo structure for this type.
1220 @flags:                 Bitwise combination of #GTypeFlags values.
1221 @Returns:       The new type identifier.
1222
1223
1224 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1225 <para>
1226 Registers @type_name as the name of a new dynamic type derived from
1227 @parent_type.  The type system uses the information contained in the
1228 #GTypePlugin structure pointed to by @plugin to manage the type and its
1229 instances (if not abstract).  The value of @flags determines the nature
1230 (e.g. abstract or not) of the type.
1231 </para>
1232
1233 @parent_type:   Type which this type will be derived from.
1234 @type_name:     0-terminated string used as the name of the new type.
1235 @plugin:        The #GTypePlugin structure to retrieve the #GTypeInfo from.
1236 @flags:                 Bitwise combination of #GTypeFlags values.
1237 @Returns:       The new type identifier or #G_TYPE_INVALID if registration failed.
1238
1239
1240 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1241 <para>
1242 Registers @type_id as the predefined identifier and @type_name as the
1243 name of a fundamental type.  The type system uses the information
1244 contained in the #GTypeInfo structure pointed to by @info and the 
1245 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1246 type and its instances.  The value of @flags determines additional
1247 characteristics of the fundamental type.
1248 </para>
1249
1250 @type_id:       A predefined #GTypeFundamentals value.
1251 @type_name:     0-terminated string used as the name of the new type.
1252 @info:          The #GTypeInfo structure for this type.
1253 @finfo:                 The #GTypeFundamentalInfo structure for this type.
1254 @flags:                 Bitwise combination of #GTypeFlags values.
1255 @Returns:       The predefined type identifier.
1256
1257
1258 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1259 <para>
1260 Adds the static @interface_type to @instantiable_type.  The information
1261 contained in the #GTypeInterfaceInfo structure pointed to by @info
1262 is used to manage the relationship.
1263 </para>
1264
1265 @instance_type:          #GType value of an instantiable type.
1266 @interface_type: #GType value of an interface type.
1267 @info:           The #GInterfaceInfo structure for this
1268                  (@instance_type, @interface_type) combination.
1269
1270
1271 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1272 <para>
1273 Adds the dynamic @interface_type to @instantiable_type. The information
1274 contained in the #GTypePlugin structure pointed to by @plugin
1275 is used to manage the relationship.
1276 </para>
1277
1278 @instance_type: the #GType value of an instantiable type.
1279 @interface_type: the #GType value of an interface type.
1280 @plugin: the #GTypePlugin structure to retrieve the #GInterfaceInfo from.
1281
1282
1283 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1284 <para>
1285 Adds @prerequisite_type to the list of prerequisites of @interface_type.
1286 This means that any type implementing @interface_type must also implement
1287 @prerequisite_type. Prerequisites can be thought of as an alternative to
1288 interface derivation (which GType doesn't support). An interface can have
1289 at most one instantiatable prerequisite type.
1290 </para>
1291
1292 @interface_type: #GType value of an interface type.
1293 @prerequisite_type: #GType value of an interface or instantiatable type.
1294
1295
1296 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1297 <para>
1298 Returns the #GTypePlugin structure for @type or
1299 %NULL if @type does not have a #GTypePlugin structure.
1300 </para>
1301
1302 @type:          The #GType to retrieve the plugin for.
1303 @Returns:       The corresponding plugin if @type is a dynamic type,
1304                 %NULL otherwise.
1305
1306
1307 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1308 <para>
1309 Returns the #GTypePlugin structure for the dynamic interface 
1310 @interface_type which has been added to @instance_type, or 
1311 %NULL if @interface_type has not been added to @instance_type or does 
1312 not have a #GTypePlugin structure. See g_type_add_interface_dynamic().
1313 </para>
1314
1315 @instance_type: the #GType value of an instantiatable type.
1316 @interface_type: the #GType value of an interface type.
1317 @Returns: the #GTypePlugin for the dynamic interface @interface_type
1318    of @instance_type.
1319
1320
1321 <!-- ##### FUNCTION g_type_fundamental_next ##### -->
1322 <para>
1323 Returns the next free fundamental type id which can be used to
1324 register a new fundamental type with g_type_register_fundamental().
1325 The returned type ID represents the highest currently registered
1326 fundamental type identifier.
1327
1328 </para>
1329
1330 @Returns: The nextmost fundamental type ID to be registered,
1331           or 0 if the type system ran out of fundamental type IDs.
1332
1333
1334 <!-- ##### FUNCTION g_type_fundamental ##### -->
1335 <para>
1336 Internal function, used to extract the fundamental type ID portion.
1337 use G_TYPE_FUNDAMENTAL() instead.
1338 </para>
1339
1340 @type_id: valid type ID
1341 @Returns: fundamental type ID
1342
1343
1344 <!-- ##### FUNCTION g_type_create_instance ##### -->
1345 <para>
1346 Creates and initializes an instance of @type if @type is valid and can
1347 be instantiated. The type system only performs basic allocation and
1348 structure setups for instances, actual instance creation should happen
1349 through functions supplied by the type's fundamental type implementation.
1350 So use of g_type_create_instance() is reserved for implementators of
1351 fundamental types only. E.g. instances of the #GObject hierarchy
1352 should be created via g_object_new() and <emphasis>never</emphasis>
1353 directly through g_type_create_instance() which doesn't handle
1354 things like singleton objects or object construction.
1355 Note: Do <emphasis>not</emphasis> use this function, unless you're
1356 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1357 use this function but g_object_new() instead.
1358 </para>
1359
1360 @type:    An instantiatable type to create an instance for.
1361 @Returns: An allocated and initialized instance, subject to further
1362           treatment by the fundamental type implementation.
1363
1364
1365 <!-- ##### FUNCTION g_type_free_instance ##### -->
1366 <para>
1367 Frees an instance of a type, returning it to the instance pool for the type,
1368 if there is one.
1369 </para>
1370 <para>
1371 Like g_type_create_instance(), this function is reserved for implementors of 
1372 fundamental types.
1373 </para>
1374
1375 @instance: an instance of a type.
1376
1377
1378 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1379 <para>
1380 Adds a #GTypeClassCacheFunc to be called before the reference count of a class 
1381 goes from one to zero. This can be used to prevent premature class destruction.
1382 All installed #GTypeClassCacheFunc functions will be chained until one of them 
1383 returns %TRUE. The functions have to check the class id passed in to figure 
1384 whether they actually want to cache the class of this type, since all classes
1385 are routed through the same #GTypeClassCacheFunc chain.
1386 </para>
1387
1388 @cache_data: data to be passed to @cache_func
1389 @cache_func: a #GTypeClassCacheFunc
1390
1391
1392 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1393 <para>
1394 Removes a previously installed #GTypeClassCacheFunc. The cache maintained 
1395 by @cache_func has to be empty when calling g_type_remove_class_cache_func() 
1396 to avoid leaks.
1397 </para>
1398
1399 @cache_data: data that was given when adding @cache_func
1400 @cache_func: a #GTypeClassCacheFunc
1401
1402
1403 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1404 <para>
1405 A variant of g_type_class_unref() for use in #GTypeClassCacheFunc
1406 implementations. It unreferences a class without consulting the chain
1407 of #GTypeClassCacheFunc<!-- -->s, avoiding the recursion which would occur
1408 otherwise.
1409 </para>
1410
1411 @g_class: The #GTypeClass structure to unreference.
1412
1413
1414 <!-- ##### FUNCTION g_type_add_interface_check ##### -->
1415 <para>
1416 Adds a function to be called after an interface vtable is
1417 initialized for any class. That is, after the @interface_init
1418 member of #GInterfaceInfo has been called.
1419 </para>
1420 <para>
1421 This function is useful when you want to check an invariant
1422 that depends on the interfaces of a class. For instance,
1423 the implementation of #GObject uses this facility to check
1424 that an object implements all of the properties that are
1425 defined on its interfaces.    
1426 </para>
1427
1428 @check_data: data to pass to @check_func
1429 @check_func: function to be called after each interface
1430    is initialized.
1431 @Since: 2.4
1432
1433
1434 <!-- ##### FUNCTION g_type_remove_interface_check ##### -->
1435 <para>
1436 Removes an interface check function added with
1437 g_type_add_interface_check().
1438 </para>
1439
1440 @check_data: callback data passed to g_type_add_interface_check()
1441 @check_func: callback function passed to g_type_add_interface_check()
1442 @Since: 2.4
1443
1444
1445 <!-- ##### USER_FUNCTION GTypeInterfaceCheckFunc ##### -->
1446 <para>
1447 A callback called after an interface vtable is initialized.
1448 See g_type_add_interface_check().
1449 </para>
1450
1451 @check_data: data passed to g_type_add_interface_check().
1452 @g_iface: the interface that has been initialized
1453 @Since: 2.4
1454
1455
1456 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1457 <para>
1458 Returns the location of the #GTypeValueTable associated with @type.
1459 <emphasis>Note, this function should only be used from source code
1460 that implements or has internal knowledge of the implementation of
1461 @type.</emphasis>
1462 </para>
1463
1464 @type:    A #GType value.
1465 @Returns: Location of the #GTypeValueTable associated with @type or
1466           %NULL if there is no #GTypeValueTable associated with @type.
1467
1468
1469 <!-- ##### MACRO G_DEFINE_TYPE ##### -->
1470 <para>
1471 A convenience macro for type implementations, which declares a 
1472 class initialization function, an instance initialization function (see #GTypeInfo for information about 
1473 these) and a static variable named @t_n<!-- -->_parent_class pointing to the parent class. Furthermore, it defines 
1474 a *_get_type() function. See G_DEFINE_TYPE_EXTENDED() for an example.
1475 </para>
1476
1477 @TN: The name of the new type, in Camel case.
1478 @t_n: The name of the new type, in lowercase, with words 
1479   separated by '_'.
1480 @T_P: The #GType of the parent type.
1481 @Since: 2.4
1482
1483
1484 <!-- ##### MACRO G_DEFINE_TYPE_WITH_CODE ##### -->
1485 <para>
1486 A convenience macro for type implementations.  
1487 Similar to G_DEFINE_TYPE(), but allows to insert custom code into the 
1488 *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
1489 See G_DEFINE_TYPE_EXTENDED() for an example.
1490 </para>
1491
1492 @TN: The name of the new type, in Camel case.
1493 @t_n: The name of the new type in lowercase, with words separated by '_'.
1494 @T_P: The #GType of the parent type.
1495 @_C_: Custom code that gets inserted in the *_get_type() function.
1496 @Since: 2.4
1497
1498
1499 <!-- ##### MACRO G_DEFINE_ABSTRACT_TYPE ##### -->
1500 <para>
1501 A convenience macro for type implementations. 
1502 Similar to G_DEFINE_TYPE(), but defines an abstract type. 
1503 See G_DEFINE_TYPE_EXTENDED() for an example.
1504 </para>
1505
1506 @TN: The name of the new type, in Camel case.
1507 @t_n: The name of the new type, in lowercase, with words 
1508   separated by '_'.
1509 @T_P: The #GType of the parent type.
1510 @Since: 2.4
1511
1512
1513 <!-- ##### MACRO G_DEFINE_ABSTRACT_TYPE_WITH_CODE ##### -->
1514 <para>
1515 A convenience macro for type implementations.
1516 Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and allows to 
1517 insert custom code into the *_get_type() function, e.g. interface implementations 
1518 via G_IMPLEMENT_INTERFACE(). See G_DEFINE_TYPE_EXTENDED() for an example.
1519 </para>
1520
1521 @TN: The name of the new type, in Camel case.
1522 @t_n: The name of the new type, in lowercase, with words 
1523   separated by '_'.
1524 @T_P: The #GType of the parent type.
1525 @_C_: Custom code that gets inserted in the @type_name_get_type() function.
1526 @Since: 2.4
1527
1528
1529 <!-- ##### MACRO G_IMPLEMENT_INTERFACE ##### -->
1530 <para>
1531 A convenience macro to ease interface addition in the @_C_ section
1532 of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). 
1533 See G_DEFINE_TYPE_EXTENDED() for an example.
1534 </para>
1535 <para>
1536 Note that this macro can only be used together with the G_DEFINE_TYPE_*
1537 macros, since it depends on variable names from those macros.
1538 </para>
1539
1540 @TYPE_IFACE: The #GType of the interface to add
1541 @iface_init: The interface init function
1542 @Since: 2.4
1543
1544
1545 <!-- ##### MACRO G_DEFINE_TYPE_EXTENDED ##### -->
1546 <para>
1547 The most general convenience macro for type implementations, on which 
1548 G_DEFINE_TYPE(), etc are based. 
1549 </para>
1550 <informalexample><programlisting>
1551 G_DEFINE_TYPE_EXTENDED (GtkGadget, 
1552                         gtk_gadget, 
1553                         GTK_TYPE_WIDGET,
1554                         0, 
1555                         G_IMPLEMENT_INTERFACE (TYPE_GIZMO, 
1556                                                gtk_gadget_gizmo_init));
1557 </programlisting>
1558 expands to
1559 <programlisting>
1560 static void     gtk_gadget_init       (GtkGadget      *self);
1561 static void     gtk_gadget_class_init (GtkGadgetClass *klass);
1562 static gpointer gtk_gadget_parent_class = NULL;
1563 static void     gtk_gadget_class_intern_init (gpointer klass)
1564 {
1565   gtk_gadget_parent_class = g_type_class_peek_parent (klass);
1566   gtk_gadget_class_init ((GtkGadgetClass*) klass);
1567 }
1568 <!-- -->
1569 GType
1570 gtk_gadget_get_type (void)
1571 {
1572   static GType g_define_type_id = 0; 
1573   if (G_UNLIKELY (g_define_type_id == 0)) 
1574     { 
1575       static const GTypeInfo g_define_type_info = { 
1576         sizeof (GtkGadgetClass), 
1577         (GBaseInitFunc) NULL, 
1578         (GBaseFinalizeFunc) NULL, 
1579         (GClassInitFunc) gtk_gadget_class_intern_init, 
1580         (GClassFinalizeFunc) NULL, 
1581         NULL,   /* class_data */ 
1582         sizeof (GtkGadget), 
1583         0,      /* n_preallocs */ 
1584         (GInstanceInitFunc) gtk_gadget_init, 
1585       }; 
1586       g_define_type_id = g_type_register_static (GTK_TYPE_WIDGET, "GtkGadget", &amp;g_define_type_info, 0); 
1587       {
1588         static const GInterfaceInfo g_implement_interface_info = {
1589           (GInterfaceInitFunc) gtk_gadget_gizmo_init
1590         };
1591         g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &amp;g_implement_interface_info);
1592       } 
1593     } 
1594   return g_define_type_id; 
1595 }
1596 </programlisting>
1597 The only pieces which have to be manually provided are the definitions of the 
1598 instance and class structure and the definitions of the instance and class 
1599 init functions.
1600 </informalexample>
1601
1602 @TypeName: The name of the new type, in Camel case.
1603 @type_name: The name of the new type, in lowercase, with words 
1604   separated by '_'.
1605 @TYPE_PARENT: The #GType of the parent type.
1606 @flags: #GTypeFlags to pass to g_type_register_static()
1607 @CODE: Custom code that gets inserted in the *_get_type() function.
1608 @Since: 2.4
1609
1610
1611 <!-- ##### MACRO G_TYPE_INVALID ##### -->
1612 <para>
1613 An invalid #GType, used as error return value in some functions which return
1614 a #GType. 
1615 </para>
1616
1617
1618
1619 <!-- ##### MACRO G_TYPE_NONE ##### -->
1620 <para>
1621 A fundamental type which is used as a replacement for the C
1622 <literal>void</literal> return type.
1623 </para>
1624
1625
1626
1627 <!-- ##### MACRO G_TYPE_INTERFACE ##### -->
1628 <para>
1629 The fundamental type from which all interfaces are derived.
1630 </para>
1631
1632
1633
1634 <!-- ##### MACRO G_TYPE_CHAR ##### -->
1635 <para>
1636 The fundamental type corresponding to #gchar.
1637 </para>
1638
1639
1640
1641 <!-- ##### MACRO G_TYPE_UCHAR ##### -->
1642 <para>
1643 The fundamental type corresponding to #guchar.
1644 </para>
1645
1646
1647
1648 <!-- ##### MACRO G_TYPE_BOOLEAN ##### -->
1649 <para>
1650 The fundamental type corresponding to #gboolean.
1651 </para>
1652
1653
1654
1655 <!-- ##### MACRO G_TYPE_INT ##### -->
1656 <para>
1657 The fundamental type corresponding to #gint.
1658 </para>
1659
1660
1661
1662 <!-- ##### MACRO G_TYPE_UINT ##### -->
1663 <para>
1664 The fundamental type corresponding to #guint.
1665 </para>
1666
1667
1668
1669 <!-- ##### MACRO G_TYPE_LONG ##### -->
1670 <para>
1671 The fundamental type corresponding to #glong.
1672 </para>
1673
1674
1675
1676 <!-- ##### MACRO G_TYPE_ULONG ##### -->
1677 <para>
1678 The fundamental type corresponding to #gulong.
1679 </para>
1680
1681
1682
1683 <!-- ##### MACRO G_TYPE_INT64 ##### -->
1684 <para>
1685 The fundamental type corresponding to #gint64.
1686 </para>
1687
1688
1689
1690 <!-- ##### MACRO G_TYPE_UINT64 ##### -->
1691 <para>
1692 The fundamental type corresponding to #guint64.
1693 </para>
1694
1695
1696
1697 <!-- ##### MACRO G_TYPE_ENUM ##### -->
1698 <para>
1699 The fundamental type from which all enumeration types are derived.
1700 </para>
1701
1702
1703
1704 <!-- ##### MACRO G_TYPE_FLAGS ##### -->
1705 <para>
1706 The fundamental type from which all flags types are derived.
1707 </para>
1708
1709
1710
1711 <!-- ##### MACRO G_TYPE_FLOAT ##### -->
1712 <para>
1713 The fundamental type corresponding to #gfloat.
1714 </para>
1715
1716
1717
1718 <!-- ##### MACRO G_TYPE_DOUBLE ##### -->
1719 <para>
1720 The fundamental type corresponding to #gdouble.
1721 </para>
1722
1723
1724
1725 <!-- ##### MACRO G_TYPE_STRING ##### -->
1726 <para>
1727 The fundamental type corresponding to nul-terminated C strings.
1728 </para>
1729
1730
1731
1732 <!-- ##### MACRO G_TYPE_POINTER ##### -->
1733 <para>
1734 The fundamental type corresponding to #gpointer.
1735 </para>
1736
1737
1738
1739 <!-- ##### MACRO G_TYPE_BOXED ##### -->
1740 <para>
1741 The fundamental type from which all boxed types are derived.
1742 </para>
1743
1744
1745
1746 <!-- ##### MACRO G_TYPE_PARAM ##### -->
1747 <para>
1748 The fundamental type from which all #GParamSpec types are derived.
1749 </para>
1750
1751
1752
1753 <!-- ##### MACRO G_TYPE_OBJECT ##### -->
1754 <para>
1755 The fundamental type for #GObject.
1756 </para>
1757
1758
1759
1760 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_FIRST ##### -->
1761 <para>
1762 First fundamental type number to create a new fundamental type id with
1763 G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
1764 </para>
1765
1766
1767
1768 <!-- ##### MACRO G_TYPE_RESERVED_GLIB_LAST ##### -->
1769 <para>
1770 Last fundamental type number reserved for GLib.
1771 </para>
1772
1773
1774
1775 <!-- ##### MACRO G_TYPE_RESERVED_BSE_FIRST ##### -->
1776 <para>
1777 First fundamental type number to create a new fundamental type id with
1778 G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
1779 </para>
1780
1781
1782
1783 <!-- ##### MACRO G_TYPE_RESERVED_BSE_LAST ##### -->
1784 <para>
1785 Last fundamental type number reserved for BSE.
1786 </para>
1787
1788
1789
1790 <!-- ##### MACRO G_TYPE_RESERVED_USER_FIRST ##### -->
1791 <para>
1792 First available fundamental type number to create new fundamental 
1793 type id with G_TYPE_MAKE_FUNDAMENTAL().
1794 </para>
1795
1796 <!--
1797 Local variables:
1798 mode: sgml
1799 sgml-parent-document: ("../gobject-docs.sgml" "book" "refsect2" "")
1800 End:
1801 -->
1802
1803
1804