Update Friulian translation
[glib.git] / gobject / gtype.h
blobd010a31a87b179a22ddb7a8cb0d471c2f9ac0890
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
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.
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.
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/>.
17 #ifndef __G_TYPE_H__
18 #define __G_TYPE_H__
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
22 #endif
24 #include <glib.h>
26 G_BEGIN_DECLS
28 /* Basic Type Macros
30 /**
31 * G_TYPE_FUNDAMENTAL:
32 * @type: A #GType value.
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.
38 #define G_TYPE_FUNDAMENTAL(type) (g_type_fundamental (type))
39 /**
40 * G_TYPE_FUNDAMENTAL_MAX:
42 * An integer constant that represents the number of identifiers reserved
43 * for types that are assigned at compile-time.
45 #define G_TYPE_FUNDAMENTAL_MAX (255 << G_TYPE_FUNDAMENTAL_SHIFT)
47 /* Constant fundamental types,
49 /**
50 * G_TYPE_INVALID:
52 * An invalid #GType used as error return value in some functions which return
53 * a #GType.
55 #define G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL (0)
56 /**
57 * G_TYPE_NONE:
59 * A fundamental type which is used as a replacement for the C
60 * void return type.
62 #define G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL (1)
63 /**
64 * G_TYPE_INTERFACE:
66 * The fundamental type from which all interfaces are derived.
68 #define G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL (2)
69 /**
70 * G_TYPE_CHAR:
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".
76 #define G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL (3)
77 /**
78 * G_TYPE_UCHAR:
80 * The fundamental type corresponding to #guchar.
82 #define G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL (4)
83 /**
84 * G_TYPE_BOOLEAN:
86 * The fundamental type corresponding to #gboolean.
88 #define G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL (5)
89 /**
90 * G_TYPE_INT:
92 * The fundamental type corresponding to #gint.
94 #define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6)
95 /**
96 * G_TYPE_UINT:
98 * The fundamental type corresponding to #guint.
100 #define G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL (7)
102 * G_TYPE_LONG:
104 * The fundamental type corresponding to #glong.
106 #define G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL (8)
108 * G_TYPE_ULONG:
110 * The fundamental type corresponding to #gulong.
112 #define G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL (9)
114 * G_TYPE_INT64:
116 * The fundamental type corresponding to #gint64.
118 #define G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL (10)
120 * G_TYPE_UINT64:
122 * The fundamental type corresponding to #guint64.
124 #define G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL (11)
126 * G_TYPE_ENUM:
128 * The fundamental type from which all enumeration types are derived.
130 #define G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL (12)
132 * G_TYPE_FLAGS:
134 * The fundamental type from which all flags types are derived.
136 #define G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL (13)
138 * G_TYPE_FLOAT:
140 * The fundamental type corresponding to #gfloat.
142 #define G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL (14)
144 * G_TYPE_DOUBLE:
146 * The fundamental type corresponding to #gdouble.
148 #define G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL (15)
150 * G_TYPE_STRING:
152 * The fundamental type corresponding to nul-terminated C strings.
154 #define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16)
156 * G_TYPE_POINTER:
158 * The fundamental type corresponding to #gpointer.
160 #define G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL (17)
162 * G_TYPE_BOXED:
164 * The fundamental type from which all boxed types are derived.
166 #define G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL (18)
168 * G_TYPE_PARAM:
170 * The fundamental type from which all #GParamSpec types are derived.
172 #define G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL (19)
174 * G_TYPE_OBJECT:
176 * The fundamental type for #GObject.
178 #define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20)
180 * G_TYPE_VARIANT:
182 * The fundamental type corresponding to #GVariant.
184 * All floating #GVariant instances passed through the #GType system are
185 * consumed.
187 * Note that callbacks in closures, and signal handlers
188 * for signals of return type %G_TYPE_VARIANT, must never return floating
189 * variants.
191 * Note: GLib 2.24 did include a boxed type with this name. It was replaced
192 * with this fundamental type in 2.26.
194 * Since: 2.26
196 #define G_TYPE_VARIANT G_TYPE_MAKE_FUNDAMENTAL (21)
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.
204 * G_TYPE_FUNDAMENTAL_SHIFT:
206 * Shift value used in converting numbers to type IDs.
208 #define G_TYPE_FUNDAMENTAL_SHIFT (2)
210 * G_TYPE_MAKE_FUNDAMENTAL:
211 * @x: the fundamental type number.
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.
217 * Returns: the GType
219 #define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
221 * G_TYPE_RESERVED_GLIB_FIRST:
223 * First fundamental type number to create a new fundamental type id with
224 * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
226 #define G_TYPE_RESERVED_GLIB_FIRST (22)
228 * G_TYPE_RESERVED_GLIB_LAST:
230 * Last fundamental type number reserved for GLib.
232 #define G_TYPE_RESERVED_GLIB_LAST (31)
234 * G_TYPE_RESERVED_BSE_FIRST:
236 * First fundamental type number to create a new fundamental type id with
237 * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
239 #define G_TYPE_RESERVED_BSE_FIRST (32)
241 * G_TYPE_RESERVED_BSE_LAST:
243 * Last fundamental type number reserved for BSE.
245 #define G_TYPE_RESERVED_BSE_LAST (48)
247 * G_TYPE_RESERVED_USER_FIRST:
249 * First available fundamental type number to create new fundamental
250 * type id with G_TYPE_MAKE_FUNDAMENTAL().
252 #define G_TYPE_RESERVED_USER_FIRST (49)
255 /* Type Checking Macros
258 * G_TYPE_IS_FUNDAMENTAL:
259 * @type: A #GType value
261 * Checks if @type is a fundamental type.
263 * Returns: %TRUE on success
265 #define G_TYPE_IS_FUNDAMENTAL(type) ((type) <= G_TYPE_FUNDAMENTAL_MAX)
267 * G_TYPE_IS_DERIVED:
268 * @type: A #GType value
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).
274 * Returns: %TRUE on success
276 #define G_TYPE_IS_DERIVED(type) ((type) > G_TYPE_FUNDAMENTAL_MAX)
278 * G_TYPE_IS_INTERFACE:
279 * @type: A #GType value
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).
289 * Returns: %TRUE on success
291 #define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
293 * G_TYPE_IS_CLASSED:
294 * @type: A #GType value
296 * Checks if @type is a classed type.
298 * Returns: %TRUE on success
300 #define G_TYPE_IS_CLASSED(type) (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED))
302 * G_TYPE_IS_INSTANTIATABLE:
303 * @type: A #GType value
305 * Checks if @type can be instantiated. Instantiation is the
306 * process of creating an instance (object) of this type.
308 * Returns: %TRUE on success
310 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
312 * G_TYPE_IS_DERIVABLE:
313 * @type: A #GType value
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.
318 * Returns: %TRUE on success
320 #define G_TYPE_IS_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE))
322 * G_TYPE_IS_DEEP_DERIVABLE:
323 * @type: A #GType value
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.
328 * Returns: %TRUE on success
330 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
332 * G_TYPE_IS_ABSTRACT:
333 * @type: A #GType value
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.
339 * Returns: %TRUE on success
341 #define G_TYPE_IS_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))
343 * G_TYPE_IS_VALUE_ABSTRACT:
344 * @type: A #GType value
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.
350 * Returns: %TRUE on success
352 #define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
354 * G_TYPE_IS_VALUE_TYPE:
355 * @type: A #GType value
357 * Checks if @type is a value type and can be used with g_value_init().
359 * Returns: %TRUE on success
361 #define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type))
363 * G_TYPE_HAS_VALUE_TABLE:
364 * @type: A #GType value
366 * Checks if @type has a #GTypeValueTable.
368 * Returns: %TRUE on success
370 #define G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek (type) != NULL)
373 /* Typedefs
376 * GType:
378 * A numerical value which represents the unique identifier of a registered
379 * type.
381 #if GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus
382 typedef gsize GType;
383 #else /* for historic reasons, C++ links against gulong GTypes */
384 typedef gulong GType;
385 #endif
386 typedef struct _GValue GValue;
387 typedef union _GTypeCValue GTypeCValue;
388 typedef struct _GTypePlugin GTypePlugin;
389 typedef struct _GTypeClass GTypeClass;
390 typedef struct _GTypeInterface GTypeInterface;
391 typedef struct _GTypeInstance GTypeInstance;
392 typedef struct _GTypeInfo GTypeInfo;
393 typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
394 typedef struct _GInterfaceInfo GInterfaceInfo;
395 typedef struct _GTypeValueTable GTypeValueTable;
396 typedef struct _GTypeQuery GTypeQuery;
399 /* Basic Type Structures
402 * GTypeClass:
404 * An opaque structure used as the base of all classes.
406 struct _GTypeClass
408 /*< private >*/
409 GType g_type;
412 * GTypeInstance:
414 * An opaque structure used as the base of all type instances.
416 struct _GTypeInstance
418 /*< private >*/
419 GTypeClass *g_class;
422 * GTypeInterface:
424 * An opaque structure used as the base of all interface types.
426 struct _GTypeInterface
428 /*< private >*/
429 GType g_type; /* iface type */
430 GType g_instance_type;
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
439 * A structure holding information for a specific type.
440 * It is filled in by the g_type_query() function.
442 struct _GTypeQuery
444 GType type;
445 const gchar *type_name;
446 guint class_size;
447 guint instance_size;
451 /* Casts, checks and accessors for structured types
452 * usage of these macros is reserved to type implementations only
454 /*< protected >*/
456 * G_TYPE_CHECK_INSTANCE:
457 * @instance: Location of a #GTypeInstance structure
459 * Checks if @instance is a valid #GTypeInstance structure,
460 * otherwise issues a warning and returns %FALSE. %NULL is not a valid
461 * #GTypeInstance.
463 * This macro should only be used in type implementations.
465 * Returns: %TRUE on success
467 #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
469 * G_TYPE_CHECK_INSTANCE_CAST:
470 * @instance: (nullable): Location of a #GTypeInstance structure
471 * @g_type: The type to be returned
472 * @c_type: The corresponding C type of @g_type
474 * Checks that @instance is an instance of the type identified by @g_type
475 * and issues a warning if this is not the case. Returns @instance casted
476 * to a pointer to @c_type.
478 * No warning will be issued if @instance is %NULL, and %NULL will be returned.
480 * This macro should only be used in type implementations.
482 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
484 * G_TYPE_CHECK_INSTANCE_TYPE:
485 * @instance: (nullable): Location of a #GTypeInstance structure.
486 * @g_type: The type to be checked
488 * Checks if @instance is an instance of the type identified by @g_type. If
489 * @instance is %NULL, %FALSE will be returned.
491 * This macro should only be used in type implementations.
493 * Returns: %TRUE on success
495 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
497 * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE:
498 * @instance: (nullable): Location of a #GTypeInstance structure.
499 * @g_type: The fundamental type to be checked
501 * Checks if @instance is an instance of the fundamental type identified by @g_type.
502 * If @instance is %NULL, %FALSE will be returned.
504 * This macro should only be used in type implementations.
506 * Returns: %TRUE on success
508 #define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type) (_G_TYPE_CIFT ((instance), (g_type)))
510 * G_TYPE_INSTANCE_GET_CLASS:
511 * @instance: Location of the #GTypeInstance structure
512 * @g_type: The #GType of the class to be returned
513 * @c_type: The C type of the class structure
515 * Get the class structure of a given @instance, casted
516 * to a specified ancestor type @g_type of the instance.
518 * Note that while calling a GInstanceInitFunc(), the class pointer
519 * gets modified, so it might not always return the expected pointer.
521 * This macro should only be used in type implementations.
523 * Returns: a pointer to the class structure
525 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
527 * G_TYPE_INSTANCE_GET_INTERFACE:
528 * @instance: Location of the #GTypeInstance structure
529 * @g_type: The #GType of the interface to be returned
530 * @c_type: The C type of the interface structure
532 * Get the interface structure for interface @g_type of a given @instance.
534 * This macro should only be used in type implementations.
536 * Returns: a pointer to the interface structure
538 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
540 * G_TYPE_CHECK_CLASS_CAST:
541 * @g_class: Location of a #GTypeClass structure
542 * @g_type: The type to be returned
543 * @c_type: The corresponding C type of class structure of @g_type
545 * Checks that @g_class is a class structure of the type identified by @g_type
546 * and issues a warning if this is not the case. Returns @g_class casted
547 * to a pointer to @c_type. %NULL is not a valid class structure.
549 * This macro should only be used in type implementations.
551 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
553 * G_TYPE_CHECK_CLASS_TYPE:
554 * @g_class: (nullable): Location of a #GTypeClass structure
555 * @g_type: The type to be checked
557 * Checks if @g_class is a class structure of the type identified by
558 * @g_type. If @g_class is %NULL, %FALSE will be returned.
560 * This macro should only be used in type implementations.
562 * Returns: %TRUE on success
564 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
566 * G_TYPE_CHECK_VALUE:
567 * @value: a #GValue
569 * Checks if @value has been initialized to hold values
570 * of a value type.
572 * This macro should only be used in type implementations.
574 * Returns: %TRUE on success
576 #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
578 * G_TYPE_CHECK_VALUE_TYPE:
579 * @value: a #GValue
580 * @g_type: The type to be checked
582 * Checks if @value has been initialized to hold values
583 * of type @g_type.
585 * This macro should only be used in type implementations.
587 * Returns: %TRUE on success
589 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type)))
591 * G_TYPE_FROM_INSTANCE:
592 * @instance: Location of a valid #GTypeInstance structure
594 * Get the type identifier from a given @instance structure.
596 * This macro should only be used in type implementations.
598 * Returns: the #GType
600 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
602 * G_TYPE_FROM_CLASS:
603 * @g_class: Location of a valid #GTypeClass structure
605 * Get the type identifier from a given @class structure.
607 * This macro should only be used in type implementations.
609 * Returns: the #GType
611 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
613 * G_TYPE_FROM_INTERFACE:
614 * @g_iface: Location of a valid #GTypeInterface structure
616 * Get the type identifier from a given @interface structure.
618 * This macro should only be used in type implementations.
620 * Returns: the #GType
622 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
625 * G_TYPE_INSTANCE_GET_PRIVATE:
626 * @instance: the instance of a type deriving from @private_type
627 * @g_type: the type identifying which private data to retrieve
628 * @c_type: The C type for the private structure
630 * Gets the private structure for a particular type.
631 * The private structure must have been registered in the
632 * class_init function with g_type_class_add_private().
634 * This macro should only be used in type implementations.
636 * Since: 2.4
637 * Returns: (not nullable): a pointer to the private data structure
639 #define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type)))
642 * G_TYPE_CLASS_GET_PRIVATE:
643 * @klass: the class of a type deriving from @private_type
644 * @g_type: the type identifying which private data to retrieve
645 * @c_type: The C type for the private structure
647 * Gets the private class structure for a particular type.
648 * The private structure must have been registered in the
649 * get_type() function with g_type_add_class_private().
651 * This macro should only be used in type implementations.
653 * Since: 2.24
654 * Returns: (not nullable): a pointer to the private data structure
656 #define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type)))
659 * GTypeDebugFlags:
660 * @G_TYPE_DEBUG_NONE: Print no messages
661 * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping
662 * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions
663 * @G_TYPE_DEBUG_MASK: Mask covering all debug flags
664 * @G_TYPE_DEBUG_INSTANCE_COUNT: Keep a count of instances of each type
666 * These flags used to be passed to g_type_init_with_debug_flags() which
667 * is now deprecated.
669 * If you need to enable debugging features, use the GOBJECT_DEBUG
670 * environment variable.
672 * Deprecated: 2.36: g_type_init() is now done automatically
674 typedef enum /*< skip >*/
676 G_TYPE_DEBUG_NONE = 0,
677 G_TYPE_DEBUG_OBJECTS = 1 << 0,
678 G_TYPE_DEBUG_SIGNALS = 1 << 1,
679 G_TYPE_DEBUG_INSTANCE_COUNT = 1 << 2,
680 G_TYPE_DEBUG_MASK = 0x07
681 } GTypeDebugFlags;
684 /* --- prototypes --- */
685 GLIB_DEPRECATED_IN_2_36
686 void g_type_init (void);
687 GLIB_DEPRECATED_IN_2_36
688 void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags);
689 GLIB_AVAILABLE_IN_ALL
690 const gchar * g_type_name (GType type);
691 GLIB_AVAILABLE_IN_ALL
692 GQuark g_type_qname (GType type);
693 GLIB_AVAILABLE_IN_ALL
694 GType g_type_from_name (const gchar *name);
695 GLIB_AVAILABLE_IN_ALL
696 GType g_type_parent (GType type);
697 GLIB_AVAILABLE_IN_ALL
698 guint g_type_depth (GType type);
699 GLIB_AVAILABLE_IN_ALL
700 GType g_type_next_base (GType leaf_type,
701 GType root_type);
702 GLIB_AVAILABLE_IN_ALL
703 gboolean g_type_is_a (GType type,
704 GType is_a_type);
705 GLIB_AVAILABLE_IN_ALL
706 gpointer g_type_class_ref (GType type);
707 GLIB_AVAILABLE_IN_ALL
708 gpointer g_type_class_peek (GType type);
709 GLIB_AVAILABLE_IN_ALL
710 gpointer g_type_class_peek_static (GType type);
711 GLIB_AVAILABLE_IN_ALL
712 void g_type_class_unref (gpointer g_class);
713 GLIB_AVAILABLE_IN_ALL
714 gpointer g_type_class_peek_parent (gpointer g_class);
715 GLIB_AVAILABLE_IN_ALL
716 gpointer g_type_interface_peek (gpointer instance_class,
717 GType iface_type);
718 GLIB_AVAILABLE_IN_ALL
719 gpointer g_type_interface_peek_parent (gpointer g_iface);
721 GLIB_AVAILABLE_IN_ALL
722 gpointer g_type_default_interface_ref (GType g_type);
723 GLIB_AVAILABLE_IN_ALL
724 gpointer g_type_default_interface_peek (GType g_type);
725 GLIB_AVAILABLE_IN_ALL
726 void g_type_default_interface_unref (gpointer g_iface);
728 /* g_free() the returned arrays */
729 GLIB_AVAILABLE_IN_ALL
730 GType* g_type_children (GType type,
731 guint *n_children);
732 GLIB_AVAILABLE_IN_ALL
733 GType* g_type_interfaces (GType type,
734 guint *n_interfaces);
736 /* per-type _static_ data */
737 GLIB_AVAILABLE_IN_ALL
738 void g_type_set_qdata (GType type,
739 GQuark quark,
740 gpointer data);
741 GLIB_AVAILABLE_IN_ALL
742 gpointer g_type_get_qdata (GType type,
743 GQuark quark);
744 GLIB_AVAILABLE_IN_ALL
745 void g_type_query (GType type,
746 GTypeQuery *query);
748 GLIB_AVAILABLE_IN_2_44
749 int g_type_get_instance_count (GType type);
751 /* --- type registration --- */
753 * GBaseInitFunc:
754 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize
756 * A callback function used by the type system to do base initialization
757 * of the class structures of derived types. It is called as part of the
758 * initialization process of all derived classes and should reallocate
759 * or reset all dynamic class members copied over from the parent class.
760 * For example, class members (such as strings) that are not sufficiently
761 * handled by a plain memory copy of the parent class into the derived class
762 * have to be altered. See GClassInitFunc() for a discussion of the class
763 * initialization process.
765 typedef void (*GBaseInitFunc) (gpointer g_class);
767 * GBaseFinalizeFunc:
768 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
770 * A callback function used by the type system to finalize those portions
771 * of a derived types class structure that were setup from the corresponding
772 * GBaseInitFunc() function. Class finalization basically works the inverse
773 * way in which class initialization is performed.
774 * See GClassInitFunc() for a discussion of the class initialization process.
776 typedef void (*GBaseFinalizeFunc) (gpointer g_class);
778 * GClassInitFunc:
779 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize.
780 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
782 * A callback function used by the type system to initialize the class
783 * of a specific type. This function should initialize all static class
784 * members.
786 * The initialization process of a class involves:
788 * - Copying common members from the parent class over to the
789 * derived class structure.
790 * - Zero initialization of the remaining members not copied
791 * over from the parent class.
792 * - Invocation of the GBaseInitFunc() initializers of all parent
793 * types and the class' type.
794 * - Invocation of the class' GClassInitFunc() initializer.
796 * Since derived classes are partially initialized through a memory copy
797 * of the parent class, the general rule is that GBaseInitFunc() and
798 * GBaseFinalizeFunc() should take care of necessary reinitialization
799 * and release of those class members that were introduced by the type
800 * that specified these GBaseInitFunc()/GBaseFinalizeFunc().
801 * GClassInitFunc() should only care about initializing static
802 * class members, while dynamic class members (such as allocated strings
803 * or reference counted resources) are better handled by a GBaseInitFunc()
804 * for this type, so proper initialization of the dynamic class members
805 * is performed for class initialization of derived types as well.
807 * An example may help to correspond the intend of the different class
808 * initializers:
810 * |[<!-- language="C" -->
811 * typedef struct {
812 * GObjectClass parent_class;
813 * gint static_integer;
814 * gchar *dynamic_string;
815 * } TypeAClass;
816 * static void
817 * type_a_base_class_init (TypeAClass *class)
819 * class->dynamic_string = g_strdup ("some string");
821 * static void
822 * type_a_base_class_finalize (TypeAClass *class)
824 * g_free (class->dynamic_string);
826 * static void
827 * type_a_class_init (TypeAClass *class)
829 * class->static_integer = 42;
832 * typedef struct {
833 * TypeAClass parent_class;
834 * gfloat static_float;
835 * GString *dynamic_gstring;
836 * } TypeBClass;
837 * static void
838 * type_b_base_class_init (TypeBClass *class)
840 * class->dynamic_gstring = g_string_new ("some other string");
842 * static void
843 * type_b_base_class_finalize (TypeBClass *class)
845 * g_string_free (class->dynamic_gstring);
847 * static void
848 * type_b_class_init (TypeBClass *class)
850 * class->static_float = 3.14159265358979323846;
852 * ]|
853 * Initialization of TypeBClass will first cause initialization of
854 * TypeAClass (derived classes reference their parent classes, see
855 * g_type_class_ref() on this).
857 * Initialization of TypeAClass roughly involves zero-initializing its fields,
858 * then calling its GBaseInitFunc() type_a_base_class_init() to allocate
859 * its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
860 * type_a_class_init() to initialize its static members (static_integer).
861 * The first step in the initialization process of TypeBClass is then
862 * a plain memory copy of the contents of TypeAClass into TypeBClass and
863 * zero-initialization of the remaining fields in TypeBClass.
864 * The dynamic members of TypeAClass within TypeBClass now need
865 * reinitialization which is performed by calling type_a_base_class_init()
866 * with an argument of TypeBClass.
868 * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
869 * is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
870 * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
871 * is called to complete the initialization process with the static members
872 * (static_float).
874 * Corresponding finalization counter parts to the GBaseInitFunc() functions
875 * have to be provided to release allocated resources at class finalization
876 * time.
878 typedef void (*GClassInitFunc) (gpointer g_class,
879 gpointer class_data);
881 * GClassFinalizeFunc:
882 * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
883 * @class_data: The @class_data member supplied via the #GTypeInfo structure
885 * A callback function used by the type system to finalize a class.
886 * This function is rarely needed, as dynamically allocated class resources
887 * should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
888 * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
889 * structure of a static type is invalid, because classes of static types
890 * will never be finalized (they are artificially kept alive when their
891 * reference count drops to zero).
893 typedef void (*GClassFinalizeFunc) (gpointer g_class,
894 gpointer class_data);
896 * GInstanceInitFunc:
897 * @instance: The instance to initialize
898 * @g_class: (type GObject.TypeClass): The class of the type the instance is
899 * created for
901 * A callback function used by the type system to initialize a new
902 * instance of a type. This function initializes all instance members and
903 * allocates any resources required by it.
905 * Initialization of a derived instance involves calling all its parent
906 * types instance initializers, so the class member of the instance
907 * is altered during its initialization to always point to the class that
908 * belongs to the type the current initializer was introduced for.
910 * The extended members of @instance are guaranteed to have been filled with
911 * zeros before this function is called.
913 typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
914 gpointer g_class);
916 * GInterfaceInitFunc:
917 * @g_iface: (type GObject.TypeInterface): The interface structure to initialize
918 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
920 * A callback function used by the type system to initialize a new
921 * interface. This function should initialize all internal data and
922 * allocate any resources required by the interface.
924 * The members of @iface_data are guaranteed to have been filled with
925 * zeros before this function is called.
927 typedef void (*GInterfaceInitFunc) (gpointer g_iface,
928 gpointer iface_data);
930 * GInterfaceFinalizeFunc:
931 * @g_iface: (type GObject.TypeInterface): The interface structure to finalize
932 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
934 * A callback function used by the type system to finalize an interface.
935 * This function should destroy any internal data and release any resources
936 * allocated by the corresponding GInterfaceInitFunc() function.
938 typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
939 gpointer iface_data);
941 * GTypeClassCacheFunc:
942 * @cache_data: data that was given to the g_type_add_class_cache_func() call
943 * @g_class: (type GObject.TypeClass): The #GTypeClass structure which is
944 * unreferenced
946 * A callback function which is called when the reference count of a class
947 * drops to zero. It may use g_type_class_ref() to prevent the class from
948 * being freed. You should not call g_type_class_unref() from a
949 * #GTypeClassCacheFunc function to prevent infinite recursion, use
950 * g_type_class_unref_uncached() instead.
952 * The functions have to check the class id passed in to figure
953 * whether they actually want to cache the class of this type, since all
954 * classes are routed through the same #GTypeClassCacheFunc chain.
956 * Returns: %TRUE to stop further #GTypeClassCacheFuncs from being
957 * called, %FALSE to continue
959 typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
960 GTypeClass *g_class);
962 * GTypeInterfaceCheckFunc:
963 * @check_data: data passed to g_type_add_interface_check()
964 * @g_iface: (type GObject.TypeInterface): the interface that has been
965 * initialized
967 * A callback called after an interface vtable is initialized.
968 * See g_type_add_interface_check().
970 * Since: 2.4
972 typedef void (*GTypeInterfaceCheckFunc) (gpointer check_data,
973 gpointer g_iface);
975 * GTypeFundamentalFlags:
976 * @G_TYPE_FLAG_CLASSED: Indicates a classed type
977 * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed)
978 * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type
979 * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable)
981 * Bit masks used to check or determine specific characteristics of a
982 * fundamental type.
984 typedef enum /*< skip >*/
986 G_TYPE_FLAG_CLASSED = (1 << 0),
987 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
988 G_TYPE_FLAG_DERIVABLE = (1 << 2),
989 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
990 } GTypeFundamentalFlags;
992 * GTypeFlags:
993 * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
994 * created for an abstract type
995 * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
996 * that introduces a value table, but can't be used for
997 * g_value_init()
999 * Bit masks used to check or determine characteristics of a type.
1001 typedef enum /*< skip >*/
1003 G_TYPE_FLAG_ABSTRACT = (1 << 4),
1004 G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5)
1005 } GTypeFlags;
1007 * GTypeInfo:
1008 * @class_size: Size of the class structure (required for interface, classed and instantiatable types)
1009 * @base_init: Location of the base initialization function (optional)
1010 * @base_finalize: Location of the base finalization function (optional)
1011 * @class_init: Location of the class initialization function for
1012 * classed and instantiatable types. Location of the default vtable
1013 * inititalization function for interface types. (optional) This function
1014 * is used both to fill in virtual functions in the class or default vtable,
1015 * and to do type-specific setup such as registering signals and object
1016 * properties.
1017 * @class_finalize: Location of the class finalization function for
1018 * classed and instantiatable types. Location of the default vtable
1019 * finalization function for interface types. (optional)
1020 * @class_data: User-supplied data passed to the class init/finalize functions
1021 * @instance_size: Size of the instance (object) structure (required for instantiatable types only)
1022 * @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.
1023 * @instance_init: Location of the instance initialization function (optional, for instantiatable types only)
1024 * @value_table: A #GTypeValueTable function table for generic handling of GValues
1025 * of this type (usually only useful for fundamental types)
1027 * This structure is used to provide the type system with the information
1028 * required to initialize and destruct (finalize) a type's class and
1029 * its instances.
1031 * The initialized structure is passed to the g_type_register_static() function
1032 * (or is copied into the provided #GTypeInfo structure in the
1033 * g_type_plugin_complete_type_info()). The type system will perform a deep
1034 * copy of this structure, so its memory does not need to be persistent
1035 * across invocation of g_type_register_static().
1037 struct _GTypeInfo
1039 /* interface types, classed types, instantiated types */
1040 guint16 class_size;
1042 GBaseInitFunc base_init;
1043 GBaseFinalizeFunc base_finalize;
1045 /* interface types, classed types, instantiated types */
1046 GClassInitFunc class_init;
1047 GClassFinalizeFunc class_finalize;
1048 gconstpointer class_data;
1050 /* instantiated types */
1051 guint16 instance_size;
1052 guint16 n_preallocs;
1053 GInstanceInitFunc instance_init;
1055 /* value handling */
1056 const GTypeValueTable *value_table;
1059 * GTypeFundamentalInfo:
1060 * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type
1062 * A structure that provides information to the type system which is
1063 * used specifically for managing fundamental types.
1065 struct _GTypeFundamentalInfo
1067 GTypeFundamentalFlags type_flags;
1070 * GInterfaceInfo:
1071 * @interface_init: location of the interface initialization function
1072 * @interface_finalize: location of the interface finalization function
1073 * @interface_data: user-supplied data passed to the interface init/finalize functions
1075 * A structure that provides information to the type system which is
1076 * used specifically for managing interface types.
1078 struct _GInterfaceInfo
1080 GInterfaceInitFunc interface_init;
1081 GInterfaceFinalizeFunc interface_finalize;
1082 gpointer interface_data;
1085 * GTypeValueTable:
1086 * @value_init: Default initialize @values contents by poking values
1087 * directly into the value->data array. The data array of
1088 * the #GValue passed into this function was zero-filled
1089 * with `memset()`, so no care has to be taken to free any
1090 * old contents. E.g. for the implementation of a string
1091 * value that may never be %NULL, the implementation might
1092 * look like:
1093 * |[<!-- language="C" -->
1094 * value->data[0].v_pointer = g_strdup ("");
1095 * ]|
1096 * @value_free: Free any old contents that might be left in the
1097 * data array of the passed in @value. No resources may
1098 * remain allocated through the #GValue contents after
1099 * this function returns. E.g. for our above string type:
1100 * |[<!-- language="C" -->
1101 * // only free strings without a specific flag for static storage
1102 * if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1103 * g_free (value->data[0].v_pointer);
1104 * ]|
1105 * @value_copy: @dest_value is a #GValue with zero-filled data section
1106 * and @src_value is a properly setup #GValue of same or
1107 * derived type.
1108 * The purpose of this function is to copy the contents of
1109 * @src_value into @dest_value in a way, that even after
1110 * @src_value has been freed, the contents of @dest_value
1111 * remain valid. String type example:
1112 * |[<!-- language="C" -->
1113 * dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
1114 * ]|
1115 * @value_peek_pointer: If the value contents fit into a pointer, such as objects
1116 * or strings, return this pointer, so the caller can peek at
1117 * the current contents. To extend on our above string example:
1118 * |[<!-- language="C" -->
1119 * return value->data[0].v_pointer;
1120 * ]|
1121 * @collect_format: A string format describing how to collect the contents of
1122 * this value bit-by-bit. Each character in the format represents
1123 * an argument to be collected, and the characters themselves indicate
1124 * the type of the argument. Currently supported arguments are:
1125 * - 'i' - Integers. passed as collect_values[].v_int.
1126 * - 'l' - Longs. passed as collect_values[].v_long.
1127 * - 'd' - Doubles. passed as collect_values[].v_double.
1128 * - 'p' - Pointers. passed as collect_values[].v_pointer.
1129 * It should be noted that for variable argument list construction,
1130 * ANSI C promotes every type smaller than an integer to an int, and
1131 * floats to doubles. So for collection of short int or char, 'i'
1132 * needs to be used, and for collection of floats 'd'.
1133 * @collect_value: The collect_value() function is responsible for converting the
1134 * values collected from a variable argument list into contents
1135 * suitable for storage in a GValue. This function should setup
1136 * @value similar to value_init(); e.g. for a string value that
1137 * does not allow %NULL pointers, it needs to either spew an error,
1138 * or do an implicit conversion by storing an empty string.
1139 * The @value passed in to this function has a zero-filled data
1140 * array, so just like for value_init() it is guaranteed to not
1141 * contain any old contents that might need freeing.
1142 * @n_collect_values is exactly the string length of @collect_format,
1143 * and @collect_values is an array of unions #GTypeCValue with
1144 * length @n_collect_values, containing the collected values
1145 * according to @collect_format.
1146 * @collect_flags is an argument provided as a hint by the caller.
1147 * It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating,
1148 * that the collected value contents may be considered "static"
1149 * for the duration of the @value lifetime.
1150 * Thus an extra copy of the contents stored in @collect_values is
1151 * not required for assignment to @value.
1152 * For our above string example, we continue with:
1153 * |[<!-- language="C" -->
1154 * if (!collect_values[0].v_pointer)
1155 * value->data[0].v_pointer = g_strdup ("");
1156 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1158 * value->data[0].v_pointer = collect_values[0].v_pointer;
1159 * // keep a flag for the value_free() implementation to not free this string
1160 * value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
1162 * else
1163 * value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
1164 * return NULL;
1165 * ]|
1166 * It should be noted, that it is generally a bad idea to follow the
1167 * #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
1168 * reentrancy requirements and reference count assertions performed
1169 * by the signal emission code, reference counts should always be
1170 * incremented for reference counted contents stored in the value->data
1171 * array. To deviate from our string example for a moment, and taking
1172 * a look at an exemplary implementation for collect_value() of
1173 * #GObject:
1174 * |[<!-- language="C" -->
1175 * if (collect_values[0].v_pointer)
1177 * GObject *object = G_OBJECT (collect_values[0].v_pointer);
1178 * // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
1179 * value->data[0].v_pointer = g_object_ref (object);
1180 * return NULL;
1182 * else
1183 * return g_strdup_printf ("Object passed as invalid NULL pointer");
1185 * ]|
1186 * The reference count for valid objects is always incremented,
1187 * regardless of @collect_flags. For invalid objects, the example
1188 * returns a newly allocated string without altering @value.
1189 * Upon success, collect_value() needs to return %NULL. If, however,
1190 * an error condition occurred, collect_value() may spew an
1191 * error by returning a newly allocated non-%NULL string, giving
1192 * a suitable description of the error condition.
1193 * The calling code makes no assumptions about the @value
1194 * contents being valid upon error returns, @value
1195 * is simply thrown away without further freeing. As such, it is
1196 * a good idea to not allocate #GValue contents, prior to returning
1197 * an error, however, collect_values() is not obliged to return
1198 * a correctly setup @value for error returns, simply because
1199 * any non-%NULL return is considered a fatal condition so further
1200 * program behaviour is undefined.
1201 * @lcopy_format: Format description of the arguments to collect for @lcopy_value,
1202 * analogous to @collect_format. Usually, @lcopy_format string consists
1203 * only of 'p's to provide lcopy_value() with pointers to storage locations.
1204 * @lcopy_value: This function is responsible for storing the @value contents into
1205 * arguments passed through a variable argument list which got
1206 * collected into @collect_values according to @lcopy_format.
1207 * @n_collect_values equals the string length of @lcopy_format,
1208 * and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS.
1209 * In contrast to collect_value(), lcopy_value() is obliged to
1210 * always properly support %G_VALUE_NOCOPY_CONTENTS.
1211 * Similar to collect_value() the function may prematurely abort
1212 * by returning a newly allocated string describing an error condition.
1213 * To complete the string example:
1214 * |[<!-- language="C" -->
1215 * gchar **string_p = collect_values[0].v_pointer;
1216 * if (!string_p)
1217 * return g_strdup_printf ("string location passed as NULL");
1218 * if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1219 * *string_p = value->data[0].v_pointer;
1220 * else
1221 * *string_p = g_strdup (value->data[0].v_pointer);
1222 * ]|
1223 * And an illustrative version of lcopy_value() for
1224 * reference-counted types:
1225 * |[<!-- language="C" -->
1226 * GObject **object_p = collect_values[0].v_pointer;
1227 * if (!object_p)
1228 * return g_strdup_printf ("object location passed as NULL");
1229 * if (!value->data[0].v_pointer)
1230 * *object_p = NULL;
1231 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
1232 * *object_p = value->data[0].v_pointer;
1233 * else
1234 * *object_p = g_object_ref (value->data[0].v_pointer);
1235 * return NULL;
1236 * ]|
1238 * The #GTypeValueTable provides the functions required by the #GValue
1239 * implementation, to serve as a container for values of a type.
1242 struct _GTypeValueTable
1244 void (*value_init) (GValue *value);
1245 void (*value_free) (GValue *value);
1246 void (*value_copy) (const GValue *src_value,
1247 GValue *dest_value);
1248 /* varargs functionality (optional) */
1249 gpointer (*value_peek_pointer) (const GValue *value);
1250 const gchar *collect_format;
1251 gchar* (*collect_value) (GValue *value,
1252 guint n_collect_values,
1253 GTypeCValue *collect_values,
1254 guint collect_flags);
1255 const gchar *lcopy_format;
1256 gchar* (*lcopy_value) (const GValue *value,
1257 guint n_collect_values,
1258 GTypeCValue *collect_values,
1259 guint collect_flags);
1261 GLIB_AVAILABLE_IN_ALL
1262 GType g_type_register_static (GType parent_type,
1263 const gchar *type_name,
1264 const GTypeInfo *info,
1265 GTypeFlags flags);
1266 GLIB_AVAILABLE_IN_ALL
1267 GType g_type_register_static_simple (GType parent_type,
1268 const gchar *type_name,
1269 guint class_size,
1270 GClassInitFunc class_init,
1271 guint instance_size,
1272 GInstanceInitFunc instance_init,
1273 GTypeFlags flags);
1275 GLIB_AVAILABLE_IN_ALL
1276 GType g_type_register_dynamic (GType parent_type,
1277 const gchar *type_name,
1278 GTypePlugin *plugin,
1279 GTypeFlags flags);
1280 GLIB_AVAILABLE_IN_ALL
1281 GType g_type_register_fundamental (GType type_id,
1282 const gchar *type_name,
1283 const GTypeInfo *info,
1284 const GTypeFundamentalInfo *finfo,
1285 GTypeFlags flags);
1286 GLIB_AVAILABLE_IN_ALL
1287 void g_type_add_interface_static (GType instance_type,
1288 GType interface_type,
1289 const GInterfaceInfo *info);
1290 GLIB_AVAILABLE_IN_ALL
1291 void g_type_add_interface_dynamic (GType instance_type,
1292 GType interface_type,
1293 GTypePlugin *plugin);
1294 GLIB_AVAILABLE_IN_ALL
1295 void g_type_interface_add_prerequisite (GType interface_type,
1296 GType prerequisite_type);
1297 GLIB_AVAILABLE_IN_ALL
1298 GType*g_type_interface_prerequisites (GType interface_type,
1299 guint *n_prerequisites);
1300 GLIB_AVAILABLE_IN_ALL
1301 void g_type_class_add_private (gpointer g_class,
1302 gsize private_size);
1303 GLIB_AVAILABLE_IN_2_38
1304 gint g_type_add_instance_private (GType class_type,
1305 gsize private_size);
1306 GLIB_AVAILABLE_IN_ALL
1307 gpointer g_type_instance_get_private (GTypeInstance *instance,
1308 GType private_type);
1309 GLIB_AVAILABLE_IN_2_38
1310 void g_type_class_adjust_private_offset (gpointer g_class,
1311 gint *private_size_or_offset);
1313 GLIB_AVAILABLE_IN_ALL
1314 void g_type_add_class_private (GType class_type,
1315 gsize private_size);
1316 GLIB_AVAILABLE_IN_ALL
1317 gpointer g_type_class_get_private (GTypeClass *klass,
1318 GType private_type);
1319 GLIB_AVAILABLE_IN_2_38
1320 gint g_type_class_get_instance_private_offset (gpointer g_class);
1322 GLIB_AVAILABLE_IN_2_34
1323 void g_type_ensure (GType type);
1324 GLIB_AVAILABLE_IN_2_36
1325 guint g_type_get_type_registration_serial (void);
1328 /* --- GType boilerplate --- */
1330 * G_DECLARE_FINAL_TYPE:
1331 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1332 * @module_obj_name: The name of the new type in lowercase, with words
1333 * separated by '_' (like 'gtk_widget')
1334 * @MODULE: The name of the module, in all caps (like 'GTK')
1335 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1336 * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1338 * A convenience macro for emitting the usual declarations in the header file for a type which is not (at the
1339 * present time) intended to be subclassed.
1341 * You might use it in a header as follows:
1343 * |[
1344 * #ifndef _myapp_window_h_
1345 * #define _myapp_window_h_
1347 * #include <gtk/gtk.h>
1349 * #define MY_APP_TYPE_WINDOW my_app_window_get_type ()
1350 * G_DECLARE_FINAL_TYPE (MyAppWindow, my_app_window, MY_APP, WINDOW, GtkWindow)
1352 * MyAppWindow * my_app_window_new (void);
1354 * ...
1356 * #endif
1357 * ]|
1359 * This results in the following things happening:
1361 * - the usual my_app_window_get_type() function is declared with a return type of #GType
1363 * - the MyAppWindow types is defined as a typedef of struct _MyAppWindow. The struct itself is not
1364 * defined and should be defined from the .c file before G_DEFINE_TYPE() is used.
1366 * - the MY_APP_WINDOW() cast is emitted as static inline function along with the MY_APP_IS_WINDOW() type
1367 * checking function
1369 * - the MyAppWindowClass type is defined as a struct containing GtkWindowClass. This is done for the
1370 * convenience of the person defining the type and should not be considered to be part of the ABI. In
1371 * particular, without a firm declaration of the instance structure, it is not possible to subclass the type
1372 * and therefore the fact that the size of the class structure is exposed is not a concern and it can be
1373 * freely changed at any point in the future.
1375 * - g_autoptr() support being added for your type, based on the type of your parent class
1377 * You can only use this function if your parent type also supports g_autoptr().
1379 * Because the type macro (MY_APP_TYPE_WINDOW in the above example) is not a callable, you must continue to
1380 * manually define this as a macro for yourself.
1382 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1383 * to be used in the usual way with export control and API versioning macros.
1385 * If you want to declare your own class structure, use G_DECLARE_DERIVABLE_TYPE().
1387 * If you are writing a library, it is important to note that it is possible to convert a type from using
1388 * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you
1389 * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1390 * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or
1391 * reorder items without breaking the API and/or ABI.
1393 * Since: 2.44
1395 #define G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1396 GType module_obj_name##_get_type (void); \
1397 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1398 typedef struct _##ModuleObjName ModuleObjName; \
1399 typedef struct { ParentName##Class parent_class; } ModuleObjName##Class; \
1401 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
1403 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1404 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1405 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1406 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1407 G_GNUC_END_IGNORE_DEPRECATIONS
1410 * G_DECLARE_DERIVABLE_TYPE:
1411 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1412 * @module_obj_name: The name of the new type in lowercase, with words
1413 * separated by '_' (like 'gtk_widget')
1414 * @MODULE: The name of the module, in all caps (like 'GTK')
1415 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1416 * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1418 * A convenience macro for emitting the usual declarations in the header file for a type which will is intended
1419 * to be subclassed.
1421 * You might use it in a header as follows:
1423 * |[
1424 * #ifndef _gtk_frobber_h_
1425 * #define _gtk_frobber_h_
1427 * #define GTK_TYPE_FROBBER gtk_frobber_get_type ()
1428 * GDK_AVAILABLE_IN_3_12
1429 * G_DECLARE_DERIVABLE_TYPE (GtkFrobber, gtk_frobber, GTK, FROBBER, GtkWidget)
1431 * struct _GtkFrobberClass
1433 * GtkWidgetClass parent_class;
1435 * void (* handle_frob) (GtkFrobber *frobber,
1436 * guint n_frobs);
1438 * gpointer padding[12];
1439 * };
1441 * GtkWidget * gtk_frobber_new (void);
1443 * ...
1445 * #endif
1446 * ]|
1448 * This results in the following things happening:
1450 * - the usual gtk_frobber_get_type() function is declared with a return type of #GType
1452 * - the GtkFrobber struct is created with GtkWidget as the first and only item. You are expected to use
1453 * a private structure from your .c file to store your instance variables.
1455 * - the GtkFrobberClass type is defined as a typedef to struct _GtkFrobberClass, which is left undefined.
1456 * You should do this from the header file directly after you use the macro.
1458 * - the GTK_FROBBER() and GTK_FROBBER_CLASS() casts are emitted as static inline functions along with
1459 * the GTK_IS_FROBBER() and GTK_IS_FROBBER_CLASS() type checking functions and GTK_FROBBER_GET_CLASS()
1460 * function.
1462 * - g_autoptr() support being added for your type, based on the type of your parent class
1464 * You can only use this function if your parent type also supports g_autoptr().
1466 * Because the type macro (GTK_TYPE_FROBBER in the above example) is not a callable, you must continue to
1467 * manually define this as a macro for yourself.
1469 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1470 * to be used in the usual way with export control and API versioning macros.
1472 * If you are writing a library, it is important to note that it is possible to convert a type from using
1473 * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you
1474 * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1475 * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or
1476 * reorder items without breaking the API and/or ABI. If you want to declare your own class structure, use
1477 * G_DECLARE_DERIVABLE_TYPE(). If you want to declare a class without exposing the class or instance
1478 * structures, use G_DECLARE_FINAL_TYPE().
1480 * If you must use G_DECLARE_DERIVABLE_TYPE() you should be sure to include some padding at the bottom of your
1481 * class structure to leave space for the addition of future virtual functions.
1483 * Since: 2.44
1485 #define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1486 GType module_obj_name##_get_type (void); \
1487 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1488 typedef struct _##ModuleObjName ModuleObjName; \
1489 typedef struct _##ModuleObjName##Class ModuleObjName##Class; \
1490 struct _##ModuleObjName { ParentName parent_instance; }; \
1492 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
1494 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1495 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1496 static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_CLASS (gpointer ptr) { \
1497 return G_TYPE_CHECK_CLASS_CAST (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
1498 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1499 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1500 static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS (gpointer ptr) { \
1501 return G_TYPE_CHECK_CLASS_TYPE (ptr, module_obj_name##_get_type ()); } \
1502 static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_GET_CLASS (gpointer ptr) { \
1503 return G_TYPE_INSTANCE_GET_CLASS (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
1504 G_GNUC_END_IGNORE_DEPRECATIONS
1507 * G_DECLARE_INTERFACE:
1508 * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1509 * @module_obj_name: The name of the new type in lowercase, with words
1510 * separated by '_' (like 'gtk_widget')
1511 * @MODULE: The name of the module, in all caps (like 'GTK')
1512 * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1513 * @PrerequisiteName: the name of the prerequisite type, in camel case (like GtkWidget)
1515 * A convenience macro for emitting the usual declarations in the header file for a GInterface type.
1517 * You might use it in a header as follows:
1519 * |[
1520 * #ifndef _my_model_h_
1521 * #define _my_model_h_
1523 * #define MY_TYPE_MODEL my_model_get_type ()
1524 * GDK_AVAILABLE_IN_3_12
1525 * G_DECLARE_INTERFACE (MyModel, my_model, MY, MODEL, GObject)
1527 * struct _MyModelInterface
1529 * GTypeInterface g_iface;
1531 * gpointer (* get_item) (MyModel *model);
1532 * };
1534 * gpointer my_model_get_item (MyModel *model);
1536 * ...
1538 * #endif
1539 * ]|
1541 * This results in the following things happening:
1543 * - the usual my_model_get_type() function is declared with a return type of #GType
1545 * - the MyModelInterface type is defined as a typedef to struct _MyModelInterface,
1546 * which is left undefined. You should do this from the header file directly after
1547 * you use the macro.
1549 * - the MY_MODEL() cast is emitted as static inline functions along with
1550 * the MY_IS_MODEL() type checking function and MY_MODEL_GET_IFACE() function.
1552 * - g_autoptr() support being added for your type, based on your prerequisite type.
1554 * You can only use this function if your prerequisite type also supports g_autoptr().
1556 * Because the type macro (MY_TYPE_MODEL in the above example) is not a callable, you must continue to
1557 * manually define this as a macro for yourself.
1559 * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro
1560 * to be used in the usual way with export control and API versioning macros.
1562 * Since: 2.44
1564 #define G_DECLARE_INTERFACE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, PrerequisiteName) \
1565 GType module_obj_name##_get_type (void); \
1566 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
1567 typedef struct _##ModuleObjName ModuleObjName; \
1568 typedef struct _##ModuleObjName##Interface ModuleObjName##Interface; \
1570 _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, PrerequisiteName) \
1572 static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
1573 return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
1574 static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
1575 return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
1576 static inline ModuleObjName##Interface * MODULE##_##OBJ_NAME##_GET_IFACE (gpointer ptr) { \
1577 return G_TYPE_INSTANCE_GET_INTERFACE (ptr, module_obj_name##_get_type (), ModuleObjName##Interface); } \
1578 G_GNUC_END_IGNORE_DEPRECATIONS
1581 * G_DEFINE_TYPE:
1582 * @TN: The name of the new type, in Camel case.
1583 * @t_n: The name of the new type, in lowercase, with words
1584 * separated by '_'.
1585 * @T_P: The #GType of the parent type.
1587 * A convenience macro for type implementations, which declares a class
1588 * initialization function, an instance initialization function (see #GTypeInfo
1589 * for information about these) and a static variable named `t_n_parent_class`
1590 * pointing to the parent class. Furthermore, it defines a *_get_type() function.
1591 * See G_DEFINE_TYPE_EXTENDED() for an example.
1593 * Since: 2.4
1595 #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
1597 * G_DEFINE_TYPE_WITH_CODE:
1598 * @TN: The name of the new type, in Camel case.
1599 * @t_n: The name of the new type in lowercase, with words separated by '_'.
1600 * @T_P: The #GType of the parent type.
1601 * @_C_: Custom code that gets inserted in the *_get_type() function.
1603 * A convenience macro for type implementations.
1604 * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the
1605 * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
1606 * See G_DEFINE_TYPE_EXTENDED() for an example.
1608 * Since: 2.4
1610 #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()
1612 * G_DEFINE_TYPE_WITH_PRIVATE:
1613 * @TN: The name of the new type, in Camel case.
1614 * @t_n: The name of the new type, in lowercase, with words
1615 * separated by '_'.
1616 * @T_P: The #GType of the parent type.
1618 * A convenience macro for type implementations, which declares a class
1619 * initialization function, an instance initialization function (see #GTypeInfo
1620 * for information about these), a static variable named `t_n_parent_class`
1621 * pointing to the parent class, and adds private instance data to the type.
1622 * Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED()
1623 * for an example.
1625 * Note that private structs added with this macros must have a struct
1626 * name of the form @TN Private.
1628 * Since: 2.38
1630 #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))
1632 * G_DEFINE_ABSTRACT_TYPE:
1633 * @TN: The name of the new type, in Camel case.
1634 * @t_n: The name of the new type, in lowercase, with words
1635 * separated by '_'.
1636 * @T_P: The #GType of the parent type.
1638 * A convenience macro for type implementations.
1639 * Similar to G_DEFINE_TYPE(), but defines an abstract type.
1640 * See G_DEFINE_TYPE_EXTENDED() for an example.
1642 * Since: 2.4
1644 #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
1646 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE:
1647 * @TN: The name of the new type, in Camel case.
1648 * @t_n: The name of the new type, in lowercase, with words
1649 * separated by '_'.
1650 * @T_P: The #GType of the parent type.
1651 * @_C_: Custom code that gets inserted in the @type_name_get_type() function.
1653 * A convenience macro for type implementations.
1654 * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and
1655 * allows you to insert custom code into the *_get_type() function, e.g.
1656 * interface implementations via G_IMPLEMENT_INTERFACE().
1657 * See G_DEFINE_TYPE_EXTENDED() for an example.
1659 * Since: 2.4
1661 #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()
1663 * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE:
1664 * @TN: The name of the new type, in Camel case.
1665 * @t_n: The name of the new type, in lowercase, with words
1666 * separated by '_'.
1667 * @T_P: The #GType of the parent type.
1669 * Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type.
1670 * See G_DEFINE_TYPE_EXTENDED() for an example.
1672 * Since: 2.38
1674 #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))
1676 * G_DEFINE_TYPE_EXTENDED:
1677 * @TN: The name of the new type, in Camel case.
1678 * @t_n: The name of the new type, in lowercase, with words
1679 * separated by '_'.
1680 * @T_P: The #GType of the parent type.
1681 * @_f_: #GTypeFlags to pass to g_type_register_static()
1682 * @_C_: Custom code that gets inserted in the *_get_type() function.
1684 * The most general convenience macro for type implementations, on which
1685 * G_DEFINE_TYPE(), etc are based.
1687 * |[<!-- language="C" -->
1688 * G_DEFINE_TYPE_EXTENDED (GtkGadget,
1689 * gtk_gadget,
1690 * GTK_TYPE_WIDGET,
1691 * 0,
1692 * G_IMPLEMENT_INTERFACE (TYPE_GIZMO,
1693 * gtk_gadget_gizmo_init));
1694 * ]|
1695 * expands to
1696 * |[<!-- language="C" -->
1697 * static void gtk_gadget_init (GtkGadget *self);
1698 * static void gtk_gadget_class_init (GtkGadgetClass *klass);
1699 * static gpointer gtk_gadget_parent_class = NULL;
1700 * static void gtk_gadget_class_intern_init (gpointer klass)
1702 * gtk_gadget_parent_class = g_type_class_peek_parent (klass);
1703 * gtk_gadget_class_init ((GtkGadgetClass*) klass);
1706 * GType
1707 * gtk_gadget_get_type (void)
1709 * static volatile gsize g_define_type_id__volatile = 0;
1710 * if (g_once_init_enter (&g_define_type_id__volatile))
1712 * GType g_define_type_id =
1713 * g_type_register_static_simple (GTK_TYPE_WIDGET,
1714 * g_intern_static_string ("GtkGadget"),
1715 * sizeof (GtkGadgetClass),
1716 * (GClassInitFunc) gtk_gadget_class_intern_init,
1717 * sizeof (GtkGadget),
1718 * (GInstanceInitFunc) gtk_gadget_init,
1719 * 0);
1721 * const GInterfaceInfo g_implement_interface_info = {
1722 * (GInterfaceInitFunc) gtk_gadget_gizmo_init
1723 * };
1724 * g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
1726 * g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
1728 * return g_define_type_id__volatile;
1730 * ]|
1731 * The only pieces which have to be manually provided are the definitions of
1732 * the instance and class structure and the definitions of the instance and
1733 * class init functions.
1735 * Since: 2.4
1737 #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()
1740 * G_DEFINE_INTERFACE:
1741 * @TN: The name of the new type, in Camel case.
1742 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1743 * @T_P: The #GType of the prerequisite type for the interface, or 0
1744 * (%G_TYPE_INVALID) for no prerequisite type.
1746 * A convenience macro for #GTypeInterface definitions, which declares
1747 * a default vtable initialization function and defines a *_get_type()
1748 * function.
1750 * The macro expects the interface initialization function to have the
1751 * name `t_n ## _default_init`, and the interface structure to have the
1752 * name `TN ## Interface`.
1754 * Since: 2.24
1756 #define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
1759 * G_DEFINE_INTERFACE_WITH_CODE:
1760 * @TN: The name of the new type, in Camel case.
1761 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1762 * @T_P: The #GType of the prerequisite type for the interface, or 0
1763 * (%G_TYPE_INVALID) for no prerequisite type.
1764 * @_C_: Custom code that gets inserted in the *_get_type() function.
1766 * A convenience macro for #GTypeInterface definitions. Similar to
1767 * G_DEFINE_INTERFACE(), but allows you to insert custom code into the
1768 * *_get_type() function, e.g. additional interface implementations
1769 * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See
1770 * G_DEFINE_TYPE_EXTENDED() for a similar example using
1771 * G_DEFINE_TYPE_WITH_CODE().
1773 * Since: 2.24
1775 #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()
1778 * G_IMPLEMENT_INTERFACE:
1779 * @TYPE_IFACE: The #GType of the interface to add
1780 * @iface_init: The interface init function
1782 * A convenience macro to ease interface addition in the `_C_` section
1783 * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1784 * See G_DEFINE_TYPE_EXTENDED() for an example.
1786 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1787 * macros, since it depends on variable names from those macros.
1789 * Since: 2.4
1791 #define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
1792 const GInterfaceInfo g_implement_interface_info = { \
1793 (GInterfaceInitFunc) iface_init, NULL, NULL \
1794 }; \
1795 g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
1799 * G_ADD_PRIVATE:
1800 * @TypeName: the name of the type in CamelCase
1802 * A convenience macro to ease adding private data to instances of a new type
1803 * in the @_C_ section of G_DEFINE_TYPE_WITH_CODE() or
1804 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1806 * For instance:
1808 * |[<!-- language="C" -->
1809 * typedef struct _MyObject MyObject;
1810 * typedef struct _MyObjectClass MyObjectClass;
1812 * typedef struct {
1813 * gint foo;
1814 * gint bar;
1815 * } MyObjectPrivate;
1817 * G_DEFINE_TYPE_WITH_CODE (MyObject, my_object, G_TYPE_OBJECT,
1818 * G_ADD_PRIVATE (MyObject))
1819 * ]|
1821 * Will add MyObjectPrivate as the private data to any instance of the MyObject
1822 * type.
1824 * G_DEFINE_TYPE_* macros will automatically create a private function
1825 * based on the arguments to this macro, which can be used to safely
1826 * retrieve the private data from an instance of the type; for instance:
1828 * |[<!-- language="C" -->
1829 * gint
1830 * my_object_get_foo (MyObject *obj)
1832 * MyObjectPrivate *priv = my_object_get_instance_private (obj);
1834 * g_return_val_if_fail (MY_IS_OBJECT (obj), 0);
1836 * return priv->foo;
1839 * void
1840 * my_object_set_bar (MyObject *obj,
1841 * gint bar)
1843 * MyObjectPrivate *priv = my_object_get_instance_private (obj);
1845 * g_return_if_fail (MY_IS_OBJECT (obj));
1847 * if (priv->bar != bar)
1848 * priv->bar = bar;
1850 * ]|
1852 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1853 * macros, since it depends on variable names from those macros.
1855 * Also note that private structs added with these macros must have a struct
1856 * name of the form `TypeNamePrivate`.
1858 * It is safe to call _get_instance_private on %NULL or invalid object since
1859 * it's only adding an offset to the instance pointer. In that case the returned
1860 * pointer must not be dereferenced.
1862 * Since: 2.38
1864 #define G_ADD_PRIVATE(TypeName) { \
1865 TypeName##_private_offset = \
1866 g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \
1870 * G_PRIVATE_OFFSET:
1871 * @TypeName: the name of the type in CamelCase
1872 * @field: the name of the field in the private data structure
1874 * Evaluates to the offset of the @field inside the instance private data
1875 * structure for @TypeName.
1877 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1878 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1879 * those macros.
1881 * Since: 2.38
1883 #define G_PRIVATE_OFFSET(TypeName, field) \
1884 (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field)))
1887 * G_PRIVATE_FIELD_P:
1888 * @TypeName: the name of the type in CamelCase
1889 * @inst: the instance of @TypeName you wish to access
1890 * @field_name: the name of the field in the private data structure
1892 * Evaluates to a pointer to the @field_name inside the @inst private data
1893 * structure for @TypeName.
1895 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1896 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1897 * those macros.
1899 * Since: 2.38
1901 #define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \
1902 G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name))
1905 * G_PRIVATE_FIELD:
1906 * @TypeName: the name of the type in CamelCase
1907 * @inst: the instance of @TypeName you wish to access
1908 * @field_type: the type of the field in the private data structure
1909 * @field_name: the name of the field in the private data structure
1911 * Evaluates to the @field_name inside the @inst private data
1912 * structure for @TypeName.
1914 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1915 * and G_ADD_PRIVATE() macros, since it depends on variable names from
1916 * those macros.
1918 * Since: 2.38
1920 #define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \
1921 G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name))
1923 /* we need to have this macro under conditional expansion, as it references
1924 * a function that has been added in 2.38. see bug:
1925 * https://bugzilla.gnome.org/show_bug.cgi?id=703191
1927 #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38
1928 #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1929 static void type_name##_class_intern_init (gpointer klass) \
1931 type_name##_parent_class = g_type_class_peek_parent (klass); \
1932 if (TypeName##_private_offset != 0) \
1933 g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \
1934 type_name##_class_init ((TypeName##Class*) klass); \
1937 #else
1938 #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1939 static void type_name##_class_intern_init (gpointer klass) \
1941 type_name##_parent_class = g_type_class_peek_parent (klass); \
1942 type_name##_class_init ((TypeName##Class*) klass); \
1944 #endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */
1946 #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
1948 static void type_name##_init (TypeName *self); \
1949 static void type_name##_class_init (TypeName##Class *klass); \
1950 static gpointer type_name##_parent_class = NULL; \
1951 static gint TypeName##_private_offset; \
1953 _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1955 G_GNUC_UNUSED \
1956 static inline gpointer \
1957 type_name##_get_instance_private (TypeName *self) \
1959 return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
1962 GType \
1963 type_name##_get_type (void) \
1965 static volatile gsize g_define_type_id__volatile = 0; \
1966 if (g_once_init_enter (&g_define_type_id__volatile)) \
1968 GType g_define_type_id = \
1969 g_type_register_static_simple (TYPE_PARENT, \
1970 g_intern_static_string (#TypeName), \
1971 sizeof (TypeName##Class), \
1972 (GClassInitFunc) type_name##_class_intern_init, \
1973 sizeof (TypeName), \
1974 (GInstanceInitFunc) type_name##_init, \
1975 (GTypeFlags) flags); \
1976 { /* custom code follows */
1977 #define _G_DEFINE_TYPE_EXTENDED_END() \
1978 /* following custom code */ \
1980 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
1982 return g_define_type_id__volatile; \
1983 } /* closes type_name##_get_type() */
1985 #define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
1987 static void type_name##_default_init (TypeName##Interface *klass); \
1989 GType \
1990 type_name##_get_type (void) \
1992 static volatile gsize g_define_type_id__volatile = 0; \
1993 if (g_once_init_enter (&g_define_type_id__volatile)) \
1995 GType g_define_type_id = \
1996 g_type_register_static_simple (G_TYPE_INTERFACE, \
1997 g_intern_static_string (#TypeName), \
1998 sizeof (TypeName##Interface), \
1999 (GClassInitFunc)type_name##_default_init, \
2000 0, \
2001 (GInstanceInitFunc)NULL, \
2002 (GTypeFlags) 0); \
2003 if (TYPE_PREREQ) \
2004 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
2005 { /* custom code follows */
2006 #define _G_DEFINE_INTERFACE_EXTENDED_END() \
2007 /* following custom code */ \
2009 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2011 return g_define_type_id__volatile; \
2012 } /* closes type_name##_get_type() */
2015 * G_DEFINE_BOXED_TYPE:
2016 * @TypeName: The name of the new type, in Camel case
2017 * @type_name: The name of the new type, in lowercase, with words
2018 * separated by '_'
2019 * @copy_func: the #GBoxedCopyFunc for the new type
2020 * @free_func: the #GBoxedFreeFunc for the new type
2022 * A convenience macro for boxed type implementations, which defines a
2023 * type_name_get_type() function registering the boxed type.
2025 * Since: 2.26
2027 #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, {})
2029 * G_DEFINE_BOXED_TYPE_WITH_CODE:
2030 * @TypeName: The name of the new type, in Camel case
2031 * @type_name: The name of the new type, in lowercase, with words
2032 * separated by '_'
2033 * @copy_func: the #GBoxedCopyFunc for the new type
2034 * @free_func: the #GBoxedFreeFunc for the new type
2035 * @_C_: Custom code that gets inserted in the *_get_type() function
2037 * A convenience macro for boxed type implementations.
2038 * Similar to G_DEFINE_BOXED_TYPE(), but allows to insert custom code into the
2039 * type_name_get_type() function, e.g. to register value transformations with
2040 * g_value_register_transform_func(), for instance:
2042 * |[<!-- language="C" -->
2043 * G_DEFINE_BOXED_TYPE_WITH_CODE (GdkRectangle, gdk_rectangle,
2044 * gdk_rectangle_copy,
2045 * gdk_rectangle_free,
2046 * register_rectangle_transform_funcs (g_define_type_id))
2047 * ]|
2049 * Similarly to the %G_DEFINE_TYPE family of macros, the #GType of the newly
2050 * defined boxed type is exposed in the `g_define_type_id` variable.
2052 * Since: 2.26
2054 #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()
2056 /* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64.
2057 * See https://bugzilla.gnome.org/show_bug.cgi?id=647145
2059 #if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__))
2060 #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2061 GType \
2062 type_name##_get_type (void) \
2064 static volatile gsize g_define_type_id__volatile = 0; \
2065 if (g_once_init_enter (&g_define_type_id__volatile)) \
2067 GType (* _g_register_boxed) \
2068 (const gchar *, \
2069 union \
2071 TypeName * (*do_copy_type) (TypeName *); \
2072 TypeName * (*do_const_copy_type) (const TypeName *); \
2073 GBoxedCopyFunc do_copy_boxed; \
2074 } __attribute__((__transparent_union__)), \
2075 union \
2077 void (* do_free_type) (TypeName *); \
2078 GBoxedFreeFunc do_free_boxed; \
2079 } __attribute__((__transparent_union__)) \
2080 ) = g_boxed_type_register_static; \
2081 GType g_define_type_id = \
2082 _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func); \
2083 { /* custom code follows */
2084 #else
2085 #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2086 GType \
2087 type_name##_get_type (void) \
2089 static volatile gsize g_define_type_id__volatile = 0; \
2090 if (g_once_init_enter (&g_define_type_id__volatile)) \
2092 GType g_define_type_id = \
2093 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
2094 (GBoxedCopyFunc) copy_func, \
2095 (GBoxedFreeFunc) free_func); \
2096 { /* custom code follows */
2097 #endif /* __GNUC__ */
2100 * G_DEFINE_POINTER_TYPE:
2101 * @TypeName: The name of the new type, in Camel case
2102 * @type_name: The name of the new type, in lowercase, with words
2103 * separated by '_'
2105 * A convenience macro for pointer type implementations, which defines a
2106 * type_name_get_type() function registering the pointer type.
2108 * Since: 2.26
2110 #define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE (TypeName, type_name, {})
2112 * G_DEFINE_POINTER_TYPE_WITH_CODE:
2113 * @TypeName: The name of the new type, in Camel case
2114 * @type_name: The name of the new type, in lowercase, with words
2115 * separated by '_'
2116 * @_C_: Custom code that gets inserted in the *_get_type() function
2118 * A convenience macro for pointer type implementations.
2119 * Similar to G_DEFINE_POINTER_TYPE(), but allows to insert
2120 * custom code into the type_name_get_type() function.
2122 * Since: 2.26
2124 #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()
2126 #define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \
2127 GType \
2128 type_name##_get_type (void) \
2130 static volatile gsize g_define_type_id__volatile = 0; \
2131 if (g_once_init_enter (&g_define_type_id__volatile)) \
2133 GType g_define_type_id = \
2134 g_pointer_type_register_static (g_intern_static_string (#TypeName)); \
2135 { /* custom code follows */
2137 /* --- protected (for fundamental type implementations) --- */
2138 GLIB_AVAILABLE_IN_ALL
2139 GTypePlugin* g_type_get_plugin (GType type);
2140 GLIB_AVAILABLE_IN_ALL
2141 GTypePlugin* g_type_interface_get_plugin (GType instance_type,
2142 GType interface_type);
2143 GLIB_AVAILABLE_IN_ALL
2144 GType g_type_fundamental_next (void);
2145 GLIB_AVAILABLE_IN_ALL
2146 GType g_type_fundamental (GType type_id);
2147 GLIB_AVAILABLE_IN_ALL
2148 GTypeInstance* g_type_create_instance (GType type);
2149 GLIB_AVAILABLE_IN_ALL
2150 void g_type_free_instance (GTypeInstance *instance);
2152 GLIB_AVAILABLE_IN_ALL
2153 void g_type_add_class_cache_func (gpointer cache_data,
2154 GTypeClassCacheFunc cache_func);
2155 GLIB_AVAILABLE_IN_ALL
2156 void g_type_remove_class_cache_func (gpointer cache_data,
2157 GTypeClassCacheFunc cache_func);
2158 GLIB_AVAILABLE_IN_ALL
2159 void g_type_class_unref_uncached (gpointer g_class);
2161 GLIB_AVAILABLE_IN_ALL
2162 void g_type_add_interface_check (gpointer check_data,
2163 GTypeInterfaceCheckFunc check_func);
2164 GLIB_AVAILABLE_IN_ALL
2165 void g_type_remove_interface_check (gpointer check_data,
2166 GTypeInterfaceCheckFunc check_func);
2168 GLIB_AVAILABLE_IN_ALL
2169 GTypeValueTable* g_type_value_table_peek (GType type);
2172 /*< private >*/
2173 GLIB_AVAILABLE_IN_ALL
2174 gboolean g_type_check_instance (GTypeInstance *instance) G_GNUC_PURE;
2175 GLIB_AVAILABLE_IN_ALL
2176 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
2177 GType iface_type);
2178 GLIB_AVAILABLE_IN_ALL
2179 gboolean g_type_check_instance_is_a (GTypeInstance *instance,
2180 GType iface_type) G_GNUC_PURE;
2181 GLIB_AVAILABLE_IN_2_42
2182 gboolean g_type_check_instance_is_fundamentally_a (GTypeInstance *instance,
2183 GType fundamental_type) G_GNUC_PURE;
2184 GLIB_AVAILABLE_IN_ALL
2185 GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
2186 GType is_a_type);
2187 GLIB_AVAILABLE_IN_ALL
2188 gboolean g_type_check_class_is_a (GTypeClass *g_class,
2189 GType is_a_type) G_GNUC_PURE;
2190 GLIB_AVAILABLE_IN_ALL
2191 gboolean g_type_check_is_value_type (GType type) G_GNUC_CONST;
2192 GLIB_AVAILABLE_IN_ALL
2193 gboolean g_type_check_value (GValue *value) G_GNUC_PURE;
2194 GLIB_AVAILABLE_IN_ALL
2195 gboolean g_type_check_value_holds (GValue *value,
2196 GType type) G_GNUC_PURE;
2197 GLIB_AVAILABLE_IN_ALL
2198 gboolean g_type_test_flags (GType type,
2199 guint flags) G_GNUC_CONST;
2202 /* --- debugging functions --- */
2203 GLIB_AVAILABLE_IN_ALL
2204 const gchar * g_type_name_from_instance (GTypeInstance *instance);
2205 GLIB_AVAILABLE_IN_ALL
2206 const gchar * g_type_name_from_class (GTypeClass *g_class);
2209 /* --- implementation bits --- */
2210 #ifndef G_DISABLE_CAST_CHECKS
2211 # define _G_TYPE_CIC(ip, gt, ct) \
2212 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
2213 # define _G_TYPE_CCC(cp, gt, ct) \
2214 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
2215 #else /* G_DISABLE_CAST_CHECKS */
2216 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
2217 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
2218 #endif /* G_DISABLE_CAST_CHECKS */
2219 #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
2220 #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
2221 #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
2222 #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
2223 #define _G_TYPE_CIFT(ip, ft) (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft))
2224 #ifdef __GNUC__
2225 # define _G_TYPE_CIT(ip, gt) (G_GNUC_EXTENSION ({ \
2226 GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
2227 if (!__inst) \
2228 __r = FALSE; \
2229 else if (__inst->g_class && __inst->g_class->g_type == __t) \
2230 __r = TRUE; \
2231 else \
2232 __r = g_type_check_instance_is_a (__inst, __t); \
2233 __r; \
2235 # define _G_TYPE_CCT(cp, gt) (G_GNUC_EXTENSION ({ \
2236 GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
2237 if (!__class) \
2238 __r = FALSE; \
2239 else if (__class->g_type == __t) \
2240 __r = TRUE; \
2241 else \
2242 __r = g_type_check_class_is_a (__class, __t); \
2243 __r; \
2245 # define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \
2246 GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \
2247 if (!__val) \
2248 __r = FALSE; \
2249 else if (__val->g_type == __t) \
2250 __r = TRUE; \
2251 else \
2252 __r = g_type_check_value_holds (__val, __t); \
2253 __r; \
2255 #else /* !__GNUC__ */
2256 # define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt))
2257 # define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt))
2258 # define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
2259 #endif /* !__GNUC__ */
2261 * G_TYPE_FLAG_RESERVED_ID_BIT:
2263 * A bit in the type number that's supposed to be left untouched.
2265 #define G_TYPE_FLAG_RESERVED_ID_BIT ((GType) (1 << 0))
2267 G_END_DECLS
2269 #endif /* __G_TYPE_H__ */