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