more docs.
[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 retrived during runtime through #GTypePlugin
24 and the g_type_plugin_*() API.
25 These registration functions are usually called only once from a 
26 function whose only purpose is to return the type identifier for a 
27 specific class.  Once the type (or class or interface) is registered,
28 it may be instantiated, inherited, or implemented depending on exactly
29 what sort of type it is.
30 There is also a third registration function for registering fundamental
31 types called g_type_register_fundamental() which requires both a #GTypeInfo
32 structure and a GTypeFundamentalInfo structure but it is seldom used
33 since most fundamental types are predefined rather than user-defined.
34 </para>
35
36 <!-- ##### SECTION See_Also ##### -->
37 <para>
38
39 </para>
40
41 <!-- ##### TYPEDEF GType ##### -->
42 <para>
43 A numerical value which represents the unique identifier of a registered
44 type.
45 </para>
46
47
48 <!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
49 <para>
50 Returns #TRUE if @type is a fundamental data type such as #G_TYPE_INT or
51 #G_TYPE_POINTER. Fundamental types are types that serve as fundaments for
52 the derived types, thus they are the roots of distinct inheritance hierarchies.
53 </para>
54
55 @type: A #GType value.
56
57
58 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_MAX ##### -->
59 <para>
60 An integer constant that represents the number of identifiers reserved
61 for types that are assigned at compile-time.
62 </para>
63
64
65
66 <!-- ##### MACRO G_TYPE_DERIVE_ID ##### -->
67 <para>
68
69 </para>
70
71 @ptype: 
72 @branch_seqno: 
73
74
75 <!-- ##### MACRO G_TYPE_BRANCH_SEQNO ##### -->
76 <para>
77
78 </para>
79
80 @type: 
81
82
83 <!-- ##### MACRO G_TYPE_FUNDAMENTAL_LAST ##### -->
84 <para>
85 An integer that currently represents the highest value of all
86 fundamental type identifiers. This is of interest for dynamic
87 introduction of new fundamental types (a
88 <emphasis>rarely</emphasis> needed feature).
89 </para>
90
91
92
93 <!-- ##### MACRO G_TYPE_IS_ABSTRACT ##### -->
94 <para>
95 Returns #TRUE if @type is an abstract type.  An abstract type can not be
96 instantiated and is normally used as an abstract base class for
97 derived classes.
98 </para>
99
100 @type: A #GType value.
101
102
103 <!-- ##### MACRO G_TYPE_IS_DERIVED ##### -->
104 <para>
105 Returns #TRUE if @type is derived (or in object-oriented terminology:
106 inherited) from another type (this holds true for all non-fundamental
107 types).
108 </para>
109
110 @type: A #GType value.
111
112
113 <!-- ##### MACRO G_TYPE_IS_FUNDAMENTAL ##### -->
114 <para>
115 Returns #TRUE if @type is a fundamental type.
116 </para>
117
118 @type: A #GType value.
119
120
121 <!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
122 <para>
123
124 </para>
125
126 @type: A #GType value.
127
128
129 <!-- ##### MACRO G_TYPE_IS_CLASSED ##### -->
130 <para>
131 Returns #TRUE if @type is a classed type.
132 </para>
133
134 @type: A #GType value.
135
136
137 <!-- ##### MACRO G_TYPE_IS_INSTANTIATABLE ##### -->
138 <para>
139 Returns #TRUE if @type can be instantiated.  Instantiation is the
140 process of creating an instance (object) of this type.
141 </para>
142
143 @type: A #GType value.
144
145
146 <!-- ##### MACRO G_TYPE_IS_DERIVABLE ##### -->
147 <para>
148 Returns #TRUE if @type is a derivable type.  A derivable type can
149 be used as the base class of a flat (single-level) class hierarchy.
150 </para>
151
152 @type: A #GType value.
153
154
155 <!-- ##### MACRO G_TYPE_IS_DEEP_DERIVABLE ##### -->
156 <para>
157 Returns #TRUE if @type is a deep derivable type.  A deep derivable type
158 can be used as the base class of a deep (multi-level) class hierarchy.
159 </para>
160
161 @type: A #GType value.
162
163
164 <!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
165 <para>
166 Returns #TRUE if @type is an interface type.
167 Interface types are types that provide pure APIs, the implementation
168 of which is provided by another type (which is then said to conform
169 to the interface).  GLib interfaces are somewhat analogous to Java
170 interfaces and C++ classes containing only pure virtual functions.
171 </para>
172
173 @type: A #GType value.
174
175
176 <!-- ##### ENUM GTypeFundamentals ##### -->
177 <para>
178 The predefined identifiers of the reserved fundamental types.
179 </para>
180
181 @G_TYPE_INVALID:                Usually a return value indicating an error.
182 @G_TYPE_NONE:                   A synonym for the "void" type in C.
183 @G_TYPE_INTERFACE:              Root type of all interface types.
184 @G_TYPE_CHAR:                   Identifier for the built-in type "gchar".
185 @G_TYPE_UCHAR:                  Identifier for the built-in type "guchar".
186 @G_TYPE_BOOLEAN:                Identifier for the built-in type "gboolean".
187 @G_TYPE_INT:                    Identifier for the built-in type "gint".
188 @G_TYPE_UINT:                   Identifier for the built-in type "guint".
189 @G_TYPE_LONG:                   Identifier for the built-in type "glong".
190 @G_TYPE_ULONG:                  Identifier for the built-in type "gulong".
191 @G_TYPE_INT64: 
192 @G_TYPE_UINT64: 
193 @G_TYPE_ENUM:                   Identifier for the "#GEnum" type.
194 @G_TYPE_FLAGS:                  Identifier for the "#GFlags" type.
195 @G_TYPE_FLOAT:                  Identifier for the built-in type "gfloat".
196 @G_TYPE_DOUBLE:                 Identifier for the built-in type "gdouble".
197 @G_TYPE_STRING:                 Identifier for a pointer to a null-terminated string "gchar*".
198 @G_TYPE_POINTER:                Identifier for anonymous pointers "void*".
199 @G_TYPE_BOXED:                  Identifier for the "#GBoxed" type.
200 @G_TYPE_PARAM:                  Identifier for the "#GParam" type.
201 @G_TYPE_OBJECT:                 Identifier for the "#GObject" type.
202 @G_TYPE_RESERVED_BSE_FIRST:     First fundamental type ID reserved for BSE.
203 @G_TYPE_RESERVED_BSE_LAST:      Last fundamental type ID reserved for BSE.
204 @G_TYPE_RESERVED_LAST_FUNDAMENTAL: Last reserved fundamental type ID.
205 @G_TYPE_CLOSURE: 
206 @G_TYPE_VALUE: 
207 @G_TYPE_VALUE_ARRAY: 
208 @G_TYPE_GSTRING: 
209 @G_TYPE_PARAM_CHAR:             Identifier for the "#GParamSpecChar" type.
210 @G_TYPE_PARAM_UCHAR:            Identifier for the "#GParamSpecUChar" type.
211 @G_TYPE_PARAM_BOOLEAN:          Identifier for the "#GParamSpecBoolean" type.
212 @G_TYPE_PARAM_INT:              Identifier for the "#GParamSpecInt" type.
213 @G_TYPE_PARAM_UINT:             Identifier for the "#GParamSpecUInt" type.
214 @G_TYPE_PARAM_LONG:             Identifier for the "#GParamSpecLong" type.
215 @G_TYPE_PARAM_ULONG:            Identifier for the "#GParamSpecULong" type.
216 @G_TYPE_PARAM_INT64: 
217 @G_TYPE_PARAM_UINT64: 
218 @G_TYPE_PARAM_UNICHAR: 
219 @G_TYPE_PARAM_ENUM:             Identifier for the "#GParamSpecEnum" type.
220 @G_TYPE_PARAM_FLAGS:            Identifier for the "#GParamSpecFlags" type.
221 @G_TYPE_PARAM_FLOAT:            Identifier for the "#GParamSpecFloat" type.
222 @G_TYPE_PARAM_DOUBLE:           Identifier for the "#GParamSpecDouble" type.
223 @G_TYPE_PARAM_STRING:           Identifier for the "#GParamSpecString" type.
224 @G_TYPE_PARAM_PARAM:            Identifier for the "#GParamSpecParam" type.
225 @G_TYPE_PARAM_BOXED:            Identifier for the "#GParamSpecBoxed" type.
226 @G_TYPE_PARAM_POINTER:          Identifier for the "#GParamSpecPointer" type.
227 @G_TYPE_PARAM_VALUE_ARRAY:      Identifier for the "#GParamSpecValueArray" type.
228 @G_TYPE_PARAM_OBJECT:           Identifier for the "#GParamSpecObject" type.
229
230 <!-- ##### STRUCT GTypeInterface ##### -->
231 <para>
232 An opaque structure used as the base of all interface types.
233 </para>
234
235
236 <!-- ##### STRUCT GTypeInstance ##### -->
237 <para>
238 An opaque structure used as the base of all type instances.
239 </para>
240
241
242 <!-- ##### STRUCT GTypeInfo ##### -->
243 <para>
244 This structure is used to provide the type system with the information
245 required to initialize and destruct (finalize) a type's class and
246 instances thereof.
247 The initialized structure is passed to the g_type_register_static() function
248 (or is copied into the provided #GTypeInfo structure in the
249 g_type_plugin_complete_type_info()). The type system will perform a deep
250 copy of this structure, so it's memory does not need to be persistent
251 across invocation of g_type_register_static().
252 </para>
253
254 @class_size:     Size of the class structure (required for interface, classed and instantiatable types).
255 @base_init:      Location of the base initialization function (optional).
256 @base_finalize:  Location of the base finalization function (optional).
257 @class_init:     Location of the class initialization function (optional, for classed and instantiatable types only).
258 @class_finalize: Location of the class finalization function (optional).
259 @class_data:     User-supplied data passed to the class init/finalize functions.
260 @instance_size:  Size of the instance (object) structure (required for instantiatable types only).
261 @n_preallocs:    Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
262 @instance_init:  Location of the instance initialization function (optional, for instantiatable types only).
263 @value_table:    A #GTypeValueTable function table for generic handling of GValues of this type (usualy only
264                  useful for fundamental types).
265
266 <!-- ##### STRUCT GTypeFundamentalInfo ##### -->
267 <para>
268 A structure that provides information to the type system which is
269 used specifically for managing fundamental types.  
270 </para>
271
272 @type_flags: 
273
274 <!-- ##### STRUCT GInterfaceInfo ##### -->
275 <para>
276 A structure that provides information to the type system which is
277 used specifically for managing interface types.
278 </para>
279
280 @interface_init:        Location of the function that initializes the interface.
281 @interface_finalize:    Location of the function that finalizes the interface.
282 @interface_data:        Location of user data passed to the @interface_init and
283                         @interface_finalize functions (optional).
284
285 <!-- ##### STRUCT GTypeValueTable ##### -->
286 <para>
287 The #GTypeValueTable provides the functions required by the #GValue implementation,
288 to serve as a container for values of a type.
289 </para>
290
291 @value_init:            Default initialize @values contents by poking values
292                         directly into the value-&gt;data array. The data array of
293                         the #GValue passed into this function was zero-filled
294                         with memset, so no care has to be taken to free any
295                         old contents. E.g. for the implementation of a string
296                         value that may never be NULL, the implementation might
297                         look like:
298 <msgtext><programlisting>
299 {
300   value-&gt;data[0].v_pointer = g_strdup ("");
301 }
302 </programlisting></msgtext>
303 @value_free:            Free any old contents that might be left in the
304                         data array of the passed in @value. No resources may
305                         remain allocated through the #GValue contents after
306                         this function returns. E.g. for our above string type:
307 <msgtext><programlisting>
308 {
309   /* only free strings without a specific flag for static storage */
310   if (!(value-&gt;data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
311     g_free (value-&gt;data[0].v_pointer);
312 }
313 </programlisting></msgtext>
314 @value_copy:            @dest_value is a #GValue with zero-filled data section
315                         and @src_value is a properly setup #GValue of same or
316                         derived type.
317                         The purpose of this function is to copy the contents of
318                         @src_value into @dest_value in a way, that even after
319                         @src_value has been freed, the contents of @dest_value
320                         remain valid. String type example:
321 <msgtext><programlisting>
322 {
323   dest_value-&gt;data[0].v_pointer = g_strdup (src_value-&gt;data[0].v_pointer);
324 }
325 </programlisting></msgtext>
326 @value_peek_pointer:    If the value contents fit into a pointer, such as objects
327                         or strings, return this pointer, so the caller can peek at
328                         the current contents. To extend on our above string example:
329 <msgtext><programlisting>
330 {
331   return value-&gt;data[0].v_pointer;
332 }
333 </programlisting></msgtext>
334 @collect_format:        A string format describing how to collect the contents of
335                         this value, bit-by-bit. Each character in the format represents
336                         an argument to be collected, the characters themselves indicate
337                         the type of the argument. Currently supported arguments are:
338 <msgtext><variablelist>
339   <varlistentry><term></term><listitem><para>
340         'i' - Integers. passed as collect_values[].v_int.
341   </para></listitem></varlistentry>
342   <varlistentry><term></term><listitem><para>
343         'l' - Longs. passed as collect_values[].v_long.
344   </para></listitem></varlistentry>
345   <varlistentry><term></term><listitem><para>
346         'd' - Doubles. passed as collect_values[].v_double.
347   </para></listitem></varlistentry>
348   <varlistentry><term></term><listitem><para>
349         'p' - Pointers. passed as collect_values[].v_pointer.
350   </para></listitem></varlistentry>
351 </variablelist></msgtext>
352                         It should be noted, that for variable argument list construction,
353                         ANSI C promotes every type smaller than an integer to an int, and
354                         floats to doubles. So for collection of short int or char, 'i'
355                         needs to be used, and for collection of floats 'd'.
356 @collect_value:         The collect_value() function is responsible for converting the
357                         values collected from a variable argument list into contents
358                         suitable for storage in a GValue. This function should setup
359                         @value similar to value_init(), e.g. for a string value that
360                         does not allow NULL pointers, it needs to either spew an error,
361                         or do an implicit conversion by storing an empty string.
362                         The @value passed in to this function has a zero-filled data
363                         array, so just like for @value_init it is guaranteed to not
364                         contain any old contents that might need freeing.
365                         @n_collect_values is exactly the string length of @collect_format,
366                         and @collect_values is an array of unions #GTypeCValue with
367                         length @n_collect_values, containing the collected values
368                         according to @collect_format.
369                         @collect_flags is an argument provided as a hint by the caller,
370                         which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
371                         that the collected value contents may be considered "static"
372                         for the duration of the #@value lifetime.
373                         Thus an extra copy of the contents stored in @collect_values is
374                         not required for assignment to @value.
375                         For our above string example, we continue with:
376 <msgtext><programlisting>
377 {
378   if (!collect_values[0].v_pointer)
379     value->data[0].v_pointer = g_strdup ("");
380   else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
381     {
382       value-&gt;data[0].v_pointer = collect_values[0].v_pointer;
383       /* keep a flag for the value_free() implementation to not free this string */
384       value-&gt;data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
385     }
386   else
387     value-&gt;data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
388
389   return NULL;
390 }
391 </programlisting></msgtext>
392                         It should be noted, that it is generally a bad idea to follow the
393                         #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
394                         reentrancy requirements and reference count assertions performed
395                         by the GSignal code, reference counts should always be incremented
396                         for reference counted contents stored in the value-&gt;data array.
397                         To deviate from our string example for a moment, and taking a look
398                         at an exemplary implementation for collect_value() of #GObject:
399 <msgtext><programlisting>
400 {
401   if (collect_values[0].v_pointer)
402     {
403       GObject *object = G_OBJECT (collect_values[0].v_pointer);
404
405       /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
406       value-&gt;data[0].v_pointer = g_object_ref (object);
407       return NULL;
408     }
409   else
410     return g_strdup_printf ("Object passed as invalid NULL pointer");
411 }
412 </programlisting></msgtext>
413                         The reference count for valid objects is always incremented,
414                         regardless of @collect_flags. For invalid objects, the example
415                         returns a newly allocated string without altering @value.
416                         Upon success, collect_value() needs to return NULL, if however
417                         a malicious condition occurred, collect_value() may spew an
418                         error by returning a newly allocated non-NULL string, giving
419                         a suitable description of the error condition.
420                         The calling code makes no assumptions about the @value
421                         contents being valid upon error returns, @value
422                         is simply thrown away without further freeing. As such, it is
423                         a good idea to not allocate #GValue contents, prior to returning
424                         an error, however, collect_values() is not obliged to return
425                         a correctly setup @value for error returns, simply because
426                         any non-NULL return is considered a fatal condition so further
427                         program behaviour is undefined.
428 @lcopy_format:          Format description of the arguments to collect for @lcopy_value,
429                         analogous to @collect_format. Usually, @lcopy_format string consists
430                         only of 'p's to provide lcopy_value() with pointers to storage locations.
431 @lcopy_value:           This function is responsible for storing the @value contents into
432                         arguments passed through a variable argument list which got
433                         collected into @collect_values according to @lcopy_format.
434                         @n_collect_values equals the string length of @lcopy_format,
435                         and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS.
436                         In contrast to collect_value(), lcopy_value() is obliged to
437                         always properly support #G_VALUE_NOCOPY_CONTENTS.
438                         Similar to collect_value() the function may prematurely abort
439                         by returning a newly allocated string describing an error condition.
440                         To complete the string example:
441 <msgtext><programlisting>
442 {
443   gchar **string_p = collect_values[0].v_pointer;
444
445   if (!string_p)
446     return g_strdup_printf ("string location passed as NULL");
447
448   if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
449     *string_p = value-&gt;data[0].v_pointer;
450   else
451     *string_p = g_strdup (value-&gt;data[0].v_pointer);
452
453 }
454 </programlisting></msgtext>
455                         And an exemplary version of lcopy_value() for
456                         reference-counted types:
457 <msgtext><programlisting>
458 {
459   GObject **object_p = collect_values[0].v_pointer;
460
461   if (!object_p)
462     return g_strdup_printf ("object location passed as NULL");
463   if (!value-&gt;data[0].v_pointer)
464     *object_p = NULL;
465   else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) /* always honour */
466     *object_p = value-&gt;data[0].v_pointer;
467   else
468     *object_p = g_object_ref (value-&gt;data[0].v_pointer);
469   return NULL;
470 }
471 </programlisting></msgtext>
472
473 <!-- ##### MACRO G_TYPE_FROM_INSTANCE ##### -->
474 <para>
475 Returns the type identifier from a given @instance structure.
476 </para>
477
478 @instance: Location of a valid #GTypeInstance structure.
479
480
481 <!-- ##### MACRO G_TYPE_FROM_CLASS ##### -->
482 <para>
483 Returns the type identifier from a given @class structure.
484 </para>
485
486 @g_class: Location of a valid #GTypeClass structure.
487
488
489 <!-- ##### MACRO G_TYPE_FROM_INTERFACE ##### -->
490 <para>
491 Returns the type identifier from a given @interface structure.
492 </para>
493
494 @g_iface: Location of a valid #GTypeInterface structure.
495
496
497 <!-- ##### MACRO G_TYPE_INSTANCE_GET_CLASS ##### -->
498 <para>
499 Returns the class structure of a given @instance, casted
500 to a specified anchestor type @g_type of the instance.
501 </para>
502
503 @instance:      Location of the #GTypeInstance structure.
504 @g_type:        The anchestor type of the class to be returned.
505 @c_type:        The corresponding C type of @g_Type.
506
507
508 <!-- ##### MACRO G_TYPE_INSTANCE_GET_INTERFACE ##### -->
509 <para>
510
511 </para>
512
513 @instance: 
514 @g_type: 
515 @c_type: 
516
517
518 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE ##### -->
519 <para>
520
521 </para>
522
523 @instance: 
524
525
526 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_CAST ##### -->
527 <para>
528
529 </para>
530
531 @instance: 
532 @g_type: 
533 @c_type: 
534
535
536 <!-- ##### MACRO G_TYPE_CHECK_INSTANCE_TYPE ##### -->
537 <para>
538
539 </para>
540
541 @instance: 
542 @g_type: 
543
544
545 <!-- ##### MACRO G_TYPE_CHECK_CLASS_CAST ##### -->
546 <para>
547
548 </para>
549
550 @g_class: 
551 @g_type: 
552 @c_type: 
553
554
555 <!-- ##### MACRO G_TYPE_CHECK_CLASS_TYPE ##### -->
556 <para>
557
558 </para>
559
560 @g_class: 
561 @g_type: 
562
563
564 <!-- ##### MACRO G_TYPE_CHECK_VALUE ##### -->
565 <para>
566
567 </para>
568
569 @value: 
570
571
572 <!-- ##### MACRO G_TYPE_CHECK_VALUE_TYPE ##### -->
573 <para>
574
575 </para>
576
577 @value: 
578 @g_type: 
579
580
581 <!-- ##### MACRO G_TYPE_FLAG_RESERVED_ID_BIT ##### -->
582 <para>
583
584 </para>
585
586
587
588 <!-- ##### FUNCTION g_type_init ##### -->
589 <para>
590 Prior to any use of the type system, g_type_init() has to be called to initialize
591 the type system and assorted other code portions (such as the various fundamental
592 type implementations or the signal system).
593 </para>
594
595 <!-- # Unused Parameters # -->
596 @debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes.
597
598
599 <!-- ##### FUNCTION g_type_init_with_debug_flags ##### -->
600 <para>
601
602 </para>
603
604 @debug_flags: 
605
606
607 <!-- ##### FUNCTION g_type_name ##### -->
608 <para>
609 Return the unique name that is assigned to a type ID (this is the preferred method
610 to find out whether a specific type has been registered for the passed in ID yet).
611 </para>
612
613 @type:          Type to return name for.
614 @Returns:       Static type name or NULL.
615
616
617 <!-- ##### FUNCTION g_type_qname ##### -->
618 <para>
619 Return the corresponding quark of the type IDs name.
620 </para>
621
622 @type:    Type to return quark of type name for.
623 @Returns: The type names quark or 0.
624
625
626 <!-- ##### FUNCTION g_type_from_name ##### -->
627 <para>
628 Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
629 (this is the preferred method to find out by name whether a specific type has been registered yet).
630 </para>
631
632 @name:    Type name to lookup.
633 @Returns: Corresponding type ID or 0.
634
635
636 <!-- ##### FUNCTION g_type_parent ##### -->
637 <para>
638 Return the direct parent type of the passed in type.
639 If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
640 </para>
641
642 @type:    The derived type.
643 @Returns: The parent type.
644
645
646 <!-- ##### FUNCTION g_type_depth ##### -->
647 <para>
648
649 </para>
650
651 @type: 
652 @Returns: 
653
654
655 <!-- ##### FUNCTION g_type_next_base ##### -->
656 <para>
657 Given a @leaf_type and a @root_type which is contained in its anchestry, return
658 the type that @root_type is the immediate parent of.
659 In other words, this function determines the type that is derived directly from
660 @root_type which is also a base class of @leaf_type.  Given a root type and a
661 leaf type, this function can be used to determine the types and order in which
662 the leaf type is descended from the root type.
663 </para>
664
665 @leaf_type:     Descendant of @root_type and the type to be returned.
666 @root_type:     Immediate parent of the returned type.
667 @Returns:       Immediate child of @root_type and anchestor of @leaf_type.
668
669
670 <!-- ##### FUNCTION g_type_is_a ##### -->
671 <para>
672 Check whether @type is a descendant of @is_a_type.
673 </para>
674
675 @type:      Type to check anchestry for.
676 @is_a_type: Possible anchestor of @type.
677 @Returns:   %TRUE if @type is_a @is_a_type holds true.
678
679
680 <!-- ##### FUNCTION g_type_fundamental_branch_last ##### -->
681 <para>
682
683 </para>
684
685 @type: 
686 @Returns: 
687
688
689 <!-- ##### FUNCTION g_type_class_ref ##### -->
690 <para>
691 Increments the reference count of the class structure belonging to
692 @type. This function will demand-create the class if it doesn't
693 exist already.
694 </para>
695
696 @type:    Type ID of a classed type.
697 @Returns: The #GTypeClass structure for the given type ID.
698
699
700 <!-- ##### FUNCTION g_type_class_peek ##### -->
701 <para>
702 This function is essentially the same as g_type_class_ref(), except that
703 the classes reference count isn't incremented. Therefore, this function
704 may return NULL if the class of the type passed in does not currently
705 exist (hasn't been referenced before).
706 </para>
707
708 @type:          Type ID of a classed type.
709 @Returns:       The #GTypeClass structure for the given type ID or NULL
710                 if the class does not currently exist.
711
712
713 <!-- ##### FUNCTION g_type_class_unref ##### -->
714 <para>
715 Decrements the reference count of the class structure being passed in.
716 Once the last reference count of a class has been released, classes
717 may be finalized by the type system, so further dereferencing of a
718 class pointer after g_type_class_unref() are invalid.
719 </para>
720
721 @g_class:       The #GTypeClass structure to unreference.
722
723
724 <!-- ##### FUNCTION g_type_class_peek_parent ##### -->
725 <para>
726 This is a convenience function, often needed in class intializers.
727 It essentially takes the immediate parent type of the class passed in,
728 and returns the class structure thereof. Since derived classes hold
729 a reference count on their parent classes as long as they are instantiated,
730 the returned class will always exist. This function is essentially
731 equivalent to:
732
733 <msgtext><programlisting>
734 g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
735 </programlisting></msgtext>
736
737 </para>
738
739 @g_class: The #GTypeClass structure to retrieve the parent class for.
740 @Returns: The parent class of @g_class.
741
742
743 <!-- ##### FUNCTION g_type_interface_peek ##### -->
744 <para>
745
746 </para>
747
748 @instance_class: 
749 @iface_type: 
750 @Returns: 
751
752
753 <!-- ##### FUNCTION g_type_interface_peek_parent ##### -->
754 <para>
755
756 </para>
757
758 @g_iface: 
759 @Returns: 
760
761
762 <!-- ##### FUNCTION g_type_children ##### -->
763 <para>
764 Return a newly allocated and 0 terminated array of type IDs, listing the
765 child types of @type. The return value has to be g_free()ed after use.
766 </para>
767
768 @type:       The parent type.
769 @n_children: Optional #guint pointer to contain the number of child types.
770 @Returns:    Newly allocated and 0 terminated array of child types.
771
772
773 <!-- ##### FUNCTION g_type_interfaces ##### -->
774 <para>
775 Return a newly allocated and 0 terminated array of type IDs, listing the
776 interface types that @type conforms to. The return value has to be
777 g_free()ed after use.
778 </para>
779
780 @type:         The type to list interface types for.
781 @n_interfaces: Optional #guint pointer to contain the number of interface types.
782 @Returns:      Newly allocated and 0 terminated array of interface types.
783
784
785 <!-- ##### FUNCTION g_type_set_qdata ##### -->
786 <para>
787
788 </para>
789
790 @type: 
791 @quark: 
792 @data: 
793
794
795 <!-- ##### FUNCTION g_type_get_qdata ##### -->
796 <para>
797
798 </para>
799
800 @type: 
801 @quark: 
802 @Returns: 
803
804
805 <!-- ##### FUNCTION g_type_query ##### -->
806 <para>
807
808 </para>
809
810 @type: 
811 @query: 
812
813
814 <!-- ##### USER_FUNCTION GBaseInitFunc ##### -->
815 <para>
816 A callback function used by the type system to do base initialization
817 of the class structures of derived types. It is called as part of the
818 initialization process of all derived classes and should reallocate
819 or reset all dynamic class members copied over from the parent class.
820 Therefore class members, e.g. strings, that are not sufficiently
821 handled by a plain memory copy of the parent class into the derived class
822 have to be altered. See GClassInitFunc() for a discussion of the class
823 intialization process.
824 </para>
825
826 @g_class: The #GTypeClass structure to initialize.
827
828
829 <!-- ##### USER_FUNCTION GBaseFinalizeFunc ##### -->
830 <para>
831 A callback function used by the type system to finalize those portions
832 of a derived types class structure that were setup from the corresponding
833 GBaseInitFunc() function. Class finalization basically works the inverse
834 way in which class intialization is performed.
835 See GClassInitFunc() for a discussion of the class intialization process.
836 </para>
837
838 @g_class: The #GTypeClass structure to finalize.
839
840
841 <!-- ##### USER_FUNCTION GClassInitFunc ##### -->
842 <para>
843 A callback function used by the type system to initialize the class
844 of a specific type. This function should initialize all static class
845 members.
846 The initialization process of a class involves:
847 <variablelist>
848   <varlistentry><term></term><listitem><para>
849         1 - Copying common members from the parent class over to the
850         derived class structure.
851   </para></listitem></varlistentry>
852   <varlistentry><term></term><listitem><para>
853         2 -  Zero initialization of the remaining members not copied
854         over from the parent class.
855   </para></listitem></varlistentry>
856   <varlistentry><term></term><listitem><para>
857         3 - Invocation of the GBaseInitFunc initializers of all parent
858         types and the class' type.
859   </para></listitem></varlistentry>
860   <varlistentry><term></term><listitem><para>
861         4 - Invocation of the class' GClassInitFunc initializer.
862   </para></listitem></varlistentry>
863 </variablelist>
864 Since derived classes are partially initialized through a memory copy
865 of the parent class, the general rule is that GBaseInitFunc() and
866 GBaseFinalizeFunc() should take care of necessary reinitialization
867 and release of those class members that were introduced by the type
868 that specified these GBaseInitFunc()/GBaseFinalizeFunc().
869 GClassInitFunc() should only care about intializing static
870 class members, while dynamic class members (such as allocated strings
871 or reference counted resources) are better handled by a GBaseInitFunc()
872 for this type, so proper initialization of the dynamic class members
873 are performed for class intialization of derived types as well.
874 An example may help to correspond the intend of the different class
875 initializers:
876
877 <msgtext><programlisting>
878 typedef struct {
879   GObjectClass parent_class;
880   gint         static_integer;
881   gchar       *dynamic_string;
882 } TypeAClass;
883 static void
884 type_a_base_class_init (TypeAClass *class)
885 {
886   class->dynamic_string = g_strdup ("some string");
887 }
888 static void
889 type_a_base_class_finalize (TypeAClass *class)
890 {
891   g_free (class->dynamic_string);
892 }
893 static void
894 type_a_class_init (TypeAClass *class)
895 {
896   class->static_integer = 42;
897 }
898
899 typedef struct {
900   TypeAClass   parent_class;
901   gfloat       static_float;
902   GString     *dynamic_gstring;
903 } TypeBClass;
904 static void
905 type_b_base_class_init (TypeBClass *class)
906 {
907   class->dynamic_gstring = g_string_new ("some other string);
908 }
909 static void
910 type_b_base_class_finalize (TypeBClass *class)
911 {
912   g_string_free (class->dynamic_gstring);
913 }
914 static void
915 type_b_class_init (TypeBClass *class)
916 {
917   class->static_float = 3.14159265358979323846;
918 }
919 </programlisting></msgtext>
920 Initialization of TypeBClass will first cause initialization of
921 TypeAClass (derived classes reference their parent classes, see
922 g_type_class_ref() on this).
923 Initialization of TypeAClass roughly involves zero-initializing its fields,
924 then calling its GBaseInitFunc() type_a_base_class_init() that allocates
925 its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
926 type_a_class_init() to initialize its static members (static_integer).
927 The first step in the initialization process of TypeBClass is then
928 a plain memory copy of the contents of TypeAClass into TypeBClass and 
929 zero-initialization of the remaining fields in TypeBClass.
930 The dynamic members of TypeAClass within TypeBClass now need
931 reinitialization which is performed by calling type_a_base_class_init()
932 with an argument of TypeBClass.
933 After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
934 is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
935 and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
936 is called to complete the initialization process with the static members
937 (static_float).
938 Corresponding finalization counter parts to the GBaseInitFunc() functions
939 have to be provided to release allocated resources at class finalization
940 time.
941 </para>
942
943 @g_class:       The #GTypeClass structure to initialize.
944 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
945
946
947 <!-- ##### USER_FUNCTION GClassFinalizeFunc ##### -->
948 <para>
949 A callback function used by the type system to finalize a class.
950 This function is rarely needed, as dynamically allocated class resources
951 should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
952 Also, specification of a GClassFinalizeFunc in the #GTypeInfo
953 structure of a static type is invalid, because classes of static types
954 will never be finalized (they are artificially kept alive when their
955 reference count drops to zero).
956 </para>
957
958 @g_class:       The #GTypeClass structure to finalize.
959 @class_data:    The @class_data member supplied via the #GTypeInfo structure.
960
961
962 <!-- ##### USER_FUNCTION GInstanceInitFunc ##### -->
963 <para>
964 A callback function used by the type system to initialize a new
965 instance of a type. This function initializes all instance members and
966 allocates any resources required by it.
967 Initialization of a derived instance involves calling all its parent
968 types instance initializers, therefore the class member of the instance
969 is altered during its initialization to always point to the class that
970 belongs to the type the current initializer was introduced for.
971 </para>
972
973 @instance:      The instance to initialize.
974 @g_class:       The class of the type the instance is created for.
975
976
977 <!-- ##### USER_FUNCTION GInterfaceInitFunc ##### -->
978 <para>
979 A callback function used by the type system to initialize a new
980 interface.  This function should initialize all internal data and
981 allocate any resources required by the interface.
982 </para>
983
984 @g_iface:       The interface structure to initialize.
985 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
986
987
988 <!-- ##### USER_FUNCTION GInterfaceFinalizeFunc ##### -->
989 <para>
990 A callback function used by the type system to finalize an interface.
991 This function should destroy any internal data and release any resources
992 allocated by the corresponding GInterfaceInitFunc() function.
993 </para>
994
995 @g_iface:       The interface structure to finalize.
996 @iface_data:    The @class_data supplied via the #GTypeInfo structure.
997
998
999 <!-- ##### USER_FUNCTION GTypeClassCacheFunc ##### -->
1000 <para>
1001
1002 </para>
1003
1004 @cache_data: 
1005 @g_class: 
1006 @Returns: 
1007
1008
1009 <!-- ##### ENUM GTypeFlags ##### -->
1010 <para>
1011 Bit masks used to check or determine characteristics of a type.
1012 </para>
1013
1014 @G_TYPE_FLAG_ABSTRACT:  Indicates an abstract type. No instances can be
1015                         created for an abstract type.
1016 @G_TYPE_FLAG_VALUE_ABSTRACT: 
1017
1018 <!-- ##### ENUM GTypeFundamentalFlags ##### -->
1019 <para>
1020 Bit masks used to check or determine specific characteristics of a
1021 fundamental type.
1022 </para>
1023
1024 @G_TYPE_FLAG_CLASSED:           Indicates a classed type.
1025 @G_TYPE_FLAG_INSTANTIATABLE:    Indicates an instantiable type (implies classed).
1026 @G_TYPE_FLAG_DERIVABLE:                 Indicates a flat derivable type.
1027 @G_TYPE_FLAG_DEEP_DERIVABLE:    Indicates a deep derivable type (implies derivable).
1028
1029 <!-- ##### FUNCTION g_type_register_static ##### -->
1030 <para>
1031 Registers @type_name as the name of a new static type derived from
1032 @parent_type.  The type system uses the information contained in the
1033 #GTypeInfo structure pointed to by @info to manage the type and its
1034 instances (if not abstract).  The value of @flags determines the nature
1035 (e.g. abstract or not) of the type.
1036 </para>
1037
1038 @parent_type:   Type which this type will be derived from.
1039 @type_name:     Null-terminated string used as the name of the new type.
1040 @info:          The #GTypeInfo structure for this type.
1041 @flags:                 Bitwise combination of #GTypeFlags values.
1042 @Returns:       The new type identifier.
1043
1044
1045 <!-- ##### FUNCTION g_type_register_dynamic ##### -->
1046 <para>
1047 Registers @type_name as the name of a new dynamic type derived from
1048 @parent_type.  The type system uses the information contained in the
1049 #GTypePlugin structure pointed to by @plugin to manage the type and its
1050 instances (if not abstract).  The value of @flags determines the nature
1051 (e.g. abstract or not) of the type.
1052 </para>
1053
1054 @parent_type:   Type which this type will be derived from.
1055 @type_name:     Null-terminated string used as the name of the new type.
1056 @plugin:        The #GTypePlugin structure to retrive the #GTypeInfo from.
1057 @flags:                 Bitwise combination of #GTypeFlags values.
1058 @Returns:       The new type identifier.
1059 <!-- # Unused Parameters # -->
1060 @Returns: #G_TYPE_INVALID if registration failed or the new type identifier.
1061
1062
1063 <!-- ##### FUNCTION g_type_register_fundamental ##### -->
1064 <para>
1065 Registers @type_id as the predefined identifier and @type_name as the
1066 name of a fundamental type.  The type system uses the information
1067 contained in the #GTypeInfo structure pointed to by @info and the 
1068 #GTypeFundamentalInfo structure pointed to by @finfo to manage the
1069 type and its instances.  The value of @flags determines additional
1070 characteristics of the fundamental type.
1071 </para>
1072
1073 @type_id:       A predefined #GTypeFundamentals value.
1074 @type_name:     Null-terminated string used as the name of the new type.
1075 @info:          The #GTypeInfo structure for this type.
1076 @finfo:                 The #GTypeFundamentalInfo structure for this type.
1077 @flags:                 Bitwise combination of #GTypeFlags values.
1078 @Returns:       The predefined type identifier.
1079
1080
1081 <!-- ##### FUNCTION g_type_add_interface_static ##### -->
1082 <para>
1083 Adds the static @interface_type to @instantiable_type.  The information
1084 contained in the #GTypeInterfaceInfo structure pointed to by @info
1085 is used to manage the relationship.
1086 </para>
1087
1088 @instance_type:          #GType value of an instantiable type.
1089 @interface_type: #GType value of an interface type.
1090 @info:           The #GInterfaceInfo structure for this
1091                  (@instance_type, @interface_type) combination.
1092
1093
1094 <!-- ##### FUNCTION g_type_add_interface_dynamic ##### -->
1095 <para>
1096 </para>
1097
1098 @instance_type: 
1099 @interface_type: 
1100 @plugin: 
1101
1102
1103 <!-- ##### FUNCTION g_type_interface_add_prerequisite ##### -->
1104 <para>
1105
1106 </para>
1107
1108 @interface_type: 
1109 @prerequisite_type: 
1110
1111
1112 <!-- ##### FUNCTION g_type_get_plugin ##### -->
1113 <para>
1114 Returns the the #GTypePlugin structure for @type or
1115 #NULL if @type does not have a #GTypePlugin structure.
1116 </para>
1117
1118 @type:          The #GType to retrive the plugin for.
1119 @Returns:       The corresponding plugin if @type is a dynamic type,
1120                 NULL otherwise.
1121
1122
1123 <!-- ##### FUNCTION g_type_interface_get_plugin ##### -->
1124 <para>
1125 </para>
1126
1127 @instance_type: 
1128 @implementation_type: 
1129 @Returns: 
1130
1131
1132 <!-- ##### FUNCTION g_type_fundamental_last ##### -->
1133 <para>
1134 Returns the last fundamental type which is registered plus one,
1135 i.e. the next fundamental type ID that may be registered.
1136 </para>
1137
1138 @Returns: The nextmost not registered fundamental type ID.
1139
1140
1141 <!-- ##### FUNCTION g_type_create_instance ##### -->
1142 <para>
1143 Creates and initializes an instance of @type if @type is valid and can
1144 be instantiated. The type system only performs basic allocation and
1145 structure setups for instances, actual instance creation should happen
1146 through functions supplied by the types fundamental type implementation.
1147 So use of g_type_create_instance() is reserved for implementators of
1148 fundamental types only. E.g. instances of the #GObject hierarchy
1149 should be created via g_object_new() and <emphasis>never</emphasis>
1150 directly through g_type_create_instance() which doesn't handle
1151 things like singleton objects or object construction.
1152 Note: Do <emphasis>not</emphasis> use this function, unless you're
1153 implementing a fundamental type. Also language bindings should <emphasis>not</emphasis>
1154 use this function but g_object_new() instead.
1155 </para>
1156
1157 @type:    An instantiabtable type to create an instance for.
1158 @Returns: An allocated and initialized instance, subject to further
1159           treatment by the fundamental type implementation.
1160
1161
1162 <!-- ##### FUNCTION g_type_free_instance ##### -->
1163 <para>
1164 </para>
1165
1166 @instance: 
1167
1168
1169 <!-- ##### FUNCTION g_type_add_class_cache_func ##### -->
1170 <para>
1171
1172 </para>
1173
1174 @cache_data: 
1175 @cache_func: 
1176
1177
1178 <!-- ##### FUNCTION g_type_remove_class_cache_func ##### -->
1179 <para>
1180
1181 </para>
1182
1183 @cache_data: 
1184 @cache_func: 
1185
1186
1187 <!-- ##### FUNCTION g_type_class_unref_uncached ##### -->
1188 <para>
1189
1190 </para>
1191
1192 @g_class: 
1193
1194
1195 <!-- ##### FUNCTION g_type_value_table_peek ##### -->
1196 <para>
1197 Returns the location of the #GTypeValueTable associated with @type.
1198 <emphasis>Note, this function should only be used from source code
1199 that implements or has internal knowledge of the implementation of
1200 @type.</emphasis>
1201 </para>
1202
1203 @type:    A #GType value.
1204 @Returns: Location of the #GTypeValueTable associated with @type or
1205           #NULL if there is no #GTypeValueTable associated with @type.
1206
1207