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