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