1/* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef __G_TYPE_H__
18#define __G_TYPE_H__
19
20#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21#error "Only <glib-object.h> can be included directly."
22#endif
23
24#include <glib.h>
25
26G_BEGIN_DECLS
27
28/* Basic Type Macros
29 */
30/**
31 * G_TYPE_FUNDAMENTAL:
32 * @type: A #GType value.
33 *
34 * The fundamental type which is the ancestor of @type.
35 * Fundamental types are types that serve as ultimate bases for the derived types,
36 * thus they are the roots of distinct inheritance hierarchies.
37 */
38#define G_TYPE_FUNDAMENTAL(type) (g_type_fundamental (type))
39/**
40 * G_TYPE_FUNDAMENTAL_MAX:
41 *
42 * An integer constant that represents the number of identifiers reserved
43 * for types that are assigned at compile-time.
44 */
45#define G_TYPE_FUNDAMENTAL_MAX (255 << G_TYPE_FUNDAMENTAL_SHIFT)
46
47/* Constant fundamental types,
48 */
49/**
50 * G_TYPE_INVALID:
51 *
52 * An invalid #GType used as error return value in some functions which return
53 * a #GType.
54 */
55#define G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL (0)
56/**
57 * G_TYPE_NONE:
58 *
59 * A fundamental type which is used as a replacement for the C
60 * void return type.
61 */
62#define G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL (1)
63/**
64 * G_TYPE_INTERFACE:
65 *
66 * The fundamental type from which all interfaces are derived.
67 */
68#define G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL (2)
69/**
70 * G_TYPE_CHAR:
71 *
72 * The fundamental type corresponding to #gchar.
73 * The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed integer.
74 * This may or may not be the same type a the C type "gchar".
75 */
76#define G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL (3)
77/**
78 * G_TYPE_UCHAR:
79 *
80 * The fundamental type corresponding to #guchar.
81 */
82#define G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL (4)
83/**
84 * G_TYPE_BOOLEAN:
85 *
86 * The fundamental type corresponding to #gboolean.
87 */
88#define G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL (5)
89/**
90 * G_TYPE_INT:
91 *
92 * The fundamental type corresponding to #gint.
93 */
94#define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6)
95/**
96 * G_TYPE_UINT:
97 *
98 * The fundamental type corresponding to #guint.
99 */
100#define G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL (7)
101/**
102 * G_TYPE_LONG:
103 *
104 * The fundamental type corresponding to #glong.
105 */
106#define G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL (8)
107/**
108 * G_TYPE_ULONG:
109 *
110 * The fundamental type corresponding to #gulong.
111 */
112#define G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL (9)
113/**
114 * G_TYPE_INT64:
115 *
116 * The fundamental type corresponding to #gint64.
117 */
118#define G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL (10)
119/**
120 * G_TYPE_UINT64:
121 *
122 * The fundamental type corresponding to #guint64.
123 */
124#define G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL (11)
125/**
126 * G_TYPE_ENUM:
127 *
128 * The fundamental type from which all enumeration types are derived.
129 */
130#define G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL (12)
131/**
132 * G_TYPE_FLAGS:
133 *
134 * The fundamental type from which all flags types are derived.
135 */
136#define G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL (13)
137/**
138 * G_TYPE_FLOAT:
139 *
140 * The fundamental type corresponding to #gfloat.
141 */
142#define G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL (14)
143/**
144 * G_TYPE_DOUBLE:
145 *
146 * The fundamental type corresponding to #gdouble.
147 */
148#define G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL (15)
149/**
150 * G_TYPE_STRING:
151 *
152 * The fundamental type corresponding to nul-terminated C strings.
153 */
154#define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16)
155/**
156 * G_TYPE_POINTER:
157 *
158 * The fundamental type corresponding to #gpointer.
159 */
160#define G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL (17)
161/**
162 * G_TYPE_BOXED:
163 *
164 * The fundamental type from which all boxed types are derived.
165 */
166#define G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL (18)
167/**
168 * G_TYPE_PARAM:
169 *
170 * The fundamental type from which all #GParamSpec types are derived.
171 */
172#define G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL (19)
173/**
174 * G_TYPE_OBJECT:
175 *
176 * The fundamental type for #GObject.
177 */
178#define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20)
179/**
180 * G_TYPE_VARIANT:
181 *
182 * The fundamental type corresponding to #GVariant.
183 *
184 * All floating #GVariant instances passed through the #GType system are
185 * consumed.
186 *
187 * Note that callbacks in closures, and signal handlers
188 * for signals of return type %G_TYPE_VARIANT, must never return floating
189 * variants.
190 *
191 * Note: GLib 2.24 did include a boxed type with this name. It was replaced
192 * with this fundamental type in 2.26.
193 *
194 * Since: 2.26
195 */
196#define G_TYPE_VARIANT G_TYPE_MAKE_FUNDAMENTAL (21)
197
198
199/* Reserved fundamental type numbers to create new fundamental
200 * type IDs with G_TYPE_MAKE_FUNDAMENTAL().
201 * Send email to gtk-devel-list@gnome.org for reservations.
202 */
203/**
204 * G_TYPE_FUNDAMENTAL_SHIFT:
205 *
206 * Shift value used in converting numbers to type IDs.
207 */
208#define G_TYPE_FUNDAMENTAL_SHIFT (2)
209/**
210 * G_TYPE_MAKE_FUNDAMENTAL:
211 * @x: the fundamental type number.
212 *
213 * Get the type ID for the fundamental type number @x.
214 * Use g_type_fundamental_next() instead of this macro to create new fundamental
215 * types.
216 *
217 * Returns: the GType
218 */
219#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
220/**
221 * G_TYPE_RESERVED_GLIB_FIRST:
222 *
223 * First fundamental type number to create a new fundamental type id with
224 * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
225 */
226#define G_TYPE_RESERVED_GLIB_FIRST (22)
227/**
228 * G_TYPE_RESERVED_GLIB_LAST:
229 *
230 * Last fundamental type number reserved for GLib.
231 */
232#define G_TYPE_RESERVED_GLIB_LAST (31)
233/**
234 * G_TYPE_RESERVED_BSE_FIRST:
235 *
236 * First fundamental type number to create a new fundamental type id with
237 * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
238 */
239#define G_TYPE_RESERVED_BSE_FIRST (32)
240/**
241 * G_TYPE_RESERVED_BSE_LAST:
242 *
243 * Last fundamental type number reserved for BSE.
244 */
245#define G_TYPE_RESERVED_BSE_LAST (48)
246/**
247 * G_TYPE_RESERVED_USER_FIRST:
248 *
249 * First available fundamental type number to create new fundamental
250 * type id with G_TYPE_MAKE_FUNDAMENTAL().
251 */
252#define G_TYPE_RESERVED_USER_FIRST (49)
253
254
255/* Type Checking Macros
256 */
257/**
258 * G_TYPE_IS_FUNDAMENTAL:
259 * @type: A #GType value
260 *
261 * Checks if @type is a fundamental type.
262 *
263 * Returns: %TRUE on success
264 */
265#define G_TYPE_IS_FUNDAMENTAL(type) ((type) <= G_TYPE_FUNDAMENTAL_MAX)
266/**
267 * G_TYPE_IS_DERIVED:
268 * @type: A #GType value
269 *
270 * Checks if @type is derived (or in object-oriented terminology:
271 * inherited) from another type (this holds true for all non-fundamental
272 * types).
273 *
274 * Returns: %TRUE on success
275 */
276#define G_TYPE_IS_DERIVED(type) ((type) > G_TYPE_FUNDAMENTAL_MAX)
277/**
278 * G_TYPE_IS_INTERFACE:
279 * @type: A #GType value
280 *
281 * Checks if @type is an interface type.
282 * An interface type provides a pure API, the implementation
283 * of which is provided by another type (which is then said to conform
284 * to the interface). GLib interfaces are somewhat analogous to Java
285 * interfaces and C++ classes containing only pure virtual functions,
286 * with the difference that GType interfaces are not derivable (but see
287 * g_type_interface_add_prerequisite() for an alternative).
288 *
289 * Returns: %TRUE on success
290 */
291#define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
292/**
293 * G_TYPE_IS_CLASSED:
294 * @type: A #GType value
295 *
296 * Checks if @type is a classed type.
297 *
298 * Returns: %TRUE on success
299 */
300#define G_TYPE_IS_CLASSED(type) (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED))
301/**
302 * G_TYPE_IS_INSTANTIATABLE:
303 * @type: A #GType value
304 *
305 * Checks if @type can be instantiated. Instantiation is the
306 * process of creating an instance (object) of this type.
307 *
308 * Returns: %TRUE on success
309 */
310#define G_TYPE_IS_INSTANTIATABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
311/**
312 * G_TYPE_IS_DERIVABLE:
313 * @type: A #GType value
314 *
315 * Checks if @type is a derivable type. A derivable type can
316 * be used as the base class of a flat (single-level) class hierarchy.
317 *
318 * Returns: %TRUE on success
319 */
320#define G_TYPE_IS_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE))
321/**
322 * G_TYPE_IS_DEEP_DERIVABLE:
323 * @type: A #GType value
324 *
325 * Checks if @type is a deep derivable type. A deep derivable type
326 * can be used as the base class of a deep (multi-level) class hierarchy.
327 *
328 * Returns: %TRUE on success
329 */
330#define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
331/**
332 * G_TYPE_IS_ABSTRACT:
333 * @type: A #GType value
334 *
335 * Checks if @type is an abstract type. An abstract type cannot be
336 * instantiated and is normally used as an abstract base class for
337 * derived classes.
338 *
339 * Returns: %TRUE on success
340 */
341#define G_TYPE_IS_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))
342/**
343 * G_TYPE_IS_VALUE_ABSTRACT:
344 * @type: A #GType value
345 *
346 * Checks if @type is an abstract value type. An abstract value type introduces
347 * a value table, but can't be used for g_value_init() and is normally used as
348 * an abstract base type for derived value types.
349 *
350 * Returns: %TRUE on success
351 */
352#define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
353/**
354 * G_TYPE_IS_VALUE_TYPE:
355 * @type: A #GType value
356 *
357 * Checks if @type is a value type and can be used with g_value_init().
358 *
359 * Returns: %TRUE on success
360 */
361#define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type))
362/**
363 * G_TYPE_HAS_VALUE_TABLE:
364 * @type: A #GType value
365 *
366 * Checks if @type has a #GTypeValueTable.
367 *
368 * Returns: %TRUE on success
369 */
370#define G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek (type) != NULL)
371
372
373/* Typedefs
374 */
375/**
376 * GType:
377 *
378 * A numerical value which represents the unique identifier of a registered
379 * type.
380 */
381#if GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus
382typedef gsize GType;
383#else /* for historic reasons, C++ links against gulong GTypes */
384typedef gulong GType;
385#endif
386typedef struct _GValue GValue;
387typedef union _GTypeCValue GTypeCValue;
388typedef struct _GTypePlugin GTypePlugin;
389typedef struct _GTypeClass GTypeClass;
390typedef struct _GTypeInterface GTypeInterface;
391typedef struct _GTypeInstance GTypeInstance;
392typedef struct _GTypeInfo GTypeInfo;
393typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
394typedef struct _GInterfaceInfo GInterfaceInfo;
395typedef struct _GTypeValueTable GTypeValueTable;
396typedef struct _GTypeQuery GTypeQuery;
397
398
399/* Basic Type Structures
400 */
401/**
402 * GTypeClass:
403 *
404 * An opaque structure used as the base of all classes.
405 */
406struct _GTypeClass
407{
408 /*< private >*/
409 GType g_type;
410};
411/**
412 * GTypeInstance:
413 *
414 * An opaque structure used as the base of all type instances.
415 */
416struct _GTypeInstance
417{
418 /*< private >*/
419 GTypeClass *g_class;
420};
421/**
422 * GTypeInterface:
423 *
424 * An opaque structure used as the base of all interface types.
425 */
426struct _GTypeInterface
427{
428 /*< private >*/
429 GType g_type; /* iface type */
430 GType g_instance_type;
431};
432/**
433 * GTypeQuery:
434 * @type: the #GType value of the type
435 * @type_name: the name of the type
436 * @class_size: the size of the class structure
437 * @instance_size: the size of the instance structure
438 *
439 * A structure holding information for a specific type.
440 * It is filled in by the g_type_query() function.
441 */
442struct _GTypeQuery
443{
444 GType type;
445 const gchar *type_name;
446 guint class_size;
447 guint instance_size;
448};
449
450
451/* Casts, checks and accessors for structured types
452 * usage of these macros is reserved to type implementations only
453 */
454/*< protected >*/
455/**
456 * G_TYPE_CHECK_INSTANCE:
457 * @instance: Location of a #GTypeInstance structure
458 *
459 * Checks if @instance is a valid #GTypeInstance structure,
460 * otherwise issues a warning and returns %FALSE.
461 *
462 * This macro should only be used in type implementations.
463 *
464 * Returns: %TRUE on success
465 */
466#define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
467/**
468 * G_TYPE_CHECK_INSTANCE_CAST:
469 * @instance: Location of a #GTypeInstance structure
470 * @g_type: The type to be returned
471 * @c_type: The corresponding C type of @g_type
472 *
473 * Checks that @instance is an instance of the type identified by @g_type
474 * and issues a warning if this is not the case. Returns @instance casted
475 * to a pointer to @c_type.
476 *
477 * This macro should only be used in type implementations.
478 */
479#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
480/**
481 * G_TYPE_CHECK_INSTANCE_TYPE:
482 * @instance: Location of a #GTypeInstance structure.
483 * @g_type: The type to be checked
484 *
485 * Checks if @instance is an instance of the type identified by @g_type.
486 *
487 * This macro should only be used in type implementations.
488 *
489 * Returns: %TRUE on success
490 */
491#define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
492/**
493 * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE:
494 * @instance: Location of a #GTypeInstance structure.
495 * @g_type: The fundamental type to be checked
496 *
497 * Checks if @instance is an instance of the fundamental type identified by @g_type.
498 *
499 * This macro should only be used in type implementations.
500 *
501 * Returns: %TRUE on success
502 */
503#define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type) (_G_TYPE_CIFT ((instance), (g_type)))
504/**
505 * G_TYPE_INSTANCE_GET_CLASS:
506 * @instance: Location of the #GTypeInstance structure
507 * @g_type: The #GType of the class to be returned
508 * @c_type: The C type of the class structure
509 *
510 * Get the class structure of a given @instance, casted
511 * to a specified ancestor type @g_type of the instance.
512 *
513 * Note that while calling a GInstanceInitFunc(), the class pointer
514 * gets modified, so it might not always return the expected pointer.
515 *
516 * This macro should only be used in type implementations.
517 *
518 * Returns: a pointer to the class structure
519 */
520#define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
521/**
522 * G_TYPE_INSTANCE_GET_INTERFACE:
523 * @instance: Location of the #GTypeInstance structure
524 * @g_type: The #GType of the interface to be returned
525 * @c_type: The C type of the interface structure
526 *
527 * Get the interface structure for interface @g_type of a given @instance.
528 *
529 * This macro should only be used in type implementations.
530 *
531 * Returns: a pointer to the interface structure
532 */
533#define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
534/**
535 * G_TYPE_CHECK_CLASS_CAST:
536 * @g_class: Location of a #GTypeClass structure
537 * @g_type: The type to be returned
538 * @c_type: The corresponding C type of class structure of @g_type
539 *
540 * Checks that @g_class is a class structure of the type identified by @g_type
541 * and issues a warning if this is not the case. Returns @g_class casted
542 * to a pointer to @c_type.
543 *
544 * This macro should only be used in type implementations.
545 */
546#define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
547/**
548 * G_TYPE_CHECK_CLASS_TYPE:
549 * @g_class: Location of a #GTypeClass structure
550 * @g_type: The type to be checked
551 *
552 * Checks if @g_class is a class structure of the type identified by
553 * @g_type.
554 *
555 * This macro should only be used in type implementations.
556 *
557 * Returns: %TRUE on success
558 */
559#define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
560/**
561 * G_TYPE_CHECK_VALUE:
562 * @value: a #GValue
563 *
564 * Checks if @value has been initialized to hold values
565 * of a value type.
566 *
567 * This macro should only be used in type implementations.
568 *
569 * Returns: %TRUE on success
570 */
571#define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
572/**
573 * G_TYPE_CHECK_VALUE_TYPE:
574 * @value: a #GValue
575 * @g_type: The type to be checked
576 *
577 * Checks if @value has been initialized to hold values
578 * of type @g_type.
579 *
580 * This macro should only be used in type implementations.
581 *
582 * Returns: %TRUE on success
583 */
584#define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type)))
585/**
586 * G_TYPE_FROM_INSTANCE:
587 * @instance: Location of a valid #GTypeInstance structure
588 *
589 * Get the type identifier from a given @instance structure.
590 *
591 * This macro should only be used in type implementations.
592 *
593 * Returns: the #GType
594 */
595#define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
596/**
597 * G_TYPE_FROM_CLASS:
598 * @g_class: Location of a valid #GTypeClass structure
599 *
600 * Get the type identifier from a given @class structure.
601 *
602 * This macro should only be used in type implementations.
603 *
604 * Returns: the #GType
605 */
606#define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
607/**
608 * G_TYPE_FROM_INTERFACE:
609 * @g_iface: Location of a valid #GTypeInterface structure
610 *
611 * Get the type identifier from a given @interface structure.
612 *
613 * This macro should only be used in type implementations.
614 *
615 * Returns: the #GType
616 */
617#define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
618
619/**
620 * G_TYPE_INSTANCE_GET_PRIVATE:
621 * @instance: the instance of a type deriving from @private_type
622 * @g_type: the type identifying which private data to retrieve
623 * @c_type: The C type for the private structure
624 *
625 * Gets the private structure for a particular type.
626 * The private structure must have been registered in the
627 * class_init function with g_type_class_add_private().
628 *
629 * This macro should only be used in type implementations.
630 *
631 * Since: 2.4
632 * Returns: (not nullable): a pointer to the private data structure
633 */
634#define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type)))
635
636/**
637 * G_TYPE_CLASS_GET_PRIVATE:
638 * @klass: the class of a type deriving from @private_type
639 * @g_type: the type identifying which private data to retrieve
640 * @c_type: The C type for the private structure
641 *
642 * Gets the private class structure for a particular type.
643 * The private structure must have been registered in the
644 * get_type() function with g_type_add_class_private().
645 *
646 * This macro should only be used in type implementations.
647 *
648 * Since: 2.24
649 * Returns: (not nullable): a pointer to the private data structure
650 */
651#define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type)))
652
653/**
654 * GTypeDebugFlags:
655 * @G_TYPE_DEBUG_NONE: Print no messages
656 * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping
657 * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions
658 * @G_TYPE_DEBUG_MASK: Mask covering all debug flags
659 * @G_TYPE_DEBUG_INSTANCE_COUNT: Keep a count of instances of each type
660 *
661 * These flags used to be passed to g_type_init_with_debug_flags() which
662 * is now deprecated.
663 *
664 * If you need to enable debugging features, use the GOBJECT_DEBUG
665 * environment variable.
666 *
667 * Deprecated: 2.36: g_type_init() is now done automatically
668 */
669typedef enum /*< skip >*/
670{
671 G_TYPE_DEBUG_NONE = 0,
672 G_TYPE_DEBUG_OBJECTS = 1 << 0,
673 G_TYPE_DEBUG_SIGNALS = 1 << 1,
674 G_TYPE_DEBUG_INSTANCE_COUNT = 1 << 2,
675 G_TYPE_DEBUG_MASK = 0x07
676} GTypeDebugFlags;
677
678
679/* --- prototypes --- */
680GLIB_DEPRECATED_IN_2_36
681void g_type_init (void);
682GLIB_DEPRECATED_IN_2_36
683void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags);
684GLIB_AVAILABLE_IN_ALL
685const gchar * g_type_name (GType type);
686GLIB_AVAILABLE_IN_ALL
687GQuark g_type_qname (GType type);
688GLIB_AVAILABLE_IN_ALL
689GType g_type_from_name (const gchar *name);
690GLIB_AVAILABLE_IN_ALL
691GType g_type_parent (GType type);
692GLIB_AVAILABLE_IN_ALL
693guint g_type_depth (GType type);
694GLIB_AVAILABLE_IN_ALL
695GType g_type_next_base (GType leaf_type,
696 GType root_type);
697GLIB_AVAILABLE_IN_ALL
698gboolean g_type_is_a (GType type,
699 GType is_a_type);
700GLIB_AVAILABLE_IN_ALL
701gpointer g_type_class_ref (GType type);
702GLIB_AVAILABLE_IN_ALL
703gpointer g_type_class_peek (GType type);
704GLIB_AVAILABLE_IN_ALL
705gpointer g_type_class_peek_static (GType type);
706GLIB_AVAILABLE_IN_ALL
707void g_type_class_unref (gpointer g_class);
708GLIB_AVAILABLE_IN_ALL
709gpointer g_type_class_peek_parent (gpointer g_class);
710GLIB_AVAILABLE_IN_ALL
711gpointer g_type_interface_peek (gpointer instance_class,
712 GType iface_type);
713GLIB_AVAILABLE_IN_ALL
714gpointer g_type_interface_peek_parent (gpointer g_iface);
715
716GLIB_AVAILABLE_IN_ALL
717gpointer g_type_default_interface_ref (GType g_type);
718GLIB_AVAILABLE_IN_ALL
719gpointer g_type_default_interface_peek (GType g_type);
720GLIB_AVAILABLE_IN_ALL
721void g_type_default_interface_unref (gpointer g_iface);
722
723/* g_free() the returned arrays */
724GLIB_AVAILABLE_IN_ALL
725GType* g_type_children (GType type,
726 guint *n_children);
727GLIB_AVAILABLE_IN_ALL
728GType* g_type_interfaces (GType type,
729 guint *n_interfaces);
730
731/* per-type _static_ data */
732GLIB_AVAILABLE_IN_ALL
733void g_type_set_qdata (GType type,
734 GQuark quark,
735 gpointer data);
736GLIB_AVAILABLE_IN_ALL
737gpointer g_type_get_qdata (GType type,
738 GQuark quark);
739GLIB_AVAILABLE_IN_ALL
740void g_type_query (GType type,
741 GTypeQuery *query);
742
743GLIB_AVAILABLE_IN_2_44
744int g_type_get_instance_count (GType type);
745
746/* --- type registration --- */
747/**
748 * GBaseInitFunc:
749 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize
750 *
751 * A callback function used by the type system to do base initialization
752 * of the class structures of derived types. It is called as part of the
753 * initialization process of all derived classes and should reallocate
754 * or reset all dynamic class members copied over from the parent class.
755 * For example, class members (such as strings) that are not sufficiently
756 * handled by a plain memory copy of the parent class into the derived class
757 * have to be altered. See GClassInitFunc() for a discussion of the class
758 * initialization process.
759 */
760typedef void (*GBaseInitFunc) (gpointer g_class);
761/**
762 * GBaseFinalizeFunc:
763 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
764 *
765 * A callback function used by the type system to finalize those portions
766 * of a derived types class structure that were setup from the corresponding
767 * GBaseInitFunc() function. Class finalization basically works the inverse
768 * way in which class initialization is performed.
769 * See GClassInitFunc() for a discussion of the class initialization process.
770 */
771typedef void (*GBaseFinalizeFunc) (gpointer g_class);
772/**
773 * GClassInitFunc:
774 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize.
775 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
776 *
777 * A callback function used by the type system to initialize the class
778 * of a specific type. This function should initialize all static class
779 * members.
780 *
781 * The initialization process of a class involves:
782 *
783 * - Copying common members from the parent class over to the
784 * derived class structure.
785 * - Zero initialization of the remaining members not copied
786 * over from the parent class.
787 * - Invocation of the GBaseInitFunc() initializers of all parent
788 * types and the class' type.
789 * - Invocation of the class' GClassInitFunc() initializer.
790 *
791 * Since derived classes are partially initialized through a memory copy
792 * of the parent class, the general rule is that GBaseInitFunc() and
793 * GBaseFinalizeFunc() should take care of necessary reinitialization
794 * and release of those class members that were introduced by the type
795 * that specified these GBaseInitFunc()/GBaseFinalizeFunc().
796 * GClassInitFunc() should only care about initializing static
797 * class members, while dynamic class members (such as allocated strings
798 * or reference counted resources) are better handled by a GBaseInitFunc()
799 * for this type, so proper initialization of the dynamic class members
800 * is performed for class initialization of derived types as well.
801 *
802 * An example may help to correspond the intend of the different class
803 * initializers:
804 *
805 * |[<!-- language="C" -->
806 * typedef struct {
807 * GObjectClass parent_class;
808 * gint static_integer;
809 * gchar *dynamic_string;
810 * } TypeAClass;
811 * static void
812 * type_a_base_class_init (TypeAClass *class)
813 * {
814 * class->dynamic_string = g_strdup ("some string");
815 * }
816 * static void
817 * type_a_base_class_finalize (TypeAClass *class)
818 * {
819 * g_free (class->dynamic_string);
820 * }
821 * static void
822 * type_a_class_init (TypeAClass *class)
823 * {
824 * class->static_integer = 42;
825 * }
826 *
827 * typedef struct {
828 * TypeAClass parent_class;
829 * gfloat static_float;
830 * GString *dynamic_gstring;
831 * } TypeBClass;
832 * static void
833 * type_b_base_class_init (TypeBClass *class)
834 * {
835 * class->dynamic_gstring = g_string_new ("some other string");
836 * }
837 * static void
838 * type_b_base_class_finalize (TypeBClass *class)
839 * {
840 * g_string_free (class->dynamic_gstring);
841 * }
842 * static void
843 * type_b_class_init (TypeBClass *class)
844 * {
845 * class->static_float = 3.14159265358979323846;
846 * }
847 * ]|
848 * Initialization of TypeBClass will first cause initialization of
849 * TypeAClass (derived classes reference their parent classes, see
850 * g_type_class_ref() on this).
851 *
852 * Initialization of TypeAClass roughly involves zero-initializing its fields,
853 * then calling its GBaseInitFunc() type_a_base_class_init() to allocate
854 * its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
855 * type_a_class_init() to initialize its static members (static_integer).
856 * The first step in the initialization process of TypeBClass is then
857 * a plain memory copy of the contents of TypeAClass into TypeBClass and
858 * zero-initialization of the remaining fields in TypeBClass.
859 * The dynamic members of TypeAClass within TypeBClass now need
860 * reinitialization which is performed by calling type_a_base_class_init()
861 * with an argument of TypeBClass.
862 *
863 * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
864 * is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
865 * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
866 * is called to complete the initialization process with the static members
867 * (static_float).
868 *
869 * Corresponding finalization counter parts to the GBaseInitFunc() functions
870 * have to be provided to release allocated resources at class finalization
871 * time.
872 */
873typedef void (*GClassInitFunc) (gpointer g_class,
874 gpointer class_data);
875/**
876 * GClassFinalizeFunc:
877 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
878 * @class_data: The @class_data member supplied via the #GTypeInfo structure
879 *
880 * A callback function used by the type system to finalize a class.
881 * This function is rarely needed, as dynamically allocated class resources
882 * should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
883 * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
884 * structure of a static type is invalid, because classes of static types
885 * will never be finalized (they are artificially kept alive when their
886 * reference count drops to zero).
887 */
888typedef void (*GClassFinalizeFunc) (gpointer g_class,
889 gpointer class_data);
890/**
891 * GInstanceInitFunc:
892 * @instance: The instance to initialize
893 * @g_class: (type GObject.TypeClass): The class of the type the instance is
894 * created for
895 *
896 * A callback function used by the type system to initialize a new
897 * instance of a type. This function initializes all instance members and
898 * allocates any resources required by it.
899 *
900 * Initialization of a derived instance involves calling all its parent
901 * types instance initializers, so the class member of the instance
902 * is altered during its initialization to always point to the class that
903 * belongs to the type the current initializer was introduced for.
904 *
905 * The extended members of @instance are guaranteed to have been filled with
906 * zeros before this function is called.
907 */
908typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
909 gpointer g_class);
910/**
911 * GInterfaceInitFunc:
912 * @g_iface: (type GObject.TypeInterface): The interface structure to initialize
913 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
914 *
915 * A callback function used by the type system to initialize a new
916 * interface. This function should initialize all internal data and
917 * allocate any resources required by the interface.
918 *
919 * The members of @iface_data are guaranteed to have been filled with
920 * zeros before this function is called.
921 */
922typedef void (*GInterfaceInitFunc) (gpointer g_iface,
923 gpointer iface_data);
924/**
925 * GInterfaceFinalizeFunc:
926 * @g_iface: (type GObject.TypeInterface): The interface structure to finalize
927 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
928 *
929 * A callback function used by the type system to finalize an interface.
930 * This function should destroy any internal data and release any resources
931 * allocated by the corresponding GInterfaceInitFunc() function.
932 */
933typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
934 gpointer iface_data);
935/**
936 * GTypeClassCacheFunc:
937 * @cache_data: data that was given to the g_type_add_class_cache_func() call
938 * @g_class: (type GObject.TypeClass): The #GTypeClass structure which is
939 * unreferenced
940 *
941 * A callback function which is called when the reference count of a class
942 * drops to zero. It may use g_type_class_ref() to prevent the class from
943 * being freed. You should not call g_type_class_unref() from a
944 * #GTypeClassCacheFunc function to prevent infinite recursion, use
945 * g_type_class_unref_uncached() instead.
946 *
947 * The functions have to check the class id passed in to figure
948 * whether they actually want to cache the class of this type, since all
949 * classes are routed through the same #GTypeClassCacheFunc chain.
950 *
951 * Returns: %TRUE to stop further #GTypeClassCacheFuncs from being
952 * called, %FALSE to continue
953 */
954typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
955 GTypeClass *g_class);
956/**
957 * GTypeInterfaceCheckFunc:
958 * @check_data: data passed to g_type_add_interface_check()
959 * @g_iface: (type GObject.TypeInterface): the interface that has been
960 * initialized
961 *
962 * A callback called after an interface vtable is initialized.
963 * See g_type_add_interface_check().
964 *
965 * Since: 2.4
966 */
967typedef void (*GTypeInterfaceCheckFunc) (gpointer check_data,
968 gpointer g_iface);
969/**
970 * GTypeFundamentalFlags:
971 * @G_TYPE_FLAG_CLASSED: Indicates a classed type
972 * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed)
973 * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type
974 * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable)
975 *
976 * Bit masks used to check or determine specific characteristics of a
977 * fundamental type.
978 */
979typedef enum /*< skip >*/
980{
981 G_TYPE_FLAG_CLASSED = (1 << 0),
982 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
983 G_TYPE_FLAG_DERIVABLE = (1 << 2),
984 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
985} GTypeFundamentalFlags;
986/**
987 * GTypeFlags:
988 * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
989 * created for an abstract type
990 * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
991 * that introduces a value table, but can't be used for
992 * g_value_init()
993 *
994 * Bit masks used to check or determine characteristics of a type.
995 */
996typedef enum /*< skip >*/
997{
998 G_TYPE_FLAG_ABSTRACT = (1 << 4),
999 G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5)
1000} GTypeFlags;
1001/**
1002 * GTypeInfo:
1003 * @class_size: Size of the class structure (required for interface, classed and instantiatable types)
1004 * @base_init: Location of the base initialization function (optional)
1005 * @base_finalize: Location of the base finalization function (optional)
1006 * @class_init: Location of the class initialization function for
1007 * classed and instantiatable types. Location of the default vtable
1008 * inititalization function for interface types. (optional) This function
1009 * is used both to fill in virtual functions in the class or default vtable,
1010 * and to do type-specific setup such as registering signals and object
1011 * properties.
1012 * @class_finalize: Location of the class finalization function for
1013 * classed and instantiatable types. Location of the default vtable
1014 * finalization function for interface types. (optional)
1015 * @class_data: User-supplied data passed to the class init/finalize functions
1016 * @instance_size: Size of the instance (object) structure (required for instantiatable types only)
1017 * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the [slice allocator][glib-Memory-Slices] now.
1018 * @instance_init: Location of the instance initialization function (optional, for instantiatable types only)
1019 * @value_table: A #GTypeValueTable function table for generic handling of GValues
1020 * of this type (usually only useful for fundamental types)
1021 *
1022 * This structure is used to provide the type system with the information
1023 * required to initialize and destruct (finalize) a type's class and
1024 * its instances.
1025 *
1026 * The initialized structure is passed to the g_type_register_static() function
1027 * (or is copied into the provided #GTypeInfo structure in the
1028 * g_type_plugin_complete_type_info()). The type system will perform a deep
1029 * copy of this structure, so its memory does not need to be persistent
1030 * across invocation of g_type_register_static().
1031 */
1032struct _GTypeInfo
1033{
1034 /* interface types, classed types, instantiated types */
1035 guint16 class_size;
1036
1037 GBaseInitFunc base_init;
1038 GBaseFinalizeFunc base_finalize;
1039
1040 /* interface types, classed types, instantiated types */
1041 GClassInitFunc class_init;
1042 GClassFinalizeFunc class_finalize;
1043 gconstpointer class_data;
1044
1045 /* instantiated types */
1046 guint16 instance_size;
1047 guint16 n_preallocs;
1048 GInstanceInitFunc instance_init;
1049
1050 /* value handling */
1051 const GTypeValueTable *value_table;
1052};
1053/**
1054 * GTypeFundamentalInfo:
1055 * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type
1056 *
1057 * A structure that provides information to the type system which is
1058 * used specifically for managing fundamental types.
1059 */
1060struct _GTypeFundamentalInfo
1061{
1062 GTypeFundamentalFlags type_flags;
1063};
1064/**
1065 * GInterfaceInfo:
1066 * @interface_init: location of the interface initialization function
1067 * @interface_finalize: location of the interface finalization function
1068 * @interface_data: user-supplied data passed to the interface init/finalize functions
1069 *
1070 * A structure that provides information to the type system which is
1071 * used specifically for managing interface types.
1072 */
1073struct _GInterfaceInfo
1074{
1075 GInterfaceInitFunc interface_init;
1076 GInterfaceFinalizeFunc interface_finalize;
1077 gpointer interface_data;
1078};
1079/**
1080 * GTypeValueTable:
1081 * @value_init: Default initialize @values contents by poking values
1082 * directly into the value->data array. The data array of
1083 * the #GValue passed into this function was zero-filled
1084 * with `memset()`, so no care has to be taken to free any
1085 * old contents. E.g. for the implementation of a string
1086 * value that may never be %NULL, the implementation might
1087 * look like:
1088 * |[<!-- language="C" -->
1089 * value->data[0].v_pointer = g_strdup ("");
1090 * ]|
1091 * @value_free: Free any old contents that might be left in the
1092 * data array of the passed in @value. No resources may
1093 * remain allocated through the #GValue contents after
1094 * this function returns. E.g. for our above string type:
1095 * |[<!-- language="C" -->
1096 * // only free strings without a specific flag for static storage
1097 * if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1098 * g_free (value->data[0].v_pointer);
1099 * ]|
1100 * @value_copy: @dest_value is a #GValue with zero-filled data section
1101 * and @src_value is a properly setup #GValue of same or
1102 * derived type.
1103 * The purpose of this function is to copy the contents of
1104 * @src_value into @dest_value in a way, that even after
1105 * @src_value has been freed, the contents of @dest_value
1106 * remain valid. String type example:
1107 * |[<!-- language="C" -->
1108 * dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
1109 * ]|
1110 * @value_peek_pointer: If the value contents fit into a pointer, such as objects
1111 * or strings, return this pointer, so the caller can peek at
1112 * the current contents. To extend on our above string example:
1113 * |[<!-- language="C" -->
1114 * return value->data[0].v_pointer;
1115 * ]|
1116 * @collect_format: A string format describing how to collect the contents of
1117 * this value bit-by-bit. Each character in the format represents
1118 * an argument to be collected, and the characters themselves indicate
1119 * the type of the argument. Currently supported arguments are:
1120 * - 'i' - Integers. passed as collect_values[].v_int.
1121 * - 'l' - Longs. passed as collect_values[].v_long.
1122 * - 'd' - Doubles. passed as collect_values[].v_double.
1123 * - 'p' - Pointers. passed as collect_values[].v_pointer.
1124 * It should be noted that for variable argument list construction,
1125 * ANSI C promotes every type smaller than an integer to an int, and
1126 * floats to doubles. So for collection of short int or char, 'i'
1127 * needs to be used, and for collection of floats 'd'.
1128 * @collect_value: The collect_value() function is responsible for converting the
1129 * values collected from a variable argument list into contents
1130 * suitable for storage in a GValue. This function should setup
1131 * @value similar to value_init(); e.g. for a string value that
1132 * does not allow %NULL pointers, it needs to either spew an error,
1133 * or do an implicit conversion by storing an empty string.
1134 * The @value passed in to this function has a zero-filled data
1135 * array, so just like for value_init() it is guaranteed to not
1136 * contain any old contents that might need freeing.
1137 * @n_collect_values is exactly the string length of @collect_format,
1138 * and @collect_values is an array of unions #GTypeCValue with
1139 * length @n_collect_values, containing the collected values
1140 * according to @collect_format.
1141 * @collect_flags is an argument provided as a hint by the caller.
1142 * It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating,
1143 * that the collected value contents may be considered "static"
1144 * for the duration of the @value lifetime.
1145 * Thus an extra copy of the contents stored in @collect_values is
1146 * not required for assignment to @value.
1147 * For our above string example, we continue with:
1148 * |[<!-- language="C" -->
1149 * if (!collect_values[0].v_pointer)
1150 * value->data[0].v_pointer = g_strdup ("");
1151 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1152 * {
1153 * value->data[0].v_pointer = collect_values[0].v_pointer;
1154 * // keep a flag for the value_free() implementation to not free this string
1155 * value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
1156 * }
1157 * else
1158 * value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
1159 * return NULL;
1160 * ]|
1161 * It should be noted, that it is generally a bad idea to follow the
1162 * #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
1163 * reentrancy requirements and reference count assertions performed
1164 * by the signal emission code, reference counts should always be
1165 * incremented for reference counted contents stored in the value->data
1166 * array. To deviate from our string example for a moment, and taking
1167 * a look at an exemplary implementation for collect_value() of
1168 * #GObject:
1169 * |[<!-- language="C" -->
1170 * if (collect_values[0].v_pointer)
1171 * {
1172 * GObject *object = G_OBJECT (collect_values[0].v_pointer);
1173 * // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
1174 * value->data[0].v_pointer = g_object_ref (object);
1175 * return NULL;
1176 * }
1177 * else
1178 * return g_strdup_printf ("Object passed as invalid NULL pointer");
1179 * }
1180 * ]|
1181 * The reference count for valid objects is always incremented,
1182 * regardless of @collect_flags. For invalid objects, the example
1183 * returns a newly allocated string without altering @value.
1184 * Upon success, collect_value() needs to return %NULL. If, however,
1185 * an error condition occurred, collect_value() may spew an
1186 * error by returning a newly allocated non-%NULL string, giving
1187 * a suitable description of the error condition.
1188 * The calling code makes no assumptions about the @value
1189 * contents being valid upon error returns, @value
1190 * is simply thrown away without further freeing. As such, it is
1191 * a good idea to not allocate #GValue contents, prior to returning
1192 * an error, however, collect_values() is not obliged to return
1193 * a correctly setup @value for error returns, simply because
1194 * any non-%NULL return is considered a fatal condition so further
1195 * program behaviour is undefined.
1196 * @lcopy_format: Format description of the arguments to collect for @lcopy_value,
1197 * analogous to @collect_format. Usually, @lcopy_format string consists
1198 * only of 'p's to provide lcopy_value() with pointers to storage locations.
1199 * @lcopy_value: This function is responsible for storing the @value contents into
1200 * arguments passed through a variable argument list which got
1201 * collected into @collect_values according to @lcopy_format.
1202 * @n_collect_values equals the string length of @lcopy_format,
1203 * and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS.
1204 * In contrast to collect_value(), lcopy_value() is obliged to
1205 * always properly support %G_VALUE_NOCOPY_CONTENTS.
1206 * Similar to collect_value() the function may prematurely abort
1207 * by returning a newly allocated string describing an error condition.
1208 * To complete the string example:
1209 * |[<!-- language="C" -->
1210 * gchar **string_p = collect_values[0].v_pointer;
1211 * if (!string_p)
1212 * return g_strdup_printf ("string location passed as NULL");
1213 * if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1214 * *string_p = value->data[0].v_pointer;
1215 * else
1216 * *string_p = g_strdup (value->data[0].v_pointer);
1217 * ]|
1218 * And an illustrative version of lcopy_value() for
1219 * reference-counted types:
1220 * |[<!-- language="C" -->
1221 * GObject **object_p = collect_values[0].v_pointer;
1222 * if (!object_p)
1223 * return g_strdup_printf ("object location passed as NULL");
1224 * if (!value->data[0].v_pointer)
1225 * *object_p = NULL;
1226 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
1227 * *object_p = value->data[0].v_pointer;
1228 * else
1229 * *object_p = g_object_ref (value->data[0].v_pointer);
1230 * return NULL;
1231 * ]|
1232 *
1233 * The #GTypeValueTable provides the functions required by the #GValue
1234 * implementation, to serve as a container for values of a type.
1235 */
1236
1237struct _GTypeValueTable
1238{
1239 void (*value_init) (GValue *value);
1240 void (*value_free) (GValue *value);
1241 void (*value_copy) (const GValue *src_value,
1242 GValue *dest_value);
1243 /* varargs functionality (optional) */
1244 gpointer (*value_peek_pointer) (const GValue *value);
1245 const gchar *collect_format;
1246 gchar* (*collect_value) (GValue *value,
1247 guint n_collect_values,
1248 GTypeCValue *collect_values,
1249 guint collect_flags);
1250 const gchar *lcopy_format;
1251 gchar* (*lcopy_value) (const GValue *value,
1252 guint n_collect_values,
1253 GTypeCValue *collect_values,
1254 guint collect_flags);
1255};
1256GLIB_AVAILABLE_IN_ALL
1257GType g_type_register_static (GType parent_type,
1258 const gchar *type_name,
1259 const GTypeInfo *info,
1260 GTypeFlags flags);
1261GLIB_AVAILABLE_IN_ALL
1262GType g_type_register_static_simple (GType parent_type,
1263 const gchar *type_name,
1264 guint class_size,
1265 GClassInitFunc class_init,
1266 guint instance_size,
1267 GInstanceInitFunc instance_init,
1268 GTypeFlags flags);
1269
1270GLIB_AVAILABLE_IN_ALL
1271GType g_type_register_dynamic (GType parent_type,
1272 const gchar *type_name,
1273 GTypePlugin *plugin,
1274 GTypeFlags flags);
1275GLIB_AVAILABLE_IN_ALL
1276GType g_type_register_fundamental (GType type_id,
1277 const gchar *type_name,
1278 const GTypeInfo *info,
1279 const GTypeFundamentalInfo *finfo,
1280 GTypeFlags flags);
1281GLIB_AVAILABLE_IN_ALL
1282void g_type_add_interface_static (GType instance_type,
1283 GType interface_type,
1284 const GInterfaceInfo *info);
1285GLIB_AVAILABLE_IN_ALL
1286void g_type_add_interface_dynamic (GType instance_type,
1287 GType interface_type,
1288 GTypePlugin *plugin);
1289GLIB_AVAILABLE_IN_ALL
1290void g_type_interface_add_prerequisite (GType interface_type,
1291 GType prerequisite_type);
1292GLIB_AVAILABLE_IN_ALL
1293GType*g_type_interface_prerequisites (GType interface_type,
1294 guint *n_prerequisites);
1295GLIB_AVAILABLE_IN_ALL
1296void g_type_class_add_private (gpointer g_class,
1297 gsize private_size);
1298GLIB_AVAILABLE_IN_2_38
1299gint g_type_add_instance_private (GType class_type,
1300 gsize private_size);
1301GLIB_AVAILABLE_IN_ALL
1302gpointer g_type_instance_get_private (GTypeInstance *instance,
1303 GType private_type);
1304GLIB_AVAILABLE_IN_2_38
1305void g_type_class_adjust_private_offset (gpointer g_class,
1306 gint *private_size_or_offset);
1307
1308GLIB_AVAILABLE_IN_ALL
1309void g_type_add_class_private (GType class_type,
1310 gsize private_size);
1311GLIB_AVAILABLE_IN_ALL
1312gpointer g_type_class_get_private (GTypeClass *klass,
1313 GType private_type);
1314GLIB_AVAILABLE_IN_2_38
1315gint g_type_class_get_instance_private_offset (gpointer g_class);
1316
1317GLIB_AVAILABLE_IN_2_34
1318void g_type_ensure (GType type);
1319GLIB_AVAILABLE_IN_2_36
1320guint g_type_get_type_registration_serial (void);
1321
1322
1323/* --- GType boilerplate --- */
1324/**
1325 * G_DECLARE_FINAL_TYPE:
1326 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1327 * @module_obj_name: The name of the new type in lowercase, with words
1328 * separated by '_' (like 'gtk_widget')
1329 * @MODULE: The name of the module, in all caps (like 'GTK')
1330 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1331 * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1332 *
1333 * A convenience macro for emitting the usual declarations in the header file for a type which is not (at the
1334 * present time) intended to be subclassed.
1335 *
1336 * You might use it in a header as follows:
1337 *
1338 * |[
1339 * #ifndef _myapp_window_h_
1340 * #define _myapp_window_h_
1341 *
1342 * #include <gtk/gtk.h>
1343 *
1344 * #define MY_APP_TYPE_WINDOW my_app_window_get_type ()
1345 * G_DECLARE_FINAL_TYPE (MyAppWindow, my_app_window, MY_APP, WINDOW, GtkWindow)
1346 *
1347 * MyAppWindow * my_app_window_new (void);
1348 *
1349 * ...
1350 *
1351 * #endif
1352 * ]|
1353 *
1354 * This results in the following things happening:
1355 *
1356 * - the usual my_app_window_get_type() function is declared with a return type of #GType
1357 *
1358 * - the MyAppWindow types is defined as a typedef of struct _MyAppWindow. The struct itself is not
1359 * defined and should be defined from the .c file before G_DEFINE_TYPE() is used.
1360 *
1361 * - the MY_APP_WINDOW() cast is emitted as static inline function along with the MY_APP_IS_WINDOW() type
1362 * checking function
1363 *
1364 * - the MyAppWindowClass type is defined as a struct containing GtkWindowClass. This is done for the
1365 * convenience of the person defining the type and should not be considered to be part of the ABI. In
1366 * particular, without a firm declaration of the instance structure, it is not possible to subclass the type
1367 * and therefore the fact that the size of the class structure is exposed is not a concern and it can be
1368 * freely changed at any point in the future.
1369 *
1370 * - g_autoptr() support being added for your type, based on the type of your parent class
1371 *
1372 * You can only use this function if your parent type also supports g_autoptr().
1373 *
1374 * Because the type macro (MY_APP_TYPE_WINDOW in the above example) is not a callable, you must continue to
1375 * manually define this as a macro for yourself.
1376 *
1377 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1378 * to be used in the usual way with export control and API versioning macros.
1379 *
1380 * If you want to declare your own class structure, use G_DECLARE_DERIVABLE_TYPE().
1381 *
1382 * If you are writing a library, it is important to note that it is possible to convert a type from using
1383 * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you
1384 * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1385 * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or
1386 * reorder items without breaking the API and/or ABI.
1387 *
1388 * Since: 2.44
1389 **/
1390#define G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1391 GType module_obj_name##_get_type (void); \
1392 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1393 typedef struct _##ModuleObjName ModuleObjName; \
1394 typedef struct { ParentName##Class parent_class; } ModuleObjName##Class; \
1395 \
1396 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
1397 \
1398 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1399 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1400 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1401 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1402 G_GNUC_END_IGNORE_DEPRECATIONS
1403
1404/**
1405 * G_DECLARE_DERIVABLE_TYPE:
1406 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1407 * @module_obj_name: The name of the new type in lowercase, with words
1408 * separated by '_' (like 'gtk_widget')
1409 * @MODULE: The name of the module, in all caps (like 'GTK')
1410 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1411 * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1412 *
1413 * A convenience macro for emitting the usual declarations in the header file for a type which will is intended
1414 * to be subclassed.
1415 *
1416 * You might use it in a header as follows:
1417 *
1418 * |[
1419 * #ifndef _gtk_frobber_h_
1420 * #define _gtk_frobber_h_
1421 *
1422 * #define GTK_TYPE_FROBBER gtk_frobber_get_type ()
1423 * GDK_AVAILABLE_IN_3_12
1424 * G_DECLARE_DERIVABLE_TYPE (GtkFrobber, gtk_frobber, GTK, FROBBER, GtkWidget)
1425 *
1426 * struct _GtkFrobberClass
1427 * {
1428 * GtkWidgetClass parent_class;
1429 *
1430 * void (* handle_frob) (GtkFrobber *frobber,
1431 * guint n_frobs);
1432 *
1433 * gpointer padding[12];
1434 * };
1435 *
1436 * GtkWidget * gtk_frobber_new (void);
1437 *
1438 * ...
1439 *
1440 * #endif
1441 * ]|
1442 *
1443 * This results in the following things happening:
1444 *
1445 * - the usual gtk_frobber_get_type() function is declared with a return type of #GType
1446 *
1447 * - the GtkFrobber struct is created with GtkWidget as the first and only item. You are expected to use
1448 * a private structure from your .c file to store your instance variables.
1449 *
1450 * - the GtkFrobberClass type is defined as a typedef to struct _GtkFrobberClass, which is left undefined.
1451 * You should do this from the header file directly after you use the macro.
1452 *
1453 * - the GTK_FROBBER() and GTK_FROBBER_CLASS() casts are emitted as static inline functions along with
1454 * the GTK_IS_FROBBER() and GTK_IS_FROBBER_CLASS() type checking functions and GTK_FROBBER_GET_CLASS()
1455 * function.
1456 *
1457 * - g_autoptr() support being added for your type, based on the type of your parent class
1458 *
1459 * You can only use this function if your parent type also supports g_autoptr().
1460 *
1461 * Because the type macro (GTK_TYPE_FROBBER in the above example) is not a callable, you must continue to
1462 * manually define this as a macro for yourself.
1463 *
1464 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1465 * to be used in the usual way with export control and API versioning macros.
1466 *
1467 * If you are writing a library, it is important to note that it is possible to convert a type from using
1468 * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you
1469 * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1470 * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or
1471 * reorder items without breaking the API and/or ABI. If you want to declare your own class structure, use
1472 * G_DECLARE_DERIVABLE_TYPE(). If you want to declare a class without exposing the class or instance
1473 * structures, use G_DECLARE_FINAL_TYPE().
1474 *
1475 * If you must use G_DECLARE_DERIVABLE_TYPE() you should be sure to include some padding at the bottom of your
1476 * class structure to leave space for the addition of future virtual functions.
1477 *
1478 * Since: 2.44
1479 **/
1480#define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1481 GType module_obj_name##_get_type (void); \
1482 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1483 typedef struct _##ModuleObjName ModuleObjName; \
1484 typedef struct _##ModuleObjName##Class ModuleObjName##Class; \
1485 struct _##ModuleObjName { ParentName parent_instance; }; \
1486 \
1487 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
1488 \
1489 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1490 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1491 static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_CLASS (gpointer ptr) { \
1492 return G_TYPE_CHECK_CLASS_CAST (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
1493 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1494 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1495 static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS (gpointer ptr) { \
1496 return G_TYPE_CHECK_CLASS_TYPE (ptr, module_obj_name##_get_type ()); } \
1497 static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_GET_CLASS (gpointer ptr) { \
1498 return G_TYPE_INSTANCE_GET_CLASS (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
1499 G_GNUC_END_IGNORE_DEPRECATIONS
1500
1501/**
1502 * G_DECLARE_INTERFACE:
1503 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1504 * @module_obj_name: The name of the new type in lowercase, with words
1505 * separated by '_' (like 'gtk_widget')
1506 * @MODULE: The name of the module, in all caps (like 'GTK')
1507 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1508 * @PrerequisiteName: the name of the prerequisite type, in camel case (like GtkWidget)
1509 *
1510 * A convenience macro for emitting the usual declarations in the header file for a GInterface type.
1511 *
1512 * You might use it in a header as follows:
1513 *
1514 * |[
1515 * #ifndef _my_model_h_
1516 * #define _my_model_h_
1517 *
1518 * #define MY_TYPE_MODEL my_model_get_type ()
1519 * GDK_AVAILABLE_IN_3_12
1520 * G_DECLARE_INTERFACE (MyModel, my_model, MY, MODEL, GObject)
1521 *
1522 * struct _MyModelInterface
1523 * {
1524 * GTypeInterface g_iface;
1525 *
1526 * gpointer (* get_item) (MyModel *model);
1527 * };
1528 *
1529 * gpointer my_model_get_item (MyModel *model);
1530 *
1531 * ...
1532 *
1533 * #endif
1534 * ]|
1535 *
1536 * This results in the following things happening:
1537 *
1538 * - the usual my_model_get_type() function is declared with a return type of #GType
1539 *
1540 * - the MyModelInterface type is defined as a typedef to struct _MyModelInterface,
1541 * which is left undefined. You should do this from the header file directly after
1542 * you use the macro.
1543 *
1544 * - the MY_MODEL() cast is emitted as static inline functions along with
1545 * the MY_IS_MODEL() type checking function and MY_MODEL_GET_IFACE() function.
1546 *
1547 * - g_autoptr() support being added for your type, based on your prerequisite type.
1548 *
1549 * You can only use this function if your prerequisite type also supports g_autoptr().
1550 *
1551 * Because the type macro (MY_TYPE_MODEL in the above example) is not a callable, you must continue to
1552 * manually define this as a macro for yourself.
1553 *
1554 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1555 * to be used in the usual way with export control and API versioning macros.
1556 *
1557 * Since: 2.44
1558 **/
1559#define G_DECLARE_INTERFACE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, PrerequisiteName) \
1560 GType module_obj_name##_get_type (void); \
1561 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1562 typedef struct _##ModuleObjName ModuleObjName; \
1563 typedef struct _##ModuleObjName##Interface ModuleObjName##Interface; \
1564 \
1565 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, PrerequisiteName) \
1566 \
1567 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1568 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1569 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1570 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1571 static inline ModuleObjName##Interface * MODULE##_##OBJ_NAME##_GET_IFACE (gpointer ptr) { \
1572 return G_TYPE_INSTANCE_GET_INTERFACE (ptr, module_obj_name##_get_type (), ModuleObjName##Interface); } \
1573 G_GNUC_END_IGNORE_DEPRECATIONS
1574
1575/**
1576 * G_DEFINE_TYPE:
1577 * @TN: The name of the new type, in Camel case.
1578 * @t_n: The name of the new type, in lowercase, with words
1579 * separated by '_'.
1580 * @T_P: The #GType of the parent type.
1581 *
1582 * A convenience macro for type implementations, which declares a class
1583 * initialization function, an instance initialization function (see #GTypeInfo
1584 * for information about these) and a static variable named `t_n_parent_class`
1585 * pointing to the parent class. Furthermore, it defines a *_get_type() function.
1586 * See G_DEFINE_TYPE_EXTENDED() for an example.
1587 *
1588 * Since: 2.4
1589 */
1590#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
1591/**
1592 * G_DEFINE_TYPE_WITH_CODE:
1593 * @TN: The name of the new type, in Camel case.
1594 * @t_n: The name of the new type in lowercase, with words separated by '_'.
1595 * @T_P: The #GType of the parent type.
1596 * @_C_: Custom code that gets inserted in the *_get_type() function.
1597 *
1598 * A convenience macro for type implementations.
1599 * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the
1600 * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
1601 * See G_DEFINE_TYPE_EXTENDED() for an example.
1602 *
1603 * Since: 2.4
1604 */
1605#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1606/**
1607 * G_DEFINE_TYPE_WITH_PRIVATE:
1608 * @TN: The name of the new type, in Camel case.
1609 * @t_n: The name of the new type, in lowercase, with words
1610 * separated by '_'.
1611 * @T_P: The #GType of the parent type.
1612 *
1613 * A convenience macro for type implementations, which declares a class
1614 * initialization function, an instance initialization function (see #GTypeInfo
1615 * for information about these), a static variable named `t_n_parent_class`
1616 * pointing to the parent class, and adds private instance data to the type.
1617 * Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED()
1618 * for an example.
1619 *
1620 * Note that private structs added with this macros must have a struct
1621 * name of the form @TN Private.
1622 *
1623 * Since: 2.38
1624 */
1625#define G_DEFINE_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, G_ADD_PRIVATE (TN))
1626/**
1627 * G_DEFINE_ABSTRACT_TYPE:
1628 * @TN: The name of the new type, in Camel case.
1629 * @t_n: The name of the new type, in lowercase, with words
1630 * separated by '_'.
1631 * @T_P: The #GType of the parent type.
1632 *
1633 * A convenience macro for type implementations.
1634 * Similar to G_DEFINE_TYPE(), but defines an abstract type.
1635 * See G_DEFINE_TYPE_EXTENDED() for an example.
1636 *
1637 * Since: 2.4
1638 */
1639#define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
1640/**
1641 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE:
1642 * @TN: The name of the new type, in Camel case.
1643 * @t_n: The name of the new type, in lowercase, with words
1644 * separated by '_'.
1645 * @T_P: The #GType of the parent type.
1646 * @_C_: Custom code that gets inserted in the @type_name_get_type() function.
1647 *
1648 * A convenience macro for type implementations.
1649 * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and
1650 * allows you to insert custom code into the *_get_type() function, e.g.
1651 * interface implementations via G_IMPLEMENT_INTERFACE().
1652 * See G_DEFINE_TYPE_EXTENDED() for an example.
1653 *
1654 * Since: 2.4
1655 */
1656#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1657/**
1658 * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE:
1659 * @TN: The name of the new type, in Camel case.
1660 * @t_n: The name of the new type, in lowercase, with words
1661 * separated by '_'.
1662 * @T_P: The #GType of the parent type.
1663 *
1664 * Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type.
1665 * See G_DEFINE_TYPE_EXTENDED() for an example.
1666 *
1667 * Since: 2.38
1668 */
1669#define G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, G_ADD_PRIVATE (TN))
1670/**
1671 * G_DEFINE_TYPE_EXTENDED:
1672 * @TN: The name of the new type, in Camel case.
1673 * @t_n: The name of the new type, in lowercase, with words
1674 * separated by '_'.
1675 * @T_P: The #GType of the parent type.
1676 * @_f_: #GTypeFlags to pass to g_type_register_static()
1677 * @_C_: Custom code that gets inserted in the *_get_type() function.
1678 *
1679 * The most general convenience macro for type implementations, on which
1680 * G_DEFINE_TYPE(), etc are based.
1681 *
1682 * |[<!-- language="C" -->
1683 * G_DEFINE_TYPE_EXTENDED (GtkGadget,
1684 * gtk_gadget,
1685 * GTK_TYPE_WIDGET,
1686 * 0,
1687 * G_IMPLEMENT_INTERFACE (TYPE_GIZMO,
1688 * gtk_gadget_gizmo_init));
1689 * ]|
1690 * expands to
1691 * |[<!-- language="C" -->
1692 * static void gtk_gadget_init (GtkGadget *self);
1693 * static void gtk_gadget_class_init (GtkGadgetClass *klass);
1694 * static gpointer gtk_gadget_parent_class = NULL;
1695 * static void gtk_gadget_class_intern_init (gpointer klass)
1696 * {
1697 * gtk_gadget_parent_class = g_type_class_peek_parent (klass);
1698 * gtk_gadget_class_init ((GtkGadgetClass*) klass);
1699 * }
1700 *
1701 * GType
1702 * gtk_gadget_get_type (void)
1703 * {
1704 * static volatile gsize g_define_type_id__volatile = 0;
1705 * if (g_once_init_enter (&g_define_type_id__volatile))
1706 * {
1707 * GType g_define_type_id =
1708 * g_type_register_static_simple (GTK_TYPE_WIDGET,
1709 * g_intern_static_string ("GtkGadget"),
1710 * sizeof (GtkGadgetClass),
1711 * (GClassInitFunc) gtk_gadget_class_intern_init,
1712 * sizeof (GtkGadget),
1713 * (GInstanceInitFunc) gtk_gadget_init,
1714 * 0);
1715 * {
1716 * const GInterfaceInfo g_implement_interface_info = {
1717 * (GInterfaceInitFunc) gtk_gadget_gizmo_init
1718 * };
1719 * g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
1720 * }
1721 * g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
1722 * }
1723 * return g_define_type_id__volatile;
1724 * }
1725 * ]|
1726 * The only pieces which have to be manually provided are the definitions of
1727 * the instance and class structure and the definitions of the instance and
1728 * class init functions.
1729 *
1730 * Since: 2.4
1731 */
1732#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1733
1734/**
1735 * G_DEFINE_INTERFACE:
1736 * @TN: The name of the new type, in Camel case.
1737 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1738 * @T_P: The #GType of the prerequisite type for the interface, or 0
1739 * (%G_TYPE_INVALID) for no prerequisite type.
1740 *
1741 * A convenience macro for #GTypeInterface definitions, which declares
1742 * a default vtable initialization function and defines a *_get_type()
1743 * function.
1744 *
1745 * The macro expects the interface initialization function to have the
1746 * name `t_n ## _default_init`, and the interface structure to have the
1747 * name `TN ## Interface`.
1748 *
1749 * Since: 2.24
1750 */
1751#define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
1752
1753/**
1754 * G_DEFINE_INTERFACE_WITH_CODE:
1755 * @TN: The name of the new type, in Camel case.
1756 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1757 * @T_P: The #GType of the prerequisite type for the interface, or 0
1758 * (%G_TYPE_INVALID) for no prerequisite type.
1759 * @_C_: Custom code that gets inserted in the *_get_type() function.
1760 *
1761 * A convenience macro for #GTypeInterface definitions. Similar to
1762 * G_DEFINE_INTERFACE(), but allows you to insert custom code into the
1763 * *_get_type() function, e.g. additional interface implementations
1764 * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See
1765 * G_DEFINE_TYPE_EXTENDED() for a similar example using
1766 * G_DEFINE_TYPE_WITH_CODE().
1767 *
1768 * Since: 2.24
1769 */
1770#define G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P) {_C_;} _G_DEFINE_INTERFACE_EXTENDED_END()
1771
1772/**
1773 * G_IMPLEMENT_INTERFACE:
1774 * @TYPE_IFACE: The #GType of the interface to add
1775 * @iface_init: The interface init function
1776 *
1777 * A convenience macro to ease interface addition in the `_C_` section
1778 * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1779 * See G_DEFINE_TYPE_EXTENDED() for an example.
1780 *
1781 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1782 * macros, since it depends on variable names from those macros.
1783 *
1784 * Since: 2.4
1785 */
1786#define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
1787 const GInterfaceInfo g_implement_interface_info = { \
1788 (GInterfaceInitFunc) iface_init, NULL, NULL \
1789 }; \
1790 g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
1791}
1792
1793/**
1794 * G_ADD_PRIVATE:
1795 * @TypeName: the name of the type in CamelCase
1796 *
1797 * A convenience macro to ease adding private data to instances of a new type
1798 * in the @_C_ section of G_DEFINE_TYPE_WITH_CODE() or
1799 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1800 *
1801 * For instance:
1802 *
1803 * |[<!-- language="C" -->
1804 * typedef struct _MyObject MyObject;
1805 * typedef struct _MyObjectClass MyObjectClass;
1806 *
1807 * typedef struct {
1808 * gint foo;
1809 * gint bar;
1810 * } MyObjectPrivate;
1811 *
1812 * G_DEFINE_TYPE_WITH_CODE (MyObject, my_object, G_TYPE_OBJECT,
1813 * G_ADD_PRIVATE (MyObject))
1814 * ]|
1815 *
1816 * Will add MyObjectPrivate as the private data to any instance of the MyObject
1817 * type.
1818 *
1819 * G_DEFINE_TYPE_* macros will automatically create a private function
1820 * based on the arguments to this macro, which can be used to safely
1821 * retrieve the private data from an instance of the type; for instance:
1822 *
1823 * |[<!-- language="C" -->
1824 * gint
1825 * my_object_get_foo (MyObject *obj)
1826 * {
1827 * MyObjectPrivate *priv = my_object_get_instance_private (obj);
1828 *
1829 * g_return_val_if_fail (MY_IS_OBJECT (obj), 0);
1830 *
1831 * return priv->foo;
1832 * }
1833 *
1834 * void
1835 * my_object_set_bar (MyObject *obj,
1836 * gint bar)
1837 * {
1838 * MyObjectPrivate *priv = my_object_get_instance_private (obj);
1839 *
1840 * g_return_if_fail (MY_IS_OBJECT (obj));
1841 *
1842 * if (priv->bar != bar)
1843 * priv->bar = bar;
1844 * }
1845 * ]|
1846 *
1847 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1848 * macros, since it depends on variable names from those macros.
1849 *
1850 * Also note that private structs added with these macros must have a struct
1851 * name of the form `TypeNamePrivate`.
1852 *
1853 * It is safe to call _get_instance_private on %NULL or invalid object since
1854 * it's only adding an offset to the instance pointer. In that case the returned
1855 * pointer must not be dereferenced.
1856 *
1857 * Since: 2.38
1858 */
1859#define G_ADD_PRIVATE(TypeName) { \
1860 TypeName##_private_offset = \
1861 g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \
1862}
1863
1864/**
1865 * G_PRIVATE_OFFSET:
1866 * @TypeName: the name of the type in CamelCase
1867 * @field: the name of the field in the private data structure
1868 *
1869 * Evaluates to the offset of the @field inside the instance private data
1870 * structure for @TypeName.
1871 *
1872 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1873 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1874 * those macros.
1875 *
1876 * Since: 2.38
1877 */
1878#define G_PRIVATE_OFFSET(TypeName, field) \
1879 (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field)))
1880
1881/**
1882 * G_PRIVATE_FIELD_P:
1883 * @TypeName: the name of the type in CamelCase
1884 * @inst: the instance of @TypeName you wish to access
1885 * @field_name: the name of the field in the private data structure
1886 *
1887 * Evaluates to a pointer to the @field_name inside the @inst private data
1888 * structure for @TypeName.
1889 *
1890 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1891 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1892 * those macros.
1893 *
1894 * Since: 2.38
1895 */
1896#define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \
1897 G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name))
1898
1899/**
1900 * G_PRIVATE_FIELD:
1901 * @TypeName: the name of the type in CamelCase
1902 * @inst: the instance of @TypeName you wish to access
1903 * @field_type: the type of the field in the private data structure
1904 * @field_name: the name of the field in the private data structure
1905 *
1906 * Evaluates to the @field_name inside the @inst private data
1907 * structure for @TypeName.
1908 *
1909 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1910 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1911 * those macros.
1912 *
1913 * Since: 2.38
1914 */
1915#define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \
1916 G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name))
1917
1918/* we need to have this macro under conditional expansion, as it references
1919 * a function that has been added in 2.38. see bug:
1920 * https://bugzilla.gnome.org/show_bug.cgi?id=703191
1921 */
1922#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38
1923#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1924static void type_name##_class_intern_init (gpointer klass) \
1925{ \
1926 type_name##_parent_class = g_type_class_peek_parent (klass); \
1927 if (TypeName##_private_offset != 0) \
1928 g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \
1929 type_name##_class_init ((TypeName##Class*) klass); \
1930}
1931
1932#else
1933#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1934static void type_name##_class_intern_init (gpointer klass) \
1935{ \
1936 type_name##_parent_class = g_type_class_peek_parent (klass); \
1937 type_name##_class_init ((TypeName##Class*) klass); \
1938}
1939#endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */
1940
1941#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
1942\
1943static void type_name##_init (TypeName *self); \
1944static void type_name##_class_init (TypeName##Class *klass); \
1945static gpointer type_name##_parent_class = NULL; \
1946static gint TypeName##_private_offset; \
1947\
1948_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1949\
1950G_GNUC_UNUSED \
1951static inline gpointer \
1952type_name##_get_instance_private (TypeName *self) \
1953{ \
1954 return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
1955} \
1956\
1957GType \
1958type_name##_get_type (void) \
1959{ \
1960 static volatile gsize g_define_type_id__volatile = 0; \
1961 if (g_once_init_enter (&g_define_type_id__volatile)) \
1962 { \
1963 GType g_define_type_id = \
1964 g_type_register_static_simple (TYPE_PARENT, \
1965 g_intern_static_string (#TypeName), \
1966 sizeof (TypeName##Class), \
1967 (GClassInitFunc) type_name##_class_intern_init, \
1968 sizeof (TypeName), \
1969 (GInstanceInitFunc) type_name##_init, \
1970 (GTypeFlags) flags); \
1971 { /* custom code follows */
1972#define _G_DEFINE_TYPE_EXTENDED_END() \
1973 /* following custom code */ \
1974 } \
1975 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
1976 } \
1977 return g_define_type_id__volatile; \
1978} /* closes type_name##_get_type() */
1979
1980#define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
1981\
1982static void type_name##_default_init (TypeName##Interface *klass); \
1983\
1984GType \
1985type_name##_get_type (void) \
1986{ \
1987 static volatile gsize g_define_type_id__volatile = 0; \
1988 if (g_once_init_enter (&g_define_type_id__volatile)) \
1989 { \
1990 GType g_define_type_id = \
1991 g_type_register_static_simple (G_TYPE_INTERFACE, \
1992 g_intern_static_string (#TypeName), \
1993 sizeof (TypeName##Interface), \
1994 (GClassInitFunc)type_name##_default_init, \
1995 0, \
1996 (GInstanceInitFunc)NULL, \
1997 (GTypeFlags) 0); \
1998 if (TYPE_PREREQ) \
1999 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
2000 { /* custom code follows */
2001#define _G_DEFINE_INTERFACE_EXTENDED_END() \
2002 /* following custom code */ \
2003 } \
2004 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2005 } \
2006 return g_define_type_id__volatile; \
2007} /* closes type_name##_get_type() */
2008
2009/**
2010 * G_DEFINE_BOXED_TYPE:
2011 * @TypeName: The name of the new type, in Camel case
2012 * @type_name: The name of the new type, in lowercase, with words
2013 * separated by '_'
2014 * @copy_func: the #GBoxedCopyFunc for the new type
2015 * @free_func: the #GBoxedFreeFunc for the new type
2016 *
2017 * A convenience macro for boxed type implementations, which defines a
2018 * type_name_get_type() function registering the boxed type.
2019 *
2020 * Since: 2.26
2021 */
2022#define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {})
2023/**
2024 * G_DEFINE_BOXED_TYPE_WITH_CODE:
2025 * @TypeName: The name of the new type, in Camel case
2026 * @type_name: The name of the new type, in lowercase, with words
2027 * separated by '_'
2028 * @copy_func: the #GBoxedCopyFunc for the new type
2029 * @free_func: the #GBoxedFreeFunc for the new type
2030 * @_C_: Custom code that gets inserted in the *_get_type() function
2031 *
2032 * A convenience macro for boxed type implementations.
2033 * Similar to G_DEFINE_BOXED_TYPE(), but allows to insert custom code into the
2034 * type_name_get_type() function, e.g. to register value transformations with
2035 * g_value_register_transform_func(), for instance:
2036 *
2037 * |[<!-- language="C" -->
2038 * G_DEFINE_BOXED_TYPE_WITH_CODE (GdkRectangle, gdk_rectangle,
2039 * gdk_rectangle_copy,
2040 * gdk_rectangle_free,
2041 * register_rectangle_transform_funcs (g_define_type_id))
2042 * ]|
2043 *
2044 * Similarly to the %G_DEFINE_TYPE family of macros, the #GType of the newly
2045 * defined boxed type is exposed in the `g_define_type_id` variable.
2046 *
2047 * Since: 2.26
2048 */
2049#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
2050
2051/* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64.
2052 * See https://bugzilla.gnome.org/show_bug.cgi?id=647145
2053 */
2054#if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__))
2055#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2056GType \
2057type_name##_get_type (void) \
2058{ \
2059 static volatile gsize g_define_type_id__volatile = 0; \
2060 if (g_once_init_enter (&g_define_type_id__volatile)) \
2061 { \
2062 GType (* _g_register_boxed) \
2063 (const gchar *, \
2064 union \
2065 { \
2066 TypeName * (*do_copy_type) (TypeName *); \
2067 TypeName * (*do_const_copy_type) (const TypeName *); \
2068 GBoxedCopyFunc do_copy_boxed; \
2069 } __attribute__((__transparent_union__)), \
2070 union \
2071 { \
2072 void (* do_free_type) (TypeName *); \
2073 GBoxedFreeFunc do_free_boxed; \
2074 } __attribute__((__transparent_union__)) \
2075 ) = g_boxed_type_register_static; \
2076 GType g_define_type_id = \
2077 _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func); \
2078 { /* custom code follows */
2079#else
2080#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2081GType \
2082type_name##_get_type (void) \
2083{ \
2084 static volatile gsize g_define_type_id__volatile = 0; \
2085 if (g_once_init_enter (&g_define_type_id__volatile)) \
2086 { \
2087 GType g_define_type_id = \
2088 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
2089 (GBoxedCopyFunc) copy_func, \
2090 (GBoxedFreeFunc) free_func); \
2091 { /* custom code follows */
2092#endif /* __GNUC__ */
2093
2094/**
2095 * G_DEFINE_POINTER_TYPE:
2096 * @TypeName: The name of the new type, in Camel case
2097 * @type_name: The name of the new type, in lowercase, with words
2098 * separated by '_'
2099 *
2100 * A convenience macro for pointer type implementations, which defines a
2101 * type_name_get_type() function registering the pointer type.
2102 *
2103 * Since: 2.26
2104 */
2105#define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE (TypeName, type_name, {})
2106/**
2107 * G_DEFINE_POINTER_TYPE_WITH_CODE:
2108 * @TypeName: The name of the new type, in Camel case
2109 * @type_name: The name of the new type, in lowercase, with words
2110 * separated by '_'
2111 * @_C_: Custom code that gets inserted in the *_get_type() function
2112 *
2113 * A convenience macro for pointer type implementations.
2114 * Similar to G_DEFINE_POINTER_TYPE(), but allows to insert
2115 * custom code into the type_name_get_type() function.
2116 *
2117 * Since: 2.26
2118 */
2119#define G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, _C_) _G_DEFINE_POINTER_TYPE_BEGIN (TypeName, type_name) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
2120
2121#define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \
2122GType \
2123type_name##_get_type (void) \
2124{ \
2125 static volatile gsize g_define_type_id__volatile = 0; \
2126 if (g_once_init_enter (&g_define_type_id__volatile)) \
2127 { \
2128 GType g_define_type_id = \
2129 g_pointer_type_register_static (g_intern_static_string (#TypeName)); \
2130 { /* custom code follows */
2131
2132/* --- protected (for fundamental type implementations) --- */
2133GLIB_AVAILABLE_IN_ALL
2134GTypePlugin* g_type_get_plugin (GType type);
2135GLIB_AVAILABLE_IN_ALL
2136GTypePlugin* g_type_interface_get_plugin (GType instance_type,
2137 GType interface_type);
2138GLIB_AVAILABLE_IN_ALL
2139GType g_type_fundamental_next (void);
2140GLIB_AVAILABLE_IN_ALL
2141GType g_type_fundamental (GType type_id);
2142GLIB_AVAILABLE_IN_ALL
2143GTypeInstance* g_type_create_instance (GType type);
2144GLIB_AVAILABLE_IN_ALL
2145void g_type_free_instance (GTypeInstance *instance);
2146
2147GLIB_AVAILABLE_IN_ALL
2148void g_type_add_class_cache_func (gpointer cache_data,
2149 GTypeClassCacheFunc cache_func);
2150GLIB_AVAILABLE_IN_ALL
2151void g_type_remove_class_cache_func (gpointer cache_data,
2152 GTypeClassCacheFunc cache_func);
2153GLIB_AVAILABLE_IN_ALL
2154void g_type_class_unref_uncached (gpointer g_class);
2155
2156GLIB_AVAILABLE_IN_ALL
2157void g_type_add_interface_check (gpointer check_data,
2158 GTypeInterfaceCheckFunc check_func);
2159GLIB_AVAILABLE_IN_ALL
2160void g_type_remove_interface_check (gpointer check_data,
2161 GTypeInterfaceCheckFunc check_func);
2162
2163GLIB_AVAILABLE_IN_ALL
2164GTypeValueTable* g_type_value_table_peek (GType type);
2165
2166
2167/*< private >*/
2168GLIB_AVAILABLE_IN_ALL
2169gboolean g_type_check_instance (GTypeInstance *instance) G_GNUC_PURE;
2170GLIB_AVAILABLE_IN_ALL
2171GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
2172 GType iface_type);
2173GLIB_AVAILABLE_IN_ALL
2174gboolean g_type_check_instance_is_a (GTypeInstance *instance,
2175 GType iface_type) G_GNUC_PURE;
2176GLIB_AVAILABLE_IN_2_42
2177gboolean g_type_check_instance_is_fundamentally_a (GTypeInstance *instance,
2178 GType fundamental_type) G_GNUC_PURE;
2179GLIB_AVAILABLE_IN_ALL
2180GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
2181 GType is_a_type);
2182GLIB_AVAILABLE_IN_ALL
2183gboolean g_type_check_class_is_a (GTypeClass *g_class,
2184 GType is_a_type) G_GNUC_PURE;
2185GLIB_AVAILABLE_IN_ALL
2186gboolean g_type_check_is_value_type (GType type) G_GNUC_CONST;
2187GLIB_AVAILABLE_IN_ALL
2188gboolean g_type_check_value (GValue *value) G_GNUC_PURE;
2189GLIB_AVAILABLE_IN_ALL
2190gboolean g_type_check_value_holds (GValue *value,
2191 GType type) G_GNUC_PURE;
2192GLIB_AVAILABLE_IN_ALL
2193gboolean g_type_test_flags (GType type,
2194 guint flags) G_GNUC_CONST;
2195
2196
2197/* --- debugging functions --- */
2198GLIB_AVAILABLE_IN_ALL
2199const gchar * g_type_name_from_instance (GTypeInstance *instance);
2200GLIB_AVAILABLE_IN_ALL
2201const gchar * g_type_name_from_class (GTypeClass *g_class);
2202
2203
2204/* --- implementation bits --- */
2205#ifndef G_DISABLE_CAST_CHECKS
2206# define _G_TYPE_CIC(ip, gt, ct) \
2207 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
2208# define _G_TYPE_CCC(cp, gt, ct) \
2209 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
2210#else /* G_DISABLE_CAST_CHECKS */
2211# define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
2212# define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
2213#endif /* G_DISABLE_CAST_CHECKS */
2214#define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
2215#define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
2216#define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
2217#define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
2218#define _G_TYPE_CIFT(ip, ft) (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft))
2219#ifdef __GNUC__
2220# define _G_TYPE_CIT(ip, gt) (G_GNUC_EXTENSION ({ \
2221 GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
2222 if (!__inst) \
2223 __r = FALSE; \
2224 else if (__inst->g_class && __inst->g_class->g_type == __t) \
2225 __r = TRUE; \
2226 else \
2227 __r = g_type_check_instance_is_a (__inst, __t); \
2228 __r; \
2229}))
2230# define _G_TYPE_CCT(cp, gt) (G_GNUC_EXTENSION ({ \
2231 GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
2232 if (!__class) \
2233 __r = FALSE; \
2234 else if (__class->g_type == __t) \
2235 __r = TRUE; \
2236 else \
2237 __r = g_type_check_class_is_a (__class, __t); \
2238 __r; \
2239}))
2240# define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \
2241 GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \
2242 if (!__val) \
2243 __r = FALSE; \
2244 else if (__val->g_type == __t) \
2245 __r = TRUE; \
2246 else \
2247 __r = g_type_check_value_holds (__val, __t); \
2248 __r; \
2249}))
2250#else /* !__GNUC__ */
2251# define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt))
2252# define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt))
2253# define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
2254#endif /* !__GNUC__ */
2255/**
2256 * G_TYPE_FLAG_RESERVED_ID_BIT:
2257 *
2258 * A bit in the type number that's supposed to be left untouched.
2259 */
2260#define G_TYPE_FLAG_RESERVED_ID_BIT ((GType) (1 << 0))
2261
2262G_END_DECLS
2263
2264#endif /* __G_TYPE_H__ */
2265