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