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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
34 * @type: A #GType value.
36 * The fundamental type which is the ancestor of @type.
37 * Fundamental types are types that serve as ultimate bases for the derived types,
38 * thus they are the roots of distinct inheritance hierarchies.
40 #define G_TYPE_FUNDAMENTAL(type) (g_type_fundamental (type))
42 * G_TYPE_FUNDAMENTAL_MAX:
44 * An integer constant that represents the number of identifiers reserved
45 * for types that are assigned at compile-time.
47 #define G_TYPE_FUNDAMENTAL_MAX (255 << G_TYPE_FUNDAMENTAL_SHIFT)
49 /* Constant fundamental types,
50 * introduced by g_type_init().
55 * An invalid #GType used as error return value in some functions which return
58 #define G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL (0)
62 * A fundamental type which is used as a replacement for the C
63 * <literal>void</literal> return type.
65 #define G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL (1)
69 * The fundamental type from which all interfaces are derived.
71 #define G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL (2)
75 * The fundamental type corresponding to #gchar.
76 * The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed integer.
77 * This may or may not be the same type a the C type "gchar".
79 #define G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL (3)
83 * The fundamental type corresponding to #guchar.
85 #define G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL (4)
89 * The fundamental type corresponding to #gboolean.
91 #define G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL (5)
95 * The fundamental type corresponding to #gint.
97 #define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6)
101 * The fundamental type corresponding to #guint.
103 #define G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL (7)
107 * The fundamental type corresponding to #glong.
109 #define G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL (8)
113 * The fundamental type corresponding to #gulong.
115 #define G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL (9)
119 * The fundamental type corresponding to #gint64.
121 #define G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL (10)
125 * The fundamental type corresponding to #guint64.
127 #define G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL (11)
131 * The fundamental type from which all enumeration types are derived.
133 #define G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL (12)
137 * The fundamental type from which all flags types are derived.
139 #define G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL (13)
143 * The fundamental type corresponding to #gfloat.
145 #define G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL (14)
149 * The fundamental type corresponding to #gdouble.
151 #define G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL (15)
155 * The fundamental type corresponding to nul-terminated C strings.
157 #define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16)
161 * The fundamental type corresponding to #gpointer.
163 #define G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL (17)
167 * The fundamental type from which all boxed types are derived.
169 #define G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL (18)
173 * The fundamental type from which all #GParamSpec types are derived.
175 #define G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL (19)
179 * The fundamental type for #GObject.
181 #define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20)
185 * The fundamental type corresponding to #GVariant.
187 * All floating #GVariant instances passed through the #GType system are
190 * Note that callbacks in closures, and signal handlers
191 * for signals of return type %G_TYPE_VARIANT, must never return floating
194 * Note: GLib 2.24 did include a boxed type with this name. It was replaced
195 * with this fundamental type in 2.26.
199 #define G_TYPE_VARIANT G_TYPE_MAKE_FUNDAMENTAL (21)
202 /* Reserved fundamental type numbers to create new fundamental
203 * type IDs with G_TYPE_MAKE_FUNDAMENTAL().
204 * Send email to gtk-devel-list@gnome.org for reservations.
207 * G_TYPE_FUNDAMENTAL_SHIFT:
209 * Shift value used in converting numbers to type IDs.
211 #define G_TYPE_FUNDAMENTAL_SHIFT (2)
213 * G_TYPE_MAKE_FUNDAMENTAL:
214 * @x: the fundamental type number.
216 * Get the type ID for the fundamental type number @x.
217 * Use g_type_fundamental_next() instead of this macro to create new fundamental
222 #define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
224 * G_TYPE_RESERVED_GLIB_FIRST:
226 * First fundamental type number to create a new fundamental type id with
227 * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
229 #define G_TYPE_RESERVED_GLIB_FIRST (22)
231 * G_TYPE_RESERVED_GLIB_LAST:
233 * Last fundamental type number reserved for GLib.
235 #define G_TYPE_RESERVED_GLIB_LAST (31)
237 * G_TYPE_RESERVED_BSE_FIRST:
239 * First fundamental type number to create a new fundamental type id with
240 * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
242 #define G_TYPE_RESERVED_BSE_FIRST (32)
244 * G_TYPE_RESERVED_BSE_LAST:
246 * Last fundamental type number reserved for BSE.
248 #define G_TYPE_RESERVED_BSE_LAST (48)
250 * G_TYPE_RESERVED_USER_FIRST:
252 * First available fundamental type number to create new fundamental
253 * type id with G_TYPE_MAKE_FUNDAMENTAL().
255 #define G_TYPE_RESERVED_USER_FIRST (49)
258 /* Type Checking Macros
261 * G_TYPE_IS_FUNDAMENTAL:
262 * @type: A #GType value.
264 * Checks if @type is a fundamental type.
266 * Returns: %TRUE on success.
268 #define G_TYPE_IS_FUNDAMENTAL(type) ((type) <= G_TYPE_FUNDAMENTAL_MAX)
271 * @type: A #GType value.
273 * Checks if @type is derived (or in object-oriented terminology:
274 * inherited) from another type (this holds true for all non-fundamental
277 * Returns: %TRUE on success.
279 #define G_TYPE_IS_DERIVED(type) ((type) > G_TYPE_FUNDAMENTAL_MAX)
281 * G_TYPE_IS_INTERFACE:
282 * @type: A #GType value.
284 * Checks if @type is an interface type.
285 * An interface type provides a pure API, the implementation
286 * of which is provided by another type (which is then said to conform
287 * to the interface). GLib interfaces are somewhat analogous to Java
288 * interfaces and C++ classes containing only pure virtual functions,
289 * with the difference that GType interfaces are not derivable (but see
290 * g_type_interface_add_prerequisite() for an alternative).
292 * Returns: %TRUE on success.
294 #define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
297 * @type: A #GType value.
299 * Checks if @type is a classed type.
301 * Returns: %TRUE on success.
303 #define G_TYPE_IS_CLASSED(type) (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED))
305 * G_TYPE_IS_INSTANTIATABLE:
306 * @type: A #GType value.
308 * Checks if @type can be instantiated. Instantiation is the
309 * process of creating an instance (object) of this type.
311 * Returns: %TRUE on success.
313 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
315 * G_TYPE_IS_DERIVABLE:
316 * @type: A #GType value.
318 * Checks if @type is a derivable type. A derivable type can
319 * be used as the base class of a flat (single-level) class hierarchy.
321 * Returns: %TRUE on success.
323 #define G_TYPE_IS_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE))
325 * G_TYPE_IS_DEEP_DERIVABLE:
326 * @type: A #GType value.
328 * Checks if @type is a deep derivable type. A deep derivable type
329 * can be used as the base class of a deep (multi-level) class hierarchy.
331 * Returns: %TRUE on success.
333 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
335 * G_TYPE_IS_ABSTRACT:
336 * @type: A #GType value.
338 * Checks if @type is an abstract type. An abstract type can not be
339 * instantiated and is normally used as an abstract base class for
342 * Returns: %TRUE on success.
344 #define G_TYPE_IS_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))
346 * G_TYPE_IS_VALUE_ABSTRACT:
347 * @type: A #GType value.
349 * Checks if @type is an abstract value type. An abstract value type introduces
350 * a value table, but can't be used for g_value_init() and is normally used as
351 * an abstract base type for derived value types.
353 * Returns: %TRUE on success.
355 #define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
357 * G_TYPE_IS_VALUE_TYPE:
358 * @type: A #GType value.
360 * Checks if @type is a value type and can be used with g_value_init().
362 * Returns: %TRUE on success.
364 #define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type))
366 * G_TYPE_HAS_VALUE_TABLE:
367 * @type: A #GType value.
369 * Checks if @type has a #GTypeValueTable.
371 * Returns: %TRUE on success.
373 #define G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek (type) != NULL)
381 * A numerical value which represents the unique identifier of a registered
384 #if GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus
386 #else /* for historic reasons, C++ links against gulong GTypes */
387 typedef gulong GType
;
389 typedef struct _GValue GValue
;
390 typedef union _GTypeCValue GTypeCValue
;
391 typedef struct _GTypePlugin GTypePlugin
;
392 typedef struct _GTypeClass GTypeClass
;
393 typedef struct _GTypeInterface GTypeInterface
;
394 typedef struct _GTypeInstance GTypeInstance
;
395 typedef struct _GTypeInfo GTypeInfo
;
396 typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo
;
397 typedef struct _GInterfaceInfo GInterfaceInfo
;
398 typedef struct _GTypeValueTable GTypeValueTable
;
399 typedef struct _GTypeQuery GTypeQuery
;
402 /* Basic Type Structures
407 * An opaque structure used as the base of all classes.
417 * An opaque structure used as the base of all type instances.
419 struct _GTypeInstance
427 * An opaque structure used as the base of all interface types.
429 struct _GTypeInterface
432 GType g_type
; /* iface type */
433 GType g_instance_type
;
437 * @type: the #GType value of the type.
438 * @type_name: the name of the type.
439 * @class_size: the size of the class structure.
440 * @instance_size: the size of the instance structure.
442 * A structure holding information for a specific type. It is
443 * filled in by the g_type_query() function.
448 const gchar
*type_name
;
454 /* Casts, checks and accessors for structured types
455 * usage of these macros is reserved to type implementations only
459 * G_TYPE_CHECK_INSTANCE:
460 * @instance: Location of a #GTypeInstance structure.
462 * Checks if @instance is a valid #GTypeInstance structure,
463 * otherwise issues a warning and returns %FALSE.
465 * This macro should only be used in type implementations.
467 * Returns: %TRUE on success.
469 #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
471 * G_TYPE_CHECK_INSTANCE_CAST:
472 * @instance: Location of a #GTypeInstance structure.
473 * @g_type: The type to be returned.
474 * @c_type: The corresponding C type of @g_type.
476 * Checks that @instance is an instance of the type identified by @g_type
477 * and issues a warning if this is not the case. Returns @instance casted
478 * to a pointer to @c_type.
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: 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.
490 * This macro should only be used in type implementations.
492 * Returns: %TRUE on success.
494 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
496 * G_TYPE_INSTANCE_GET_CLASS:
497 * @instance: Location of the #GTypeInstance structure.
498 * @g_type: The #GType of the class to be returned.
499 * @c_type: The C type of the class structure.
501 * Get the class structure of a given @instance, casted
502 * to a specified ancestor type @g_type of the instance.
504 * Note that while calling a GInstanceInitFunc(), the class pointer gets
505 * modified, so it might not always return the expected pointer.
507 * This macro should only be used in type implementations.
509 * Returns: a pointer to the class structure
511 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
513 * G_TYPE_INSTANCE_GET_INTERFACE:
514 * @instance: Location of the #GTypeInstance structure.
515 * @g_type: The #GType of the interface to be returned.
516 * @c_type: The C type of the interface structure.
518 * Get the interface structure for interface @g_type of a given @instance.
520 * This macro should only be used in type implementations.
522 * Returns: a pointer to the interface structure
524 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
526 * G_TYPE_CHECK_CLASS_CAST:
527 * @g_class: Location of a #GTypeClass structure.
528 * @g_type: The type to be returned.
529 * @c_type: The corresponding C type of class structure of @g_type.
531 * Checks that @g_class is a class structure of the type identified by @g_type
532 * and issues a warning if this is not the case. Returns @g_class casted
533 * to a pointer to @c_type.
535 * This macro should only be used in type implementations.
537 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
539 * G_TYPE_CHECK_CLASS_TYPE:
540 * @g_class: Location of a #GTypeClass structure.
541 * @g_type: The type to be checked.
543 * Checks if @g_class is a class structure of the type identified by
546 * This macro should only be used in type implementations.
548 * Returns: %TRUE on success.
550 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
552 * G_TYPE_CHECK_VALUE:
555 * Checks if @value has been initialized to hold values
558 * This macro should only be used in type implementations.
560 * Returns: %TRUE on success.
562 #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
564 * G_TYPE_CHECK_VALUE_TYPE:
566 * @g_type: The type to be checked.
568 * Checks if @value has been initialized to hold values
571 * This macro should only be used in type implementations.
573 * Returns: %TRUE on success.
575 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type)))
577 * G_TYPE_FROM_INSTANCE:
578 * @instance: Location of a valid #GTypeInstance structure.
580 * Get the type identifier from a given @instance structure.
582 * This macro should only be used in type implementations.
584 * Returns: the #GType
586 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
589 * @g_class: Location of a valid #GTypeClass structure.
591 * Get the type identifier from a given @class structure.
593 * This macro should only be used in type implementations.
595 * Returns: the #GType
597 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
599 * G_TYPE_FROM_INTERFACE:
600 * @g_iface: Location of a valid #GTypeInterface structure.
602 * Get the type identifier from a given @interface structure.
604 * This macro should only be used in type implementations.
606 * Returns: the #GType
608 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
611 * G_TYPE_INSTANCE_GET_PRIVATE:
612 * @instance: the instance of a type deriving from @private_type.
613 * @g_type: the type identifying which private data to retrieve.
614 * @c_type: The C type for the private structure.
616 * Gets the private structure for a particular type.
617 * The private structure must have been registered in the
618 * class_init function with g_type_class_add_private().
620 * This macro should only be used in type implementations.
623 * Returns: a pointer to the private data structure.
625 #define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type)))
628 * G_TYPE_CLASS_GET_PRIVATE:
629 * @klass: the class of a type deriving from @private_type.
630 * @g_type: the type identifying which private data to retrieve.
631 * @c_type: The C type for the private structure.
633 * Gets the private class structure for a particular type.
634 * The private structure must have been registered in the
635 * get_type() function with g_type_add_class_private().
637 * This macro should only be used in type implementations.
640 * Returns: a pointer to the private data structure.
642 #define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type)))
646 * @G_TYPE_DEBUG_NONE: Print no messages.
647 * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping.
648 * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions.
649 * @G_TYPE_DEBUG_MASK: Mask covering all debug flags.
651 * The <type>GTypeDebugFlags</type> enumeration values can be passed to
652 * g_type_init_with_debug_flags() to trigger debugging messages during runtime.
653 * Note that the messages can also be triggered by setting the
654 * <envar>GOBJECT_DEBUG</envar> environment variable to a ':'-separated list of
655 * "objects" and "signals".
657 typedef enum /*< skip >*/
659 G_TYPE_DEBUG_NONE
= 0,
660 G_TYPE_DEBUG_OBJECTS
= 1 << 0,
661 G_TYPE_DEBUG_SIGNALS
= 1 << 1,
662 G_TYPE_DEBUG_MASK
= 0x03
666 /* --- prototypes --- */
667 void g_type_init (void);
668 void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags
);
669 G_CONST_RETURN gchar
* g_type_name (GType type
);
670 GQuark
g_type_qname (GType type
);
671 GType
g_type_from_name (const gchar
*name
);
672 GType
g_type_parent (GType type
);
673 guint
g_type_depth (GType type
);
674 GType
g_type_next_base (GType leaf_type
,
676 gboolean
g_type_is_a (GType type
,
678 gpointer
g_type_class_ref (GType type
);
679 gpointer
g_type_class_peek (GType type
);
680 gpointer
g_type_class_peek_static (GType type
);
681 void g_type_class_unref (gpointer g_class
);
682 gpointer
g_type_class_peek_parent (gpointer g_class
);
683 gpointer
g_type_interface_peek (gpointer instance_class
,
685 gpointer
g_type_interface_peek_parent (gpointer g_iface
);
687 gpointer
g_type_default_interface_ref (GType g_type
);
688 gpointer
g_type_default_interface_peek (GType g_type
);
689 void g_type_default_interface_unref (gpointer g_iface
);
691 /* g_free() the returned arrays */
692 GType
* g_type_children (GType type
,
694 GType
* g_type_interfaces (GType type
,
695 guint
*n_interfaces
);
697 /* per-type _static_ data */
698 void g_type_set_qdata (GType type
,
701 gpointer
g_type_get_qdata (GType type
,
703 void g_type_query (GType type
,
707 /* --- type registration --- */
710 * @g_class: The #GTypeClass structure to initialize.
712 * A callback function used by the type system to do base initialization
713 * of the class structures of derived types. It is called as part of the
714 * initialization process of all derived classes and should reallocate
715 * or reset all dynamic class members copied over from the parent class.
716 * For example, class members (such as strings) that are not sufficiently
717 * handled by a plain memory copy of the parent class into the derived class
718 * have to be altered. See GClassInitFunc() for a discussion of the class
719 * intialization process.
721 typedef void (*GBaseInitFunc
) (gpointer g_class
);
724 * @g_class: The #GTypeClass structure to finalize.
726 * A callback function used by the type system to finalize those portions
727 * of a derived types class structure that were setup from the corresponding
728 * GBaseInitFunc() function. Class finalization basically works the inverse
729 * way in which class intialization is performed.
730 * See GClassInitFunc() for a discussion of the class intialization process.
732 typedef void (*GBaseFinalizeFunc
) (gpointer g_class
);
735 * @g_class: The #GTypeClass structure to initialize.
736 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
738 * A callback function used by the type system to initialize the class
739 * of a specific type. This function should initialize all static class
741 * The initialization process of a class involves:
744 * 1 - Copying common members from the parent class over to the
745 * derived class structure.
748 * 2 - Zero initialization of the remaining members not copied
749 * over from the parent class.
752 * 3 - Invocation of the GBaseInitFunc() initializers of all parent
753 * types and the class' type.
756 * 4 - Invocation of the class' GClassInitFunc() initializer.
759 * Since derived classes are partially initialized through a memory copy
760 * of the parent class, the general rule is that GBaseInitFunc() and
761 * GBaseFinalizeFunc() should take care of necessary reinitialization
762 * and release of those class members that were introduced by the type
763 * that specified these GBaseInitFunc()/GBaseFinalizeFunc().
764 * GClassInitFunc() should only care about initializing static
765 * class members, while dynamic class members (such as allocated strings
766 * or reference counted resources) are better handled by a GBaseInitFunc()
767 * for this type, so proper initialization of the dynamic class members
768 * is performed for class initialization of derived types as well.
769 * An example may help to correspond the intend of the different class
774 * GObjectClass parent_class;
775 * gint static_integer;
776 * gchar *dynamic_string;
779 * type_a_base_class_init (TypeAClass *class)
781 * class->dynamic_string = g_strdup ("some string");
784 * type_a_base_class_finalize (TypeAClass *class)
786 * g_free (class->dynamic_string);
789 * type_a_class_init (TypeAClass *class)
791 * class->static_integer = 42;
795 * TypeAClass parent_class;
796 * gfloat static_float;
797 * GString *dynamic_gstring;
800 * type_b_base_class_init (TypeBClass *class)
802 * class->dynamic_gstring = g_string_new ("some other string");
805 * type_b_base_class_finalize (TypeBClass *class)
807 * g_string_free (class->dynamic_gstring);
810 * type_b_class_init (TypeBClass *class)
812 * class->static_float = 3.14159265358979323846;
815 * Initialization of TypeBClass will first cause initialization of
816 * TypeAClass (derived classes reference their parent classes, see
817 * g_type_class_ref() on this).
818 * Initialization of TypeAClass roughly involves zero-initializing its fields,
819 * then calling its GBaseInitFunc() type_a_base_class_init() to allocate
820 * its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
821 * type_a_class_init() to initialize its static members (static_integer).
822 * The first step in the initialization process of TypeBClass is then
823 * a plain memory copy of the contents of TypeAClass into TypeBClass and
824 * zero-initialization of the remaining fields in TypeBClass.
825 * The dynamic members of TypeAClass within TypeBClass now need
826 * reinitialization which is performed by calling type_a_base_class_init()
827 * with an argument of TypeBClass.
828 * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
829 * is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
830 * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
831 * is called to complete the initialization process with the static members
833 * Corresponding finalization counter parts to the GBaseInitFunc() functions
834 * have to be provided to release allocated resources at class finalization
837 typedef void (*GClassInitFunc
) (gpointer g_class
,
838 gpointer class_data
);
840 * GClassFinalizeFunc:
841 * @g_class: The #GTypeClass structure to finalize.
842 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
844 * A callback function used by the type system to finalize a class.
845 * This function is rarely needed, as dynamically allocated class resources
846 * should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
847 * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
848 * structure of a static type is invalid, because classes of static types
849 * will never be finalized (they are artificially kept alive when their
850 * reference count drops to zero).
852 typedef void (*GClassFinalizeFunc
) (gpointer g_class
,
853 gpointer class_data
);
856 * @instance: The instance to initialize.
857 * @g_class: The class of the type the instance is created for.
859 * A callback function used by the type system to initialize a new
860 * instance of a type. This function initializes all instance members and
861 * allocates any resources required by it.
862 * Initialization of a derived instance involves calling all its parent
863 * types instance initializers, so the class member of the instance
864 * is altered during its initialization to always point to the class that
865 * belongs to the type the current initializer was introduced for.
867 typedef void (*GInstanceInitFunc
) (GTypeInstance
*instance
,
870 * GInterfaceInitFunc:
871 * @g_iface: The interface structure to initialize.
872 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure.
874 * A callback function used by the type system to initialize a new
875 * interface. This function should initialize all internal data and
876 * allocate any resources required by the interface.
878 typedef void (*GInterfaceInitFunc
) (gpointer g_iface
,
879 gpointer iface_data
);
881 * GInterfaceFinalizeFunc:
882 * @g_iface: The interface structure to finalize.
883 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure.
885 * A callback function used by the type system to finalize an interface.
886 * This function should destroy any internal data and release any resources
887 * allocated by the corresponding GInterfaceInitFunc() function.
889 typedef void (*GInterfaceFinalizeFunc
) (gpointer g_iface
,
890 gpointer iface_data
);
892 * GTypeClassCacheFunc:
893 * @cache_data: data that was given to the g_type_add_class_cache_func() call
894 * @g_class: The #GTypeClass structure which is unreferenced
896 * A callback function which is called when the reference count of a class
897 * drops to zero. It may use g_type_class_ref() to prevent the class from
898 * being freed. You should not call g_type_class_unref() from a
899 * #GTypeClassCacheFunc function to prevent infinite recursion, use
900 * g_type_class_unref_uncached() instead.
902 * The functions have to check the class id passed in to figure
903 * whether they actually want to cache the class of this type, since all
904 * classes are routed through the same #GTypeClassCacheFunc chain.
906 * Returns: %TRUE to stop further #GTypeClassCacheFunc<!-- -->s from being
907 * called, %FALSE to continue.
909 typedef gboolean (*GTypeClassCacheFunc
) (gpointer cache_data
,
910 GTypeClass
*g_class
);
912 * GTypeInterfaceCheckFunc:
913 * @check_data: data passed to g_type_add_interface_check().
914 * @g_iface: the interface that has been initialized
916 * A callback called after an interface vtable is initialized.
917 * See g_type_add_interface_check().
921 typedef void (*GTypeInterfaceCheckFunc
) (gpointer check_data
,
924 * GTypeFundamentalFlags:
925 * @G_TYPE_FLAG_CLASSED: Indicates a classed type.
926 * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed).
927 * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type.
928 * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable).
930 * Bit masks used to check or determine specific characteristics of a
933 typedef enum /*< skip >*/
935 G_TYPE_FLAG_CLASSED
= (1 << 0),
936 G_TYPE_FLAG_INSTANTIATABLE
= (1 << 1),
937 G_TYPE_FLAG_DERIVABLE
= (1 << 2),
938 G_TYPE_FLAG_DEEP_DERIVABLE
= (1 << 3)
939 } GTypeFundamentalFlags
;
942 * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
943 * created for an abstract type.
944 * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
945 * that introduces a value table, but can't be used for
948 * Bit masks used to check or determine characteristics of a type.
950 typedef enum /*< skip >*/
952 G_TYPE_FLAG_ABSTRACT
= (1 << 4),
953 G_TYPE_FLAG_VALUE_ABSTRACT
= (1 << 5)
957 * @class_size: Size of the class structure (required for interface, classed and instantiatable types).
958 * @base_init: Location of the base initialization function (optional).
959 * @base_finalize: Location of the base finalization function (optional).
960 * @class_init: Location of the class initialization function for
961 * classed and instantiatable types. Location of the default vtable
962 * inititalization function for interface types. (optional) This function
963 * is used both to fill in virtual functions in the class or default vtable,
964 * and to do type-specific setup such as registering signals and object
966 * @class_finalize: Location of the class finalization function for
967 * classed and instantiatable types. Location fo the default vtable
968 * finalization function for interface types. (optional)
969 * @class_data: User-supplied data passed to the class init/finalize functions.
970 * @instance_size: Size of the instance (object) structure (required for instantiatable types only).
971 * @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 <link linkend="glib-Memory-Slices">slice allocator</link> now.
972 * @instance_init: Location of the instance initialization function (optional, for instantiatable types only).
973 * @value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usually only
974 * useful for fundamental types).
976 * This structure is used to provide the type system with the information
977 * required to initialize and destruct (finalize) a type's class and
979 * The initialized structure is passed to the g_type_register_static() function
980 * (or is copied into the provided #GTypeInfo structure in the
981 * g_type_plugin_complete_type_info()). The type system will perform a deep
982 * copy of this structure, so its memory does not need to be persistent
983 * across invocation of g_type_register_static().
987 /* interface types, classed types, instantiated types */
990 GBaseInitFunc base_init
;
991 GBaseFinalizeFunc base_finalize
;
993 /* interface types, classed types, instantiated types */
994 GClassInitFunc class_init
;
995 GClassFinalizeFunc class_finalize
;
996 gconstpointer class_data
;
998 /* instantiated types */
999 guint16 instance_size
;
1000 guint16 n_preallocs
;
1001 GInstanceInitFunc instance_init
;
1003 /* value handling */
1004 const GTypeValueTable
*value_table
;
1007 * GTypeFundamentalInfo:
1008 * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type
1010 * A structure that provides information to the type system which is
1011 * used specifically for managing fundamental types.
1013 struct _GTypeFundamentalInfo
1015 GTypeFundamentalFlags type_flags
;
1019 * @interface_init: location of the interface initialization function
1020 * @interface_finalize: location of the interface finalization function
1021 * @interface_data: user-supplied data passed to the interface init/finalize functions
1023 * A structure that provides information to the type system which is
1024 * used specifically for managing interface types.
1026 struct _GInterfaceInfo
1028 GInterfaceInitFunc interface_init
;
1029 GInterfaceFinalizeFunc interface_finalize
;
1030 gpointer interface_data
;
1034 * @value_init: Default initialize @values contents by poking values
1035 * directly into the value->data array. The data array of
1036 * the #GValue passed into this function was zero-filled
1037 * with <function>memset()</function>, so no care has to
1038 * be taken to free any
1039 * old contents. E.g. for the implementation of a string
1040 * value that may never be %NULL, the implementation might
1043 * value->data[0].v_pointer = g_strdup ("");
1045 * @value_free: Free any old contents that might be left in the
1046 * data array of the passed in @value. No resources may
1047 * remain allocated through the #GValue contents after
1048 * this function returns. E.g. for our above string type:
1050 * // only free strings without a specific flag for static storage
1051 * if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1052 * g_free (value->data[0].v_pointer);
1054 * @value_copy: @dest_value is a #GValue with zero-filled data section
1055 * and @src_value is a properly setup #GValue of same or
1057 * The purpose of this function is to copy the contents of
1058 * @src_value into @dest_value in a way, that even after
1059 * @src_value has been freed, the contents of @dest_value
1060 * remain valid. String type example:
1062 * dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
1064 * @value_peek_pointer: If the value contents fit into a pointer, such as objects
1065 * or strings, return this pointer, so the caller can peek at
1066 * the current contents. To extend on our above string example:
1068 * return value->data[0].v_pointer;
1070 * @collect_format: A string format describing how to collect the contents of
1071 * this value bit-by-bit. Each character in the format represents
1072 * an argument to be collected, and the characters themselves indicate
1073 * the type of the argument. Currently supported arguments are:
1075 * <varlistentry><term /><listitem><para>
1076 * 'i' - Integers. passed as collect_values[].v_int.
1077 * </para></listitem></varlistentry>
1078 * <varlistentry><term /><listitem><para>
1079 * 'l' - Longs. passed as collect_values[].v_long.
1080 * </para></listitem></varlistentry>
1081 * <varlistentry><term /><listitem><para>
1082 * 'd' - Doubles. passed as collect_values[].v_double.
1083 * </para></listitem></varlistentry>
1084 * <varlistentry><term /><listitem><para>
1085 * 'p' - Pointers. passed as collect_values[].v_pointer.
1086 * </para></listitem></varlistentry>
1088 * It should be noted that for variable argument list construction,
1089 * ANSI C promotes every type smaller than an integer to an int, and
1090 * floats to doubles. So for collection of short int or char, 'i'
1091 * needs to be used, and for collection of floats 'd'.
1092 * @collect_value: The collect_value() function is responsible for converting the
1093 * values collected from a variable argument list into contents
1094 * suitable for storage in a GValue. This function should setup
1095 * @value similar to value_init(); e.g. for a string value that
1096 * does not allow %NULL pointers, it needs to either spew an error,
1097 * or do an implicit conversion by storing an empty string.
1098 * The @value passed in to this function has a zero-filled data
1099 * array, so just like for value_init() it is guaranteed to not
1100 * contain any old contents that might need freeing.
1101 * @n_collect_values is exactly the string length of @collect_format,
1102 * and @collect_values is an array of unions #GTypeCValue with
1103 * length @n_collect_values, containing the collected values
1104 * according to @collect_format.
1105 * @collect_flags is an argument provided as a hint by the caller.
1106 * It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating,
1107 * that the collected value contents may be considered "static"
1108 * for the duration of the @value lifetime.
1109 * Thus an extra copy of the contents stored in @collect_values is
1110 * not required for assignment to @value.
1111 * For our above string example, we continue with:
1113 * if (!collect_values[0].v_pointer)
1114 * value->data[0].v_pointer = g_strdup ("");
1115 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1117 * value->data[0].v_pointer = collect_values[0].v_pointer;
1118 * // keep a flag for the value_free() implementation to not free this string
1119 * value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
1122 * value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
1125 * It should be noted, that it is generally a bad idea to follow the
1126 * #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
1127 * reentrancy requirements and reference count assertions performed
1128 * by the #GSignal code, reference counts should always be incremented
1129 * for reference counted contents stored in the value->data array.
1130 * To deviate from our string example for a moment, and taking a look
1131 * at an exemplary implementation for collect_value() of #GObject:
1133 * if (collect_values[0].v_pointer)
1135 * GObject *object = G_OBJECT (collect_values[0].v_pointer);
1136 * // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
1137 * value->data[0].v_pointer = g_object_ref (object);
1141 * return g_strdup_printf ("Object passed as invalid NULL pointer");
1144 * The reference count for valid objects is always incremented,
1145 * regardless of @collect_flags. For invalid objects, the example
1146 * returns a newly allocated string without altering @value.
1147 * Upon success, collect_value() needs to return %NULL. If, however,
1148 * an error condition occurred, collect_value() may spew an
1149 * error by returning a newly allocated non-%NULL string, giving
1150 * a suitable description of the error condition.
1151 * The calling code makes no assumptions about the @value
1152 * contents being valid upon error returns, @value
1153 * is simply thrown away without further freeing. As such, it is
1154 * a good idea to not allocate #GValue contents, prior to returning
1155 * an error, however, collect_values() is not obliged to return
1156 * a correctly setup @value for error returns, simply because
1157 * any non-%NULL return is considered a fatal condition so further
1158 * program behaviour is undefined.
1159 * @lcopy_format: Format description of the arguments to collect for @lcopy_value,
1160 * analogous to @collect_format. Usually, @lcopy_format string consists
1161 * only of 'p's to provide lcopy_value() with pointers to storage locations.
1162 * @lcopy_value: This function is responsible for storing the @value contents into
1163 * arguments passed through a variable argument list which got
1164 * collected into @collect_values according to @lcopy_format.
1165 * @n_collect_values equals the string length of @lcopy_format,
1166 * and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS.
1167 * In contrast to collect_value(), lcopy_value() is obliged to
1168 * always properly support %G_VALUE_NOCOPY_CONTENTS.
1169 * Similar to collect_value() the function may prematurely abort
1170 * by returning a newly allocated string describing an error condition.
1171 * To complete the string example:
1173 * gchar **string_p = collect_values[0].v_pointer;
1175 * return g_strdup_printf ("string location passed as NULL");
1176 * if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1177 * *string_p = value->data[0].v_pointer;
1179 * *string_p = g_strdup (value->data[0].v_pointer);
1181 * And an illustrative version of lcopy_value() for
1182 * reference-counted types:
1184 * GObject **object_p = collect_values[0].v_pointer;
1186 * return g_strdup_printf ("object location passed as NULL");
1187 * if (!value->data[0].v_pointer)
1189 * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
1190 * *object_p = value->data[0].v_pointer;
1192 * *object_p = g_object_ref (value->data[0].v_pointer);
1196 * The #GTypeValueTable provides the functions required by the #GValue implementation,
1197 * to serve as a container for values of a type.
1200 struct _GTypeValueTable
1202 void (*value_init
) (GValue
*value
);
1203 void (*value_free
) (GValue
*value
);
1204 void (*value_copy
) (const GValue
*src_value
,
1205 GValue
*dest_value
);
1206 /* varargs functionality (optional) */
1207 gpointer (*value_peek_pointer
) (const GValue
*value
);
1208 gchar
*collect_format
;
1209 gchar
* (*collect_value
) (GValue
*value
,
1210 guint n_collect_values
,
1211 GTypeCValue
*collect_values
,
1212 guint collect_flags
);
1213 gchar
*lcopy_format
;
1214 gchar
* (*lcopy_value
) (const GValue
*value
,
1215 guint n_collect_values
,
1216 GTypeCValue
*collect_values
,
1217 guint collect_flags
);
1219 GType
g_type_register_static (GType parent_type
,
1220 const gchar
*type_name
,
1221 const GTypeInfo
*info
,
1223 GType
g_type_register_static_simple (GType parent_type
,
1224 const gchar
*type_name
,
1226 GClassInitFunc class_init
,
1227 guint instance_size
,
1228 GInstanceInitFunc instance_init
,
1231 GType
g_type_register_dynamic (GType parent_type
,
1232 const gchar
*type_name
,
1233 GTypePlugin
*plugin
,
1235 GType
g_type_register_fundamental (GType type_id
,
1236 const gchar
*type_name
,
1237 const GTypeInfo
*info
,
1238 const GTypeFundamentalInfo
*finfo
,
1240 void g_type_add_interface_static (GType instance_type
,
1241 GType interface_type
,
1242 const GInterfaceInfo
*info
);
1243 void g_type_add_interface_dynamic (GType instance_type
,
1244 GType interface_type
,
1245 GTypePlugin
*plugin
);
1246 void g_type_interface_add_prerequisite (GType interface_type
,
1247 GType prerequisite_type
);
1248 GType
*g_type_interface_prerequisites (GType interface_type
,
1249 guint
*n_prerequisites
);
1250 void g_type_class_add_private (gpointer g_class
,
1251 gsize private_size
);
1252 gpointer
g_type_instance_get_private (GTypeInstance
*instance
,
1253 GType private_type
);
1255 void g_type_add_class_private (GType class_type
,
1256 gsize private_size
);
1257 gpointer
g_type_class_get_private (GTypeClass
*klass
,
1258 GType private_type
);
1261 /* --- GType boilerplate --- */
1264 * @TN: The name of the new type, in Camel case.
1265 * @t_n: The name of the new type, in lowercase, with words
1267 * @T_P: The #GType of the parent type.
1269 * A convenience macro for type implementations, which declares a
1270 * class initialization function, an instance initialization function (see #GTypeInfo for information about
1271 * these) and a static variable named @t_n<!-- -->_parent_class pointing to the parent class. Furthermore, it defines
1272 * a *_get_type() function. See G_DEFINE_TYPE_EXTENDED() for an example.
1276 #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
1278 * G_DEFINE_TYPE_WITH_CODE:
1279 * @TN: The name of the new type, in Camel case.
1280 * @t_n: The name of the new type in lowercase, with words separated by '_'.
1281 * @T_P: The #GType of the parent type.
1282 * @_C_: Custom code that gets inserted in the *_get_type() function.
1284 * A convenience macro for type implementations.
1285 * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the
1286 * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
1287 * See G_DEFINE_TYPE_EXTENDED() for an example.
1291 #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()
1293 * G_DEFINE_ABSTRACT_TYPE:
1294 * @TN: The name of the new type, in Camel case.
1295 * @t_n: The name of the new type, in lowercase, with words
1297 * @T_P: The #GType of the parent type.
1299 * A convenience macro for type implementations.
1300 * Similar to G_DEFINE_TYPE(), but defines an abstract type.
1301 * See G_DEFINE_TYPE_EXTENDED() for an example.
1305 #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
1307 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE:
1308 * @TN: The name of the new type, in Camel case.
1309 * @t_n: The name of the new type, in lowercase, with words
1311 * @T_P: The #GType of the parent type.
1312 * @_C_: Custom code that gets inserted in the @type_name_get_type() function.
1314 * A convenience macro for type implementations.
1315 * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and allows you to
1316 * insert custom code into the *_get_type() function, e.g. interface implementations
1317 * via G_IMPLEMENT_INTERFACE(). See G_DEFINE_TYPE_EXTENDED() for an example.
1321 #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()
1323 * G_DEFINE_TYPE_EXTENDED:
1324 * @TN: The name of the new type, in Camel case.
1325 * @t_n: The name of the new type, in lowercase, with words
1327 * @T_P: The #GType of the parent type.
1328 * @_f_: #GTypeFlags to pass to g_type_register_static()
1329 * @_C_: Custom code that gets inserted in the *_get_type() function.
1331 * The most general convenience macro for type implementations, on which
1332 * G_DEFINE_TYPE(), etc are based.
1335 * G_DEFINE_TYPE_EXTENDED (GtkGadget,
1339 * G_IMPLEMENT_INTERFACE (TYPE_GIZMO,
1340 * gtk_gadget_gizmo_init));
1344 * static void gtk_gadget_init (GtkGadget *self);
1345 * static void gtk_gadget_class_init (GtkGadgetClass *klass);
1346 * static gpointer gtk_gadget_parent_class = NULL;
1347 * static void gtk_gadget_class_intern_init (gpointer klass)
1349 * gtk_gadget_parent_class = g_type_class_peek_parent (klass);
1350 * gtk_gadget_class_init ((GtkGadgetClass*) klass);
1354 * gtk_gadget_get_type (void)
1356 * static volatile gsize g_define_type_id__volatile = 0;
1357 * if (g_once_init_enter (&g_define_type_id__volatile))
1359 * GType g_define_type_id =
1360 * g_type_register_static_simple (GTK_TYPE_WIDGET,
1361 * g_intern_static_string ("GtkGadget"),
1362 * sizeof (GtkGadgetClass),
1363 * (GClassInitFunc) gtk_gadget_class_intern_init,
1364 * sizeof (GtkGadget),
1365 * (GInstanceInitFunc) gtk_gadget_init,
1366 * (GTypeFlags) flags);
1368 * static const GInterfaceInfo g_implement_interface_info = {
1369 * (GInterfaceInitFunc) gtk_gadget_gizmo_init
1371 * g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
1373 * g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
1375 * return g_define_type_id__volatile;
1378 * The only pieces which have to be manually provided are the definitions of
1379 * the instance and class structure and the definitions of the instance and
1380 * class init functions.
1384 #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()
1387 * G_DEFINE_INTERFACE:
1388 * @TN: The name of the new type, in Camel case.
1389 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1390 * @T_P: The #GType of the prerequisite type for the interface, or 0
1391 * (%G_TYPE_INVALID) for no prerequisite type.
1393 * A convenience macro for #GTypeInterface definitions, which declares
1394 * a default vtable initialization function and defines a *_get_type()
1397 * The macro expects the interface initialization function to have the
1398 * name <literal>t_n ## _default_init</literal>, and the interface
1399 * structure to have the name <literal>TN ## Interface</literal>.
1403 #define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
1406 * G_DEFINE_INTERFACE_WITH_CODE:
1407 * @TN: The name of the new type, in Camel case.
1408 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1409 * @T_P: The #GType of the prerequisite type for the interface, or 0
1410 * (%G_TYPE_INVALID) for no prerequisite type.
1411 * @_C_: Custom code that gets inserted in the *_get_type() function.
1413 * A convenience macro for #GTypeInterface definitions. Similar to
1414 * G_DEFINE_INTERFACE(), but allows you to insert custom code into the
1415 * *_get_type() function, e.g. additional interface implementations
1416 * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See
1417 * G_DEFINE_TYPE_EXTENDED() for a similar example using
1418 * G_DEFINE_TYPE_WITH_CODE().
1422 #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()
1425 * G_IMPLEMENT_INTERFACE:
1426 * @TYPE_IFACE: The #GType of the interface to add
1427 * @iface_init: The interface init function
1429 * A convenience macro to ease interface addition in the @_C_ section
1430 * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1431 * See G_DEFINE_TYPE_EXTENDED() for an example.
1433 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1434 * macros, since it depends on variable names from those macros.
1438 #define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
1439 const GInterfaceInfo g_implement_interface_info = { \
1440 (GInterfaceInitFunc) iface_init, NULL, NULL \
1442 g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
1445 #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
1447 static void type_name##_init (TypeName *self); \
1448 static void type_name##_class_init (TypeName##Class *klass); \
1449 static gpointer type_name##_parent_class = NULL; \
1450 static void type_name##_class_intern_init (gpointer klass) \
1452 type_name##_parent_class = g_type_class_peek_parent (klass); \
1453 type_name##_class_init ((TypeName##Class*) klass); \
1457 type_name##_get_type (void) \
1459 static volatile gsize g_define_type_id__volatile = 0; \
1460 if (g_once_init_enter (&g_define_type_id__volatile)) \
1462 GType g_define_type_id = \
1463 g_type_register_static_simple (TYPE_PARENT, \
1464 g_intern_static_string (#TypeName), \
1465 sizeof (TypeName##Class), \
1466 (GClassInitFunc) type_name##_class_intern_init, \
1467 sizeof (TypeName), \
1468 (GInstanceInitFunc) type_name##_init, \
1469 (GTypeFlags) flags); \
1470 { /* custom code follows */
1471 #define _G_DEFINE_TYPE_EXTENDED_END() \
1472 /* following custom code */ \
1474 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
1476 return g_define_type_id__volatile; \
1477 } /* closes type_name##_get_type() */
1479 #define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
1481 static void type_name##_default_init (TypeName##Interface *klass); \
1484 type_name##_get_type (void) \
1486 static volatile gsize g_define_type_id__volatile = 0; \
1487 if (g_once_init_enter (&g_define_type_id__volatile)) \
1489 GType g_define_type_id = \
1490 g_type_register_static_simple (G_TYPE_INTERFACE, \
1491 g_intern_static_string (#TypeName), \
1492 sizeof (TypeName##Interface), \
1493 (GClassInitFunc)type_name##_default_init, \
1495 (GInstanceInitFunc)NULL, \
1498 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
1499 { /* custom code follows */
1500 #define _G_DEFINE_INTERFACE_EXTENDED_END() \
1501 /* following custom code */ \
1503 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
1505 return g_define_type_id__volatile; \
1506 } /* closes type_name##_get_type() */
1508 /* --- protected (for fundamental type implementations) --- */
1509 GTypePlugin
* g_type_get_plugin (GType type
);
1510 GTypePlugin
* g_type_interface_get_plugin (GType instance_type
,
1511 GType interface_type
);
1512 GType
g_type_fundamental_next (void);
1513 GType
g_type_fundamental (GType type_id
);
1514 GTypeInstance
* g_type_create_instance (GType type
);
1515 void g_type_free_instance (GTypeInstance
*instance
);
1517 void g_type_add_class_cache_func (gpointer cache_data
,
1518 GTypeClassCacheFunc cache_func
);
1519 void g_type_remove_class_cache_func (gpointer cache_data
,
1520 GTypeClassCacheFunc cache_func
);
1521 void g_type_class_unref_uncached (gpointer g_class
);
1523 void g_type_add_interface_check (gpointer check_data
,
1524 GTypeInterfaceCheckFunc check_func
);
1525 void g_type_remove_interface_check (gpointer check_data
,
1526 GTypeInterfaceCheckFunc check_func
);
1528 GTypeValueTable
* g_type_value_table_peek (GType type
);
1532 gboolean
g_type_check_instance (GTypeInstance
*instance
) G_GNUC_PURE
;
1533 GTypeInstance
* g_type_check_instance_cast (GTypeInstance
*instance
,
1535 gboolean
g_type_check_instance_is_a (GTypeInstance
*instance
,
1536 GType iface_type
) G_GNUC_PURE
;
1537 GTypeClass
* g_type_check_class_cast (GTypeClass
*g_class
,
1539 gboolean
g_type_check_class_is_a (GTypeClass
*g_class
,
1540 GType is_a_type
) G_GNUC_PURE
;
1541 gboolean
g_type_check_is_value_type (GType type
) G_GNUC_CONST
;
1542 gboolean
g_type_check_value (GValue
*value
) G_GNUC_PURE
;
1543 gboolean
g_type_check_value_holds (GValue
*value
,
1544 GType type
) G_GNUC_PURE
;
1545 gboolean
g_type_test_flags (GType type
,
1546 guint flags
) G_GNUC_CONST
;
1549 /* --- debugging functions --- */
1550 G_CONST_RETURN gchar
* g_type_name_from_instance (GTypeInstance
*instance
);
1551 G_CONST_RETURN gchar
* g_type_name_from_class (GTypeClass
*g_class
);
1554 /* --- internal functions --- */
1555 G_GNUC_INTERNAL
void g_value_c_init (void); /* sync with gvalue.c */
1556 G_GNUC_INTERNAL
void g_value_types_init (void); /* sync with gvaluetypes.c */
1557 G_GNUC_INTERNAL
void g_enum_types_init (void); /* sync with genums.c */
1558 G_GNUC_INTERNAL
void g_param_type_init (void); /* sync with gparam.c */
1559 G_GNUC_INTERNAL
void g_boxed_type_init (void); /* sync with gboxed.c */
1560 G_GNUC_INTERNAL
void g_object_type_init (void); /* sync with gobject.c */
1561 G_GNUC_INTERNAL
void g_param_spec_types_init (void); /* sync with gparamspecs.c */
1562 G_GNUC_INTERNAL
void g_value_transforms_init (void); /* sync with gvaluetransform.c */
1563 G_GNUC_INTERNAL
void g_signal_init (void); /* sync with gsignal.c */
1566 /* --- implementation bits --- */
1567 #ifndef G_DISABLE_CAST_CHECKS
1568 # define _G_TYPE_CIC(ip, gt, ct) \
1569 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
1570 # define _G_TYPE_CCC(cp, gt, ct) \
1571 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
1572 #else /* G_DISABLE_CAST_CHECKS */
1573 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
1574 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
1575 #endif /* G_DISABLE_CAST_CHECKS */
1576 #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
1577 #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
1578 #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
1579 #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
1581 # define _G_TYPE_CIT(ip, gt) (G_GNUC_EXTENSION ({ \
1582 GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
1585 else if (__inst->g_class && __inst->g_class->g_type == __t) \
1588 __r = g_type_check_instance_is_a (__inst, __t); \
1591 # define _G_TYPE_CCT(cp, gt) (G_GNUC_EXTENSION ({ \
1592 GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
1595 else if (__class->g_type == __t) \
1598 __r = g_type_check_class_is_a (__class, __t); \
1601 # define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \
1602 GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \
1605 else if (__val->g_type == __t) \
1608 __r = g_type_check_value_holds (__val, __t); \
1611 #else /* !__GNUC__ */
1612 # define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt))
1613 # define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt))
1614 # define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
1615 #endif /* !__GNUC__ */
1617 * G_TYPE_FLAG_RESERVED_ID_BIT:
1619 * A bit in the type number that's supposed to be left untouched.
1621 #define G_TYPE_FLAG_RESERVED_ID_BIT ((GType) (1 << 0))
1622 extern GTypeDebugFlags _g_type_debug_flags
;
1626 #endif /* __G_TYPE_H__ */