1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module gobject.gtype; 7 8 import gobject.gvalue; 9 import glib; 10 11 12 alias G_TYPE_FUNDAMENTAL = g_type_fundamental; 13 14 15 16 private enum G_TYPE_FUNDAMENTAL_SHIFT = 2; 17 18 GType G_TYPE_MAKE_FUNDAMENTAL(X)(X x) { return x << G_TYPE_FUNDAMENTAL_SHIFT; } 19 20 enum GType G_TYPE_FUNDAMENTAL_MAX = 255 << G_TYPE_FUNDAMENTAL_SHIFT; 21 22 enum G_TYPE_INVALID = G_TYPE_MAKE_FUNDAMENTAL (0); 23 enum G_TYPE_NONE = G_TYPE_MAKE_FUNDAMENTAL (1); 24 enum G_TYPE_INTERFACE = G_TYPE_MAKE_FUNDAMENTAL (2); 25 enum G_TYPE_CHAR = G_TYPE_MAKE_FUNDAMENTAL (3); 26 enum G_TYPE_UCHAR = G_TYPE_MAKE_FUNDAMENTAL (4); 27 enum G_TYPE_BOOLEAN = G_TYPE_MAKE_FUNDAMENTAL (5); 28 enum G_TYPE_INT = G_TYPE_MAKE_FUNDAMENTAL (6); 29 enum G_TYPE_UINT = G_TYPE_MAKE_FUNDAMENTAL (7); 30 enum G_TYPE_LONG = G_TYPE_MAKE_FUNDAMENTAL (8); 31 enum G_TYPE_ULONG = G_TYPE_MAKE_FUNDAMENTAL (9); 32 enum G_TYPE_INT64 = G_TYPE_MAKE_FUNDAMENTAL (10); 33 enum G_TYPE_UINT64 = G_TYPE_MAKE_FUNDAMENTAL (11); 34 enum G_TYPE_ENUM = G_TYPE_MAKE_FUNDAMENTAL (12); 35 enum G_TYPE_FLAGS = G_TYPE_MAKE_FUNDAMENTAL (13); 36 enum G_TYPE_FLOAT = G_TYPE_MAKE_FUNDAMENTAL (14); 37 enum G_TYPE_DOUBLE = G_TYPE_MAKE_FUNDAMENTAL (15); 38 enum G_TYPE_STRING = G_TYPE_MAKE_FUNDAMENTAL (16); 39 enum G_TYPE_POINTER = G_TYPE_MAKE_FUNDAMENTAL (17); 40 enum G_TYPE_BOXED = G_TYPE_MAKE_FUNDAMENTAL (18); 41 enum G_TYPE_PARAM = G_TYPE_MAKE_FUNDAMENTAL (19); 42 enum G_TYPE_OBJECT = G_TYPE_MAKE_FUNDAMENTAL (20); 43 enum G_TYPE_VARIANT = G_TYPE_MAKE_FUNDAMENTAL (21); 44 45 enum G_TYPE_RESERVED_GLIB_FIRST = (22); 46 enum G_TYPE_RESERVED_GLIB_LAST = (31); 47 enum G_TYPE_RESERVED_BSE_FIRST = (32); 48 enum G_TYPE_RESERVED_BSE_LAST = (48); 49 enum G_TYPE_RESERVED_USER_FIRST = (49); 50 51 auto G_TYPE_IS_FUNDAMENTAL(GType t) { return t <= G_TYPE_FUNDAMENTAL_MAX; } 52 auto G_TYPE_IS_DERIVED(GType t) { return t > G_TYPE_FUNDAMENTAL_MAX; } 53 auto G_TYPE_IS_INTERFACE(GType t) { return G_TYPE_FUNDAMENTAL(t) == G_TYPE_INTERFACE; } 54 auto G_TYPE_IS_CLASSED(GType t) { return g_type_test_flags(t, GTypeFundamentalFlags.G_TYPE_FLAG_CLASSED); } 55 auto G_TYPE_IS_INSTANTIATABLE(GType t) { return g_type_test_flags(t, GTypeFundamentalFlags.G_TYPE_FLAG_INSTANTIATABLE); } 56 auto G_TYPE_IS_DERIVABLE(GType t) { return g_type_test_flags(t, GTypeFundamentalFlags.G_TYPE_FLAG_DERIVABLE); } 57 auto G_TYPE_IS_DEEP_DERIVABLE(GType t) { return g_type_test_flags(t, GTypeFundamentalFlags.G_TYPE_FLAG_DEEP_DERIVABLE); } 58 auto G_TYPE_IS_ABSTRACT(GType t) { return g_type_test_flags(t, GTypeFlags.G_TYPE_FLAG_ABSTRACT); } 59 auto G_TYPE_IS_VALUE_ABSTRACT(GType t) { return g_type_test_flags(t, GTypeFlags.G_TYPE_FLAG_VALUE_ABSTRACT); } 60 auto G_TYPE_IS_VALUE_TYPE(GType t) { return g_type_check_is_value_type(t); } 61 auto G_TYPE_HAS_VALUE_TABLE(GType t) { return g_type_value_table_peek(t) !is null; } 62 63 alias GType = gsize; 64 65 66 union GTypeCValue; 67 struct GTypePlugin; 68 69 70 struct GTypeClass 71 { 72 /*< private >*/ 73 GType g_type; 74 } 75 76 struct GTypeInstance 77 { 78 /*< private >*/ 79 GTypeClass *g_class; 80 } 81 82 struct GTypeInterface 83 { 84 /*< private >*/ 85 GType g_type; /* iface type */ 86 GType g_instance_type; 87 } 88 89 struct GTypeQuery 90 { 91 GType type; 92 const(gchar) *type_name; 93 guint class_size; 94 guint instance_size; 95 } 96 97 98 99 enum GTypeDebugFlags 100 { 101 G_TYPE_DEBUG_NONE = 0, 102 G_TYPE_DEBUG_OBJECTS = 1 << 0, 103 G_TYPE_DEBUG_SIGNALS = 1 << 1, 104 G_TYPE_DEBUG_MASK = 0x03 105 } 106 107 enum GTypeFundamentalFlags 108 { 109 G_TYPE_FLAG_CLASSED = (1 << 0), 110 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1), 111 G_TYPE_FLAG_DERIVABLE = (1 << 2), 112 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3) 113 } 114 115 enum GTypeFlags 116 { 117 G_TYPE_FLAG_ABSTRACT = (1 << 4), 118 G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5) 119 } 120 121 struct GTypeInfo 122 { 123 /* interface types, classed types, instantiated types */ 124 guint16 class_size; 125 126 GBaseInitFunc base_init; 127 GBaseFinalizeFunc base_finalize; 128 129 /* interface types, classed types, instantiated types */ 130 GClassInitFunc class_init; 131 GClassFinalizeFunc class_finalize; 132 gconstpointer class_data; 133 134 /* instantiated types */ 135 guint16 instance_size; 136 guint16 n_preallocs; 137 GInstanceInitFunc instance_init; 138 139 /* value handling */ 140 const(GTypeValueTable) *value_table; 141 } 142 143 struct GTypeFundamentalInfo 144 { 145 GTypeFundamentalFlags type_flags; 146 } 147 148 struct GInterfaceInfo 149 { 150 GInterfaceInitFunc interface_init; 151 GInterfaceFinalizeFunc interface_finalize; 152 gpointer interface_data; 153 } 154 155 156 extern (C) { 157 158 struct GTypeValueTable 159 { 160 void function (GValue *value) value_init; 161 void function (GValue *value) value_free; 162 void function (const(GValue) *src_value, 163 GValue *dest_value) value_copy; 164 165 gpointer function (const(GValue) *value) value_peek_pointer; 166 167 const(gchar) *collect_format; 168 169 gchar* function (GValue *value, 170 guint n_collect_values, 171 GTypeCValue *collect_values, 172 guint collect_flags) collect_value; 173 174 const(gchar) *lcopy_format; 175 176 gchar* function (const(GValue) *value, 177 guint n_collect_values, 178 GTypeCValue *collect_values, 179 guint collect_flags) lcopy_value; 180 } 181 182 183 alias GBaseInitFunc = void function (gpointer g_class); 184 alias GBaseFinalizeFunc = void function (gpointer g_class); 185 alias GClassInitFunc = void function (gpointer g_class, 186 gpointer class_data); 187 alias GClassFinalizeFunc = void function (gpointer g_class, 188 gpointer class_data); 189 alias GInstanceInitFunc = void function (GTypeInstance *instance, 190 gpointer g_class); 191 alias GInterfaceInitFunc = void function (gpointer g_iface, 192 gpointer iface_data); 193 alias GInterfaceFinalizeFunc = void function (gpointer g_iface, 194 gpointer iface_data); 195 alias GTypeClassCacheFunc = gboolean function (gpointer cache_data, 196 GTypeClass *g_class); 197 alias GTypeInterfaceCheckFunc = void function (gpointer check_data, 198 gpointer g_iface); 199 200 201 202 /* --- prototypes --- */ 203 deprecated 204 void g_type_init (); 205 deprecated 206 void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags); 207 208 const(gchar) * g_type_name (GType type); 209 210 GQuark g_type_qname (GType type); 211 212 GType g_type_from_name (const(gchar) *name); 213 214 GType g_type_parent (GType type); 215 216 guint g_type_depth (GType type); 217 218 GType g_type_next_base (GType leaf_type, 219 GType root_type); 220 221 gboolean g_type_is_a (GType type, 222 GType is_a_type); 223 224 gpointer g_type_class_ref (GType type); 225 226 gpointer g_type_class_peek (GType type); 227 228 gpointer g_type_class_peek_static (GType type); 229 230 void g_type_class_unref (gpointer g_class); 231 232 gpointer g_type_class_peek_parent (gpointer g_class); 233 234 gpointer g_type_interface_peek (gpointer instance_class, 235 GType iface_type); 236 237 gpointer g_type_interface_peek_parent (gpointer g_iface); 238 239 240 gpointer g_type_default_interface_ref (GType g_type); 241 242 gpointer g_type_default_interface_peek (GType g_type); 243 244 void g_type_default_interface_unref (gpointer g_iface); 245 246 /* g_free() the returned arrays */ 247 248 GType* g_type_children (GType type, 249 guint *n_children); 250 251 GType* g_type_interfaces (GType type, 252 guint *n_interfaces); 253 254 /* per-type _static_ data */ 255 256 void g_type_set_qdata (GType type, 257 GQuark quark, 258 gpointer data); 259 260 gpointer g_type_get_qdata (GType type, 261 GQuark quark); 262 263 void g_type_query (GType type, 264 GTypeQuery *query); 265 266 267 GType g_type_register_static (GType parent_type, 268 const(gchar) *type_name, 269 const(GTypeInfo) *info, 270 GTypeFlags flags); 271 272 GType g_type_register_static_simple (GType parent_type, 273 const(gchar) *type_name, 274 guint class_size, 275 GClassInitFunc class_init, 276 guint instance_size, 277 GInstanceInitFunc instance_init, 278 GTypeFlags flags); 279 280 281 GType g_type_register_dynamic (GType parent_type, 282 const(gchar) *type_name, 283 GTypePlugin *plugin, 284 GTypeFlags flags); 285 286 GType g_type_register_fundamental (GType type_id, 287 const(gchar) *type_name, 288 const(GTypeInfo) *info, 289 const(GTypeFundamentalInfo) *finfo, 290 GTypeFlags flags); 291 292 void g_type_add_interface_static (GType instance_type, 293 GType interface_type, 294 const(GInterfaceInfo) *info); 295 296 void g_type_add_interface_dynamic (GType instance_type, 297 GType interface_type, 298 GTypePlugin *plugin); 299 300 void g_type_interface_add_prerequisite (GType interface_type, 301 GType prerequisite_type); 302 303 GType*g_type_interface_prerequisites (GType interface_type, 304 guint *n_prerequisites); 305 306 void g_type_class_add_private (gpointer g_class, 307 gsize private_size); 308 309 gint g_type_add_instance_private (GType class_type, 310 gsize private_size); 311 312 gpointer g_type_instance_get_private (GTypeInstance *instance, 313 GType private_type); 314 315 void g_type_class_adjust_private_offset (gpointer g_class, 316 gint *private_size_or_offset); 317 318 319 void g_type_add_class_private (GType class_type, 320 gsize private_size); 321 322 gpointer g_type_class_get_private (GTypeClass *klass, 323 GType private_type); 324 325 gint g_type_class_get_instance_private_offset (gpointer g_class); 326 327 328 void g_type_ensure (GType type); 329 330 guint g_type_get_type_registration_serial (); 331 332 } 333 334 // #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance))) 335 // /** 336 // * G_TYPE_CHECK_INSTANCE_CAST: 337 // * @instance: Location of a #GTypeInstance structure 338 // * @g_type: The type to be returned 339 // * @c_type: The corresponding C type of @g_type 340 // * 341 // * Checks that @instance is an instance of the type identified by @g_type 342 // * and issues a warning if this is not the case. Returns @instance casted 343 // * to a pointer to @c_type. 344 // * 345 // * This macro should only be used in type implementations. 346 // */ 347 // #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type)) 348 // /** 349 // * G_TYPE_CHECK_INSTANCE_TYPE: 350 // * @instance: Location of a #GTypeInstance structure. 351 // * @g_type: The type to be checked 352 // * 353 // * Checks if @instance is an instance of the type identified by @g_type. 354 // * 355 // * This macro should only be used in type implementations. 356 // * 357 // * Returns: %TRUE on success 358 // */ 359 // #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type))) 360 // /** 361 // * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE: 362 // * @instance: Location of a #GTypeInstance structure. 363 // * @g_type: The fundamental type to be checked 364 // * 365 // * Checks if @instance is an instance of the fundamental type identified by @g_type. 366 // * 367 // * This macro should only be used in type implementations. 368 // * 369 // * Returns: %TRUE on success 370 // */ 371 // #define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type) (_G_TYPE_CIFT ((instance), (g_type))) 372 // /** 373 // * G_TYPE_INSTANCE_GET_CLASS: 374 // * @instance: Location of the #GTypeInstance structure 375 // * @g_type: The #GType of the class to be returned 376 // * @c_type: The C type of the class structure 377 // * 378 // * Get the class structure of a given @instance, casted 379 // * to a specified ancestor type @g_type of the instance. 380 // * 381 // * Note that while calling a GInstanceInitFunc(), the class pointer 382 // * gets modified, so it might not always return the expected pointer. 383 // * 384 // * This macro should only be used in type implementations. 385 // * 386 // * Returns: a pointer to the class structure 387 // */ 388 // #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type)) 389 // /** 390 // * G_TYPE_INSTANCE_GET_INTERFACE: 391 // * @instance: Location of the #GTypeInstance structure 392 // * @g_type: The #GType of the interface to be returned 393 // * @c_type: The C type of the interface structure 394 // * 395 // * Get the interface structure for interface @g_type of a given @instance. 396 // * 397 // * This macro should only be used in type implementations. 398 // * 399 // * Returns: a pointer to the interface structure 400 // */ 401 // #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type)) 402 // /** 403 // * G_TYPE_CHECK_CLASS_CAST: 404 // * @g_class: Location of a #GTypeClass structure 405 // * @g_type: The type to be returned 406 // * @c_type: The corresponding C type of class structure of @g_type 407 // * 408 // * Checks that @g_class is a class structure of the type identified by @g_type 409 // * and issues a warning if this is not the case. Returns @g_class casted 410 // * to a pointer to @c_type. 411 // * 412 // * This macro should only be used in type implementations. 413 // */ 414 // #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type)) 415 // /** 416 // * G_TYPE_CHECK_CLASS_TYPE: 417 // * @g_class: Location of a #GTypeClass structure 418 // * @g_type: The type to be checked 419 // * 420 // * Checks if @g_class is a class structure of the type identified by 421 // * @g_type. 422 // * 423 // * This macro should only be used in type implementations. 424 // * 425 // * Returns: %TRUE on success 426 // */ 427 // #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type))) 428 // /** 429 // * G_TYPE_CHECK_VALUE: 430 // * @value: a #GValue 431 // * 432 // * Checks if @value has been initialized to hold values 433 // * of a value type. 434 // * 435 // * This macro should only be used in type implementations. 436 // * 437 // * Returns: %TRUE on success 438 // */ 439 // #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value))) 440 // /** 441 // * G_TYPE_CHECK_VALUE_TYPE: 442 // * @value: a #GValue 443 // * @g_type: The type to be checked 444 // * 445 // * Checks if @value has been initialized to hold values 446 // * of type @g_type. 447 // * 448 // * This macro should only be used in type implementations. 449 // * 450 // * Returns: %TRUE on success 451 // */ 452 // #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type))) 453 // /** 454 // * G_TYPE_FROM_INSTANCE: 455 // * @instance: Location of a valid #GTypeInstance structure 456 // * 457 // * Get the type identifier from a given @instance structure. 458 // * 459 // * This macro should only be used in type implementations. 460 // * 461 // * Returns: the #GType 462 // */ 463 auto G_TYPE_FROM_INSTANCE(I)(I instance) { return G_TYPE_FROM_CLASS((cast(GTypeInstance*)instance).g_class); } 464 // #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class)) 465 // /** 466 // * G_TYPE_FROM_CLASS: 467 // * @g_class: Location of a valid #GTypeClass structure 468 // * 469 // * Get the type identifier from a given @class structure. 470 // * 471 // * This macro should only be used in type implementations. 472 // * 473 // * Returns: the #GType 474 // */ 475 auto G_TYPE_FROM_CLASS(GC)(GC g_class) { return (cast(GTypeClass*)g_class).g_type; } 476 // #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type) 477 // /** 478 // * G_TYPE_FROM_INTERFACE: 479 // * @g_iface: Location of a valid #GTypeInterface structure 480 // * 481 // * Get the type identifier from a given @interface structure. 482 // * 483 // * This macro should only be used in type implementations. 484 // * 485 // * Returns: the #GType 486 // */ 487 auto G_TYPE_FROM_INTERFACE(GI)(GI g_iface) { return (cast(GTypeInterface*)g_iface).g_type; } 488 // #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type) 489 // 490 // /** 491 // * G_TYPE_INSTANCE_GET_PRIVATE: 492 // * @instance: the instance of a type deriving from @private_type 493 // * @g_type: the type identifying which private data to retrieve 494 // * @c_type: The C type for the private structure 495 // * 496 // * Gets the private structure for a particular type. 497 // * The private structure must have been registered in the 498 // * class_init function with g_type_class_add_private(). 499 // * 500 // * This macro should only be used in type implementations. 501 // * 502 // * Since: 2.4 503 // * Returns: a pointer to the private data structure 504 // */ 505 // #define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type))) 506 // 507 // /** 508 // * G_TYPE_CLASS_GET_PRIVATE: 509 // * @klass: the class of a type deriving from @private_type 510 // * @g_type: the type identifying which private data to retrieve 511 // * @c_type: The C type for the private structure 512 // * 513 // * Gets the private class structure for a particular type. 514 // * The private structure must have been registered in the 515 // * get_type() function with g_type_add_class_private(). 516 // * 517 // * This macro should only be used in type implementations. 518 // * 519 // * Since: 2.24 520 // * Returns: a pointer to the private data structure 521 // */ 522 // #define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type))) 523 524 525 526 // /* --- GType boilerplate --- */ 527 // /** 528 // * G_DEFINE_TYPE: 529 // * @TN: The name of the new type, in Camel case. 530 // * @t_n: The name of the new type, in lowercase, with words 531 // * separated by '_'. 532 // * @T_P: The #GType of the parent type. 533 // * 534 // * A convenience macro for type implementations, which declares a class 535 // * initialization function, an instance initialization function (see #GTypeInfo 536 // * for information about these) and a static variable named `t_n_parent_class` 537 // * pointing to the parent class. Furthermore, it defines a *_get_type() function. 538 // * See G_DEFINE_TYPE_EXTENDED() for an example. 539 // * 540 // * Since: 2.4 541 // */ 542 // #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) 543 // /** 544 // * G_DEFINE_TYPE_WITH_CODE: 545 // * @TN: The name of the new type, in Camel case. 546 // * @t_n: The name of the new type in lowercase, with words separated by '_'. 547 // * @T_P: The #GType of the parent type. 548 // * @_C_: Custom code that gets inserted in the *_get_type() function. 549 // * 550 // * A convenience macro for type implementations. 551 // * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the 552 // * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE(). 553 // * See G_DEFINE_TYPE_EXTENDED() for an example. 554 // * 555 // * Since: 2.4 556 // */ 557 // #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() 558 // /** 559 // * G_DEFINE_TYPE_WITH_PRIVATE: 560 // * @TN: The name of the new type, in Camel case. 561 // * @t_n: The name of the new type, in lowercase, with words 562 // * separated by '_'. 563 // * @T_P: The #GType of the parent type. 564 // * 565 // * A convenience macro for type implementations, which declares a class 566 // * initialization function, an instance initialization function (see #GTypeInfo 567 // * for information about these), a static variable named `t_n_parent_class` 568 // * pointing to the parent class, and adds private instance data to the type. 569 // * Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED() 570 // * for an example. 571 // * 572 // * Note that private structs added with this macros must have a struct 573 // * name of the form @TN Private. 574 // * 575 // * Since: 2.38 576 // */ 577 // #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)) 578 // /** 579 // * G_DEFINE_ABSTRACT_TYPE: 580 // * @TN: The name of the new type, in Camel case. 581 // * @t_n: The name of the new type, in lowercase, with words 582 // * separated by '_'. 583 // * @T_P: The #GType of the parent type. 584 // * 585 // * A convenience macro for type implementations. 586 // * Similar to G_DEFINE_TYPE(), but defines an abstract type. 587 // * See G_DEFINE_TYPE_EXTENDED() for an example. 588 // * 589 // * Since: 2.4 590 // */ 591 // #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {}) 592 // /** 593 // * G_DEFINE_ABSTRACT_TYPE_WITH_CODE: 594 // * @TN: The name of the new type, in Camel case. 595 // * @t_n: The name of the new type, in lowercase, with words 596 // * separated by '_'. 597 // * @T_P: The #GType of the parent type. 598 // * @_C_: Custom code that gets inserted in the @type_name_get_type() function. 599 // * 600 // * A convenience macro for type implementations. 601 // * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and 602 // * allows you to insert custom code into the *_get_type() function, e.g. 603 // * interface implementations via G_IMPLEMENT_INTERFACE(). 604 // * See G_DEFINE_TYPE_EXTENDED() for an example. 605 // * 606 // * Since: 2.4 607 // */ 608 // #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() 609 // /** 610 // * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE: 611 // * @TN: The name of the new type, in Camel case. 612 // * @t_n: The name of the new type, in lowercase, with words 613 // * separated by '_'. 614 // * @T_P: The #GType of the parent type. 615 // * 616 // * Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type. 617 // * See G_DEFINE_TYPE_EXTENDED() for an example. 618 // * 619 // * Since: 2.38 620 // */ 621 // #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)) 622 // /** 623 // * G_DEFINE_TYPE_EXTENDED: 624 // * @TN: The name of the new type, in Camel case. 625 // * @t_n: The name of the new type, in lowercase, with words 626 // * separated by '_'. 627 // * @T_P: The #GType of the parent type. 628 // * @_f_: #GTypeFlags to pass to g_type_register_static() 629 // * @_C_: Custom code that gets inserted in the *_get_type() function. 630 // * 631 // * The most general convenience macro for type implementations, on which 632 // * G_DEFINE_TYPE(), etc are based. 633 // * 634 // * |[<!-- language="C" --> 635 // * G_DEFINE_TYPE_EXTENDED (GtkGadget, 636 // * gtk_gadget, 637 // * GTK_TYPE_WIDGET, 638 // * 0, 639 // * G_IMPLEMENT_INTERFACE (TYPE_GIZMO, 640 // * gtk_gadget_gizmo_init)); 641 // * ]| 642 // * expands to 643 // * |[<!-- language="C" --> 644 // * static void gtk_gadget_init (GtkGadget *self); 645 // * static void gtk_gadget_class_init (GtkGadgetClass *klass); 646 // * static gpointer gtk_gadget_parent_class = NULL; 647 // * static void gtk_gadget_class_intern_init (gpointer klass) 648 // * { 649 // * gtk_gadget_parent_class = g_type_class_peek_parent (klass); 650 // * gtk_gadget_class_init ((GtkGadgetClass*) klass); 651 // * } 652 // * 653 // * GType 654 // * gtk_gadget_get_type (void) 655 // * { 656 // * static volatile gsize g_define_type_id__volatile = 0; 657 // * if (g_once_init_enter (&g_define_type_id__volatile)) 658 // * { 659 // * GType g_define_type_id = 660 // * g_type_register_static_simple (GTK_TYPE_WIDGET, 661 // * g_intern_static_string ("GtkGadget"), 662 // * sizeof (GtkGadgetClass), 663 // * (GClassInitFunc) gtk_gadget_class_intern_init, 664 // * sizeof (GtkGadget), 665 // * (GInstanceInitFunc) gtk_gadget_init, 666 // * 0); 667 // * { 668 // * const GInterfaceInfo g_implement_interface_info = { 669 // * (GInterfaceInitFunc) gtk_gadget_gizmo_init 670 // * }; 671 // * g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info); 672 // * } 673 // * g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); 674 // * } 675 // * return g_define_type_id__volatile; 676 // * } 677 // * ]| 678 // * The only pieces which have to be manually provided are the definitions of 679 // * the instance and class structure and the definitions of the instance and 680 // * class init functions. 681 // * 682 // * Since: 2.4 683 // */ 684 // #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() 685 // 686 // /** 687 // * G_DEFINE_INTERFACE: 688 // * @TN: The name of the new type, in Camel case. 689 // * @t_n: The name of the new type, in lowercase, with words separated by '_'. 690 // * @T_P: The #GType of the prerequisite type for the interface, or 0 691 // * (%G_TYPE_INVALID) for no prerequisite type. 692 // * 693 // * A convenience macro for #GTypeInterface definitions, which declares 694 // * a default vtable initialization function and defines a *_get_type() 695 // * function. 696 // * 697 // * The macro expects the interface initialization function to have the 698 // * name `t_n ## _default_init`, and the interface structure to have the 699 // * name `TN ## Interface`. 700 // * 701 // * Since: 2.24 702 // */ 703 // #define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;) 704 // 705 // /** 706 // * G_DEFINE_INTERFACE_WITH_CODE: 707 // * @TN: The name of the new type, in Camel case. 708 // * @t_n: The name of the new type, in lowercase, with words separated by '_'. 709 // * @T_P: The #GType of the prerequisite type for the interface, or 0 710 // * (%G_TYPE_INVALID) for no prerequisite type. 711 // * @_C_: Custom code that gets inserted in the *_get_type() function. 712 // * 713 // * A convenience macro for #GTypeInterface definitions. Similar to 714 // * G_DEFINE_INTERFACE(), but allows you to insert custom code into the 715 // * *_get_type() function, e.g. additional interface implementations 716 // * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See 717 // * G_DEFINE_TYPE_EXTENDED() for a similar example using 718 // * G_DEFINE_TYPE_WITH_CODE(). 719 // * 720 // * Since: 2.24 721 // */ 722 // #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() 723 // 724 // /** 725 // * G_IMPLEMENT_INTERFACE: 726 // * @TYPE_IFACE: The #GType of the interface to add 727 // * @iface_init: The interface init function 728 // * 729 // * A convenience macro to ease interface addition in the `_C_` section 730 // * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). 731 // * See G_DEFINE_TYPE_EXTENDED() for an example. 732 // * 733 // * Note that this macro can only be used together with the G_DEFINE_TYPE_* 734 // * macros, since it depends on variable names from those macros. 735 // * 736 // * Since: 2.4 737 // */ 738 // #define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \ 739 // const GInterfaceInfo g_implement_interface_info = { \ 740 // (GInterfaceInitFunc) iface_init, NULL, NULL \ 741 // }; \ 742 // g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ 743 // } 744 // 745 // /** 746 // * G_ADD_PRIVATE: 747 // * @TypeName: the name of the type in CamelCase 748 // * 749 // * A convenience macro to ease adding private data to instances of a new type 750 // * in the @_C_ section of G_DEFINE_TYPE_WITH_CODE() or 751 // * G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). 752 // * 753 // * For instance: 754 // * 755 // * |[<!-- language="C" --> 756 // * typedef struct _MyObject MyObject; 757 // * typedef struct _MyObjectClass MyObjectClass; 758 // * 759 // * typedef struct { 760 // * gint foo; 761 // * gint bar; 762 // * } MyObjectPrivate; 763 // * 764 // * G_DEFINE_TYPE_WITH_CODE (MyObject, my_object, G_TYPE_OBJECT, 765 // * G_ADD_PRIVATE (MyObject)) 766 // * ]| 767 // * 768 // * Will add MyObjectPrivate as the private data to any instance of the MyObject 769 // * type. 770 // * 771 // * G_DEFINE_TYPE_* macros will automatically create a private function 772 // * based on the arguments to this macro, which can be used to safely 773 // * retrieve the private data from an instance of the type; for instance: 774 // * 775 // * |[<!-- language="C" --> 776 // * gint 777 // * my_object_get_foo (MyObject *obj) 778 // * { 779 // * MyObjectPrivate *priv = my_object_get_instance_private (obj); 780 // * 781 // * return priv->foo; 782 // * } 783 // * 784 // * void 785 // * my_object_set_bar (MyObject *obj, 786 // * gint bar) 787 // * { 788 // * MyObjectPrivate *priv = my_object_get_instance_private (obj); 789 // * 790 // * if (priv->bar != bar) 791 // * priv->bar = bar; 792 // * } 793 // * ]| 794 // * 795 // * Note that this macro can only be used together with the G_DEFINE_TYPE_* 796 // * macros, since it depends on variable names from those macros. 797 // * 798 // * Also note that private structs added with these macros must have a struct 799 // * name of the form `TypeNamePrivate`. 800 // * 801 // * Since: 2.38 802 // */ 803 // #define G_ADD_PRIVATE(TypeName) { \ 804 // TypeName##_private_offset = \ 805 // g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \ 806 // } 807 // 808 // /** 809 // * G_PRIVATE_OFFSET: 810 // * @TypeName: the name of the type in CamelCase 811 // * @field: the name of the field in the private data structure 812 // * 813 // * Evaluates to the offset of the @field inside the instance private data 814 // * structure for @TypeName. 815 // * 816 // * Note that this macro can only be used together with the G_DEFINE_TYPE_* 817 // * and G_ADD_PRIVATE() macros, since it depends on variable names from 818 // * those macros. 819 // * 820 // * Since: 2.38 821 // */ 822 // #define G_PRIVATE_OFFSET(TypeName, field) \ 823 // (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field))) 824 // 825 // /** 826 // * G_PRIVATE_FIELD_P: 827 // * @TypeName: the name of the type in CamelCase 828 // * @inst: the instance of @TypeName you wish to access 829 // * @field_name: the name of the field in the private data structure 830 // * 831 // * Evaluates to a pointer to the @field_name inside the @inst private data 832 // * structure for @TypeName. 833 // * 834 // * Note that this macro can only be used together with the G_DEFINE_TYPE_* 835 // * and G_ADD_PRIVATE() macros, since it depends on variable names from 836 // * those macros. 837 // * 838 // * Since: 2.38 839 // */ 840 // #define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \ 841 // G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name)) 842 // 843 // /** 844 // * G_PRIVATE_FIELD: 845 // * @TypeName: the name of the type in CamelCase 846 // * @inst: the instance of @TypeName you wish to access 847 // * @field_type: the type of the field in the private data structure 848 // * @field_name: the name of the field in the private data structure 849 // * 850 // * Evaluates to the @field_name inside the @inst private data 851 // * structure for @TypeName. 852 // * 853 // * Note that this macro can only be used together with the G_DEFINE_TYPE_* 854 // * and G_ADD_PRIVATE() macros, since it depends on variable names from 855 // * those macros. 856 // * 857 // * Since: 2.38 858 // */ 859 // #define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \ 860 // G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name)) 861 // 862 // /* we need to have this macro under conditional expansion, as it references 863 // * a function that has been added in 2.38. see bug: 864 // * https://bugzilla.gnome.org/show_bug.cgi?id=703191 865 // */ 866 // #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 867 // #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ 868 // static void type_name##_class_intern_init (gpointer klass) \ 869 // { \ 870 // type_name##_parent_class = g_type_class_peek_parent (klass); \ 871 // if (TypeName##_private_offset != 0) \ 872 // g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \ 873 // type_name##_class_init ((TypeName##Class*) klass); \ 874 // } 875 // 876 // #else 877 // #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ 878 // static void type_name##_class_intern_init (gpointer klass) \ 879 // { \ 880 // type_name##_parent_class = g_type_class_peek_parent (klass); \ 881 // type_name##_class_init ((TypeName##Class*) klass); \ 882 // } 883 // #endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */ 884 // 885 // #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ 886 // \ 887 // static void type_name##_init (TypeName *self); \ 888 // static void type_name##_class_init (TypeName##Class *klass); \ 889 // static gpointer type_name##_parent_class = NULL; \ 890 // static gint TypeName##_private_offset; \ 891 // \ 892 // _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ 893 // \ 894 // G_GNUC_UNUSED \ 895 // static inline gpointer \ 896 // type_name##_get_instance_private (TypeName *self) \ 897 // { \ 898 // return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ 899 // } \ 900 // \ 901 // GType \ 902 // type_name##_get_type (void) \ 903 // { \ 904 // static volatile gsize g_define_type_id__volatile = 0; \ 905 // if (g_once_init_enter (&g_define_type_id__volatile)) \ 906 // { \ 907 // GType g_define_type_id = \ 908 // g_type_register_static_simple (TYPE_PARENT, \ 909 // g_intern_static_string (#TypeName), \ 910 // sizeof (TypeName##Class), \ 911 // (GClassInitFunc) type_name##_class_intern_init, \ 912 // sizeof (TypeName), \ 913 // (GInstanceInitFunc) type_name##_init, \ 914 // (GTypeFlags) flags); \ 915 // { /* custom code follows */ 916 // #define _G_DEFINE_TYPE_EXTENDED_END() \ 917 // /* following custom code */ \ 918 // } \ 919 // g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ 920 // } \ 921 // return g_define_type_id__volatile; \ 922 // } /* closes type_name##_get_type() */ 923 // 924 // #define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \ 925 // \ 926 // static void type_name##_default_init (TypeName##Interface *klass); \ 927 // \ 928 // GType \ 929 // type_name##_get_type (void) \ 930 // { \ 931 // static volatile gsize g_define_type_id__volatile = 0; \ 932 // if (g_once_init_enter (&g_define_type_id__volatile)) \ 933 // { \ 934 // GType g_define_type_id = \ 935 // g_type_register_static_simple (G_TYPE_INTERFACE, \ 936 // g_intern_static_string (#TypeName), \ 937 // sizeof (TypeName##Interface), \ 938 // (GClassInitFunc)type_name##_default_init, \ 939 // 0, \ 940 // (GInstanceInitFunc)NULL, \ 941 // (GTypeFlags) 0); \ 942 // if (TYPE_PREREQ) \ 943 // g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \ 944 // { /* custom code follows */ 945 // #define _G_DEFINE_INTERFACE_EXTENDED_END() \ 946 // /* following custom code */ \ 947 // } \ 948 // g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ 949 // } \ 950 // return g_define_type_id__volatile; \ 951 // } /* closes type_name##_get_type() */ 952 // 953 // /** 954 // * G_DEFINE_BOXED_TYPE: 955 // * @TypeName: The name of the new type, in Camel case 956 // * @type_name: The name of the new type, in lowercase, with words 957 // * separated by '_' 958 // * @copy_func: the #GBoxedCopyFunc for the new type 959 // * @free_func: the #GBoxedFreeFunc for the new type 960 // * 961 // * A convenience macro for boxed type implementations, which defines a 962 // * type_name_get_type() function registering the boxed type. 963 // * 964 // * Since: 2.26 965 // */ 966 // #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, {}) 967 // /** 968 // * G_DEFINE_BOXED_TYPE_WITH_CODE: 969 // * @TypeName: The name of the new type, in Camel case 970 // * @type_name: The name of the new type, in lowercase, with words 971 // * separated by '_' 972 // * @copy_func: the #GBoxedCopyFunc for the new type 973 // * @free_func: the #GBoxedFreeFunc for the new type 974 // * @_C_: Custom code that gets inserted in the *_get_type() function 975 // * 976 // * A convenience macro for boxed type implementations. 977 // * Similar to G_DEFINE_BOXED_TYPE(), but allows to insert custom code into the 978 // * type_name_get_type() function, e.g. to register value transformations with 979 // * g_value_register_transform_func(). 980 // * 981 // * Since: 2.26 982 // */ 983 // #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() 984 // 985 // /* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64. 986 // * See https://bugzilla.gnome.org/show_bug.cgi?id=647145 987 // */ 988 // #if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__)) 989 // #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ 990 // GType \ 991 // type_name##_get_type (void) \ 992 // { \ 993 // static volatile gsize g_define_type_id__volatile = 0; \ 994 // if (g_once_init_enter (&g_define_type_id__volatile)) \ 995 // { \ 996 // GType (* _g_register_boxed) \ 997 // (const gchar *, \ 998 // union \ 999 // { \ 1000 // TypeName * (*do_copy_type) (TypeName *); \ 1001 // TypeName * (*do_const_copy_type) (const TypeName *); \ 1002 // GBoxedCopyFunc do_copy_boxed; \ 1003 // } __attribute__((__transparent_union__)), \ 1004 // union \ 1005 // { \ 1006 // void (* do_free_type) (TypeName *); \ 1007 // GBoxedFreeFunc do_free_boxed; \ 1008 // } __attribute__((__transparent_union__)) \ 1009 // ) = g_boxed_type_register_static; \ 1010 // GType g_define_type_id = \ 1011 // _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func); \ 1012 // { /* custom code follows */ 1013 // #else 1014 // #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ 1015 // GType \ 1016 // type_name##_get_type (void) \ 1017 // { \ 1018 // static volatile gsize g_define_type_id__volatile = 0; \ 1019 // if (g_once_init_enter (&g_define_type_id__volatile)) \ 1020 // { \ 1021 // GType g_define_type_id = \ 1022 // g_boxed_type_register_static (g_intern_static_string (#TypeName), \ 1023 // (GBoxedCopyFunc) copy_func, \ 1024 // (GBoxedFreeFunc) free_func); \ 1025 // { /* custom code follows */ 1026 // #endif /* __GNUC__ */ 1027 // 1028 // /** 1029 // * G_DEFINE_POINTER_TYPE: 1030 // * @TypeName: The name of the new type, in Camel case 1031 // * @type_name: The name of the new type, in lowercase, with words 1032 // * separated by '_' 1033 // * 1034 // * A convenience macro for pointer type implementations, which defines a 1035 // * type_name_get_type() function registering the pointer type. 1036 // * 1037 // * Since: 2.26 1038 // */ 1039 // #define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE (TypeName, type_name, {}) 1040 // /** 1041 // * G_DEFINE_POINTER_TYPE_WITH_CODE: 1042 // * @TypeName: The name of the new type, in Camel case 1043 // * @type_name: The name of the new type, in lowercase, with words 1044 // * separated by '_' 1045 // * @_C_: Custom code that gets inserted in the *_get_type() function 1046 // * 1047 // * A convenience macro for pointer type implementations. 1048 // * Similar to G_DEFINE_POINTER_TYPE(), but allows to insert 1049 // * custom code into the type_name_get_type() function. 1050 // * 1051 // * Since: 2.26 1052 // */ 1053 // #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() 1054 // 1055 // #define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \ 1056 // GType \ 1057 // type_name##_get_type (void) \ 1058 // { \ 1059 // static volatile gsize g_define_type_id__volatile = 0; \ 1060 // if (g_once_init_enter (&g_define_type_id__volatile)) \ 1061 // { \ 1062 // GType g_define_type_id = \ 1063 // g_pointer_type_register_static (g_intern_static_string (#TypeName)); \ 1064 // { /* custom code follows */ 1065 // 1066 /* --- protected (for fundamental type implementations) --- */ 1067 extern (C) { 1068 1069 GTypePlugin* g_type_get_plugin (GType type); 1070 1071 GTypePlugin* g_type_interface_get_plugin (GType instance_type, 1072 GType interface_type); 1073 1074 GType g_type_fundamental_next (); 1075 1076 GType g_type_fundamental (GType type_id); 1077 1078 GTypeInstance* g_type_create_instance (GType type); 1079 1080 void g_type_free_instance (GTypeInstance *instance); 1081 1082 1083 void g_type_add_class_cache_func (gpointer cache_data, 1084 GTypeClassCacheFunc cache_func); 1085 1086 void g_type_remove_class_cache_func (gpointer cache_data, 1087 GTypeClassCacheFunc cache_func); 1088 1089 void g_type_class_unref_uncached (gpointer g_class); 1090 1091 1092 void g_type_add_interface_check (gpointer check_data, 1093 GTypeInterfaceCheckFunc check_func); 1094 1095 void g_type_remove_interface_check (gpointer check_data, 1096 GTypeInterfaceCheckFunc check_func); 1097 1098 1099 GTypeValueTable* g_type_value_table_peek (GType type); 1100 1101 1102 /*< private >*/ 1103 1104 pure gboolean g_type_check_instance (GTypeInstance *instance); 1105 1106 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance, 1107 GType iface_type); 1108 1109 pure gboolean g_type_check_instance_is_a (GTypeInstance *instance, 1110 GType iface_type); 1111 1112 pure gboolean g_type_check_instance_is_fundamentally_a (GTypeInstance *instance, 1113 GType fundamental_type); 1114 1115 GTypeClass* g_type_check_class_cast (GTypeClass *g_class, 1116 GType is_a_type); 1117 1118 pure gboolean g_type_check_class_is_a (GTypeClass *g_class, 1119 GType is_a_type); 1120 1121 pure gboolean g_type_check_is_value_type (GType type); 1122 1123 pure gboolean g_type_check_value (GValue *value); 1124 1125 pure gboolean g_type_check_value_holds (GValue *value, 1126 GType type); 1127 1128 pure gboolean g_type_test_flags (GType type, 1129 guint flags); 1130 1131 1132 /* --- debugging functions --- */ 1133 1134 const(gchar) * g_type_name_from_instance (GTypeInstance *instance); 1135 1136 const(gchar) * g_type_name_from_class (GTypeClass *g_class); 1137 1138 } 1139 1140 // /* --- implementation bits --- */ 1141 // #ifndef G_DISABLE_CAST_CHECKS 1142 // # define _G_TYPE_CIC(ip, gt, ct) \ 1143 // ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt)) 1144 // # define _G_TYPE_CCC(cp, gt, ct) \ 1145 // ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt)) 1146 // #else /* G_DISABLE_CAST_CHECKS */ 1147 // # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip) 1148 // # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp) 1149 // #endif /* G_DISABLE_CAST_CHECKS */ 1150 // #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip)) 1151 // #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl)) 1152 // #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class)) 1153 // #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt)) 1154 // #define _G_TYPE_CIFT(ip, ft) (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft)) 1155 // #ifdef __GNUC__ 1156 // # define _G_TYPE_CIT(ip, gt) (G_GNUC_EXTENSION ({ \ 1157 // GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \ 1158 // if (!__inst) \ 1159 // __r = FALSE; \ 1160 // else if (__inst->g_class && __inst->g_class->g_type == __t) \ 1161 // __r = TRUE; \ 1162 // else \ 1163 // __r = g_type_check_instance_is_a (__inst, __t); \ 1164 // __r; \ 1165 // })) 1166 // # define _G_TYPE_CCT(cp, gt) (G_GNUC_EXTENSION ({ \ 1167 // GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \ 1168 // if (!__class) \ 1169 // __r = FALSE; \ 1170 // else if (__class->g_type == __t) \ 1171 // __r = TRUE; \ 1172 // else \ 1173 // __r = g_type_check_class_is_a (__class, __t); \ 1174 // __r; \ 1175 // })) 1176 // # define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \ 1177 // GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \ 1178 // if (!__val) \ 1179 // __r = FALSE; \ 1180 // else if (__val->g_type == __t) \ 1181 // __r = TRUE; \ 1182 // else \ 1183 // __r = g_type_check_value_holds (__val, __t); \ 1184 // __r; \ 1185 // })) 1186 // #else /* !__GNUC__ */ 1187 // # define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt)) 1188 // # define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt)) 1189 // # define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt)) 1190 // #endif /* !__GNUC__ */ 1191 // /** 1192 // * G_TYPE_FLAG_RESERVED_ID_BIT: 1193 // * 1194 // * A bit in the type number that's supposed to be left untouched. 1195 // */ 1196 // #define G_TYPE_FLAG_RESERVED_ID_BIT ((GType) (1 << 0)) 1197