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