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