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