1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module glib.VariantType; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 public import glib.c.types; 31 public import gtkc.glibtypes; 32 private import gtkd.Loader; 33 34 35 /** 36 * This section introduces the GVariant type system. It is based, in 37 * large part, on the D-Bus type system, with two major changes and 38 * some minor lifting of restrictions. The 39 * [D-Bus specification](http://dbus.freedesktop.org/doc/dbus-specification.html), 40 * therefore, provides a significant amount of 41 * information that is useful when working with GVariant. 42 * 43 * The first major change with respect to the D-Bus type system is the 44 * introduction of maybe (or "nullable") types. Any type in GVariant can be 45 * converted to a maybe type, in which case, "nothing" (or "null") becomes a 46 * valid value. Maybe types have been added by introducing the 47 * character "m" to type strings. 48 * 49 * The second major change is that the GVariant type system supports the 50 * concept of "indefinite types" -- types that are less specific than 51 * the normal types found in D-Bus. For example, it is possible to speak 52 * of "an array of any type" in GVariant, where the D-Bus type system 53 * would require you to speak of "an array of integers" or "an array of 54 * strings". Indefinite types have been added by introducing the 55 * characters "*", "?" and "r" to type strings. 56 * 57 * Finally, all arbitrary restrictions relating to the complexity of 58 * types are lifted along with the restriction that dictionary entries 59 * may only appear nested inside of arrays. 60 * 61 * Just as in D-Bus, GVariant types are described with strings ("type 62 * strings"). Subject to the differences mentioned above, these strings 63 * are of the same form as those found in DBus. Note, however: D-Bus 64 * always works in terms of messages and therefore individual type 65 * strings appear nowhere in its interface. Instead, "signatures" 66 * are a concatenation of the strings of the type of each argument in a 67 * message. GVariant deals with single values directly so GVariant type 68 * strings always describe the type of exactly one value. This means 69 * that a D-Bus signature string is generally not a valid GVariant type 70 * string -- except in the case that it is the signature of a message 71 * containing exactly one argument. 72 * 73 * An indefinite type is similar in spirit to what may be called an 74 * abstract type in other type systems. No value can exist that has an 75 * indefinite type as its type, but values can exist that have types 76 * that are subtypes of indefinite types. That is to say, 77 * g_variant_get_type() will never return an indefinite type, but 78 * calling g_variant_is_of_type() with an indefinite type may return 79 * %TRUE. For example, you cannot have a value that represents "an 80 * array of no particular type", but you can have an "array of integers" 81 * which certainly matches the type of "an array of no particular type", 82 * since "array of integers" is a subtype of "array of no particular 83 * type". 84 * 85 * This is similar to how instances of abstract classes may not 86 * directly exist in other type systems, but instances of their 87 * non-abstract subtypes may. For example, in GTK, no object that has 88 * the type of #GtkBin can exist (since #GtkBin is an abstract class), 89 * but a #GtkWindow can certainly be instantiated, and you would say 90 * that the #GtkWindow is a #GtkBin (since #GtkWindow is a subclass of 91 * #GtkBin). 92 * 93 * ## GVariant Type Strings 94 * 95 * A GVariant type string can be any of the following: 96 * 97 * - any basic type string (listed below) 98 * 99 * - "v", "r" or "*" 100 * 101 * - one of the characters 'a' or 'm', followed by another type string 102 * 103 * - the character '(', followed by a concatenation of zero or more other 104 * type strings, followed by the character ')' 105 * 106 * - the character '{', followed by a basic type string (see below), 107 * followed by another type string, followed by the character '}' 108 * 109 * A basic type string describes a basic type (as per 110 * g_variant_type_is_basic()) and is always a single character in length. 111 * The valid basic type strings are "b", "y", "n", "q", "i", "u", "x", "t", 112 * "h", "d", "s", "o", "g" and "?". 113 * 114 * The above definition is recursive to arbitrary depth. "aaaaai" and 115 * "(ui(nq((y)))s)" are both valid type strings, as is 116 * "a(aa(ui)(qna{ya(yd)}))". 117 * 118 * The meaning of each of the characters is as follows: 119 * - `b`: the type string of %G_VARIANT_TYPE_BOOLEAN; a boolean value. 120 * - `y`: the type string of %G_VARIANT_TYPE_BYTE; a byte. 121 * - `n`: the type string of %G_VARIANT_TYPE_INT16; a signed 16 bit integer. 122 * - `q`: the type string of %G_VARIANT_TYPE_UINT16; an unsigned 16 bit integer. 123 * - `i`: the type string of %G_VARIANT_TYPE_INT32; a signed 32 bit integer. 124 * - `u`: the type string of %G_VARIANT_TYPE_UINT32; an unsigned 32 bit integer. 125 * - `x`: the type string of %G_VARIANT_TYPE_INT64; a signed 64 bit integer. 126 * - `t`: the type string of %G_VARIANT_TYPE_UINT64; an unsigned 64 bit integer. 127 * - `h`: the type string of %G_VARIANT_TYPE_HANDLE; a signed 32 bit value 128 * that, by convention, is used as an index into an array of file 129 * descriptors that are sent alongside a D-Bus message. 130 * - `d`: the type string of %G_VARIANT_TYPE_DOUBLE; a double precision 131 * floating point value. 132 * - `s`: the type string of %G_VARIANT_TYPE_STRING; a string. 133 * - `o`: the type string of %G_VARIANT_TYPE_OBJECT_PATH; a string in the form 134 * of a D-Bus object path. 135 * - `g`: the type string of %G_VARIANT_TYPE_SIGNATURE; a string in the form of 136 * a D-Bus type signature. 137 * - `?`: the type string of %G_VARIANT_TYPE_BASIC; an indefinite type that 138 * is a supertype of any of the basic types. 139 * - `v`: the type string of %G_VARIANT_TYPE_VARIANT; a container type that 140 * contain any other type of value. 141 * - `a`: used as a prefix on another type string to mean an array of that 142 * type; the type string "ai", for example, is the type of an array of 143 * signed 32-bit integers. 144 * - `m`: used as a prefix on another type string to mean a "maybe", or 145 * "nullable", version of that type; the type string "ms", for example, 146 * is the type of a value that maybe contains a string, or maybe contains 147 * nothing. 148 * - `()`: used to enclose zero or more other concatenated type strings to 149 * create a tuple type; the type string "(is)", for example, is the type of 150 * a pair of an integer and a string. 151 * - `r`: the type string of %G_VARIANT_TYPE_TUPLE; an indefinite type that is 152 * a supertype of any tuple type, regardless of the number of items. 153 * - `{}`: used to enclose a basic type string concatenated with another type 154 * string to create a dictionary entry type, which usually appears inside of 155 * an array to form a dictionary; the type string "a{sd}", for example, is 156 * the type of a dictionary that maps strings to double precision floating 157 * point values. 158 * 159 * The first type (the basic type) is the key type and the second type is 160 * the value type. The reason that the first type is restricted to being a 161 * basic type is so that it can easily be hashed. 162 * - `*`: the type string of %G_VARIANT_TYPE_ANY; the indefinite type that is 163 * a supertype of all types. Note that, as with all type strings, this 164 * character represents exactly one type. It cannot be used inside of tuples 165 * to mean "any number of items". 166 * 167 * Any type string of a container that contains an indefinite type is, 168 * itself, an indefinite type. For example, the type string "a*" 169 * (corresponding to %G_VARIANT_TYPE_ARRAY) is an indefinite type 170 * that is a supertype of every array type. "(*s)" is a supertype 171 * of all tuples that contain exactly two items where the second 172 * item is a string. 173 * 174 * "a{?*}" is an indefinite type that is a supertype of all arrays 175 * containing dictionary entries where the key is any basic type and 176 * the value is any type at all. This is, by definition, a dictionary, 177 * so this type string corresponds to %G_VARIANT_TYPE_DICTIONARY. Note 178 * that, due to the restriction that the key of a dictionary entry must 179 * be a basic type, "{**}" is not a valid type string. 180 */ 181 public class VariantType 182 { 183 /** the main Gtk struct */ 184 protected GVariantType* gVariantType; 185 protected bool ownedRef; 186 187 /** Get the main Gtk struct */ 188 public GVariantType* getVariantTypeStruct(bool transferOwnership = false) 189 { 190 if (transferOwnership) 191 ownedRef = false; 192 return gVariantType; 193 } 194 195 /** the main Gtk struct as a void* */ 196 protected void* getStruct() 197 { 198 return cast(void*)gVariantType; 199 } 200 201 /** 202 * Sets our main struct and passes it to the parent class. 203 */ 204 public this (GVariantType* gVariantType, bool ownedRef = false) 205 { 206 this.gVariantType = gVariantType; 207 this.ownedRef = ownedRef; 208 } 209 210 ~this () 211 { 212 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 213 g_variant_type_free(gVariantType); 214 } 215 216 /** 217 * Constructs the type corresponding to a maybe instance containing 218 * type type or Nothing. 219 * 220 * It is appropriate to call free() on the return value. 221 * 222 * Params: 223 * element = a VariantType 224 * 225 * Return: a new maybe VariantType 226 * 227 * Since 2.24 228 * 229 * Throws: ConstructionException GTK+ fails to create the object. 230 */ 231 public static VariantType newMaybe(VariantType element) 232 { 233 auto p = g_variant_type_new_maybe((element is null) ? null : element.getVariantTypeStruct()); 234 235 if(p is null) 236 { 237 throw new ConstructionException("null returned by new_maybe"); 238 } 239 240 return new VariantType(cast(GVariantType*) p); 241 } 242 243 /** 244 */ 245 246 /** 247 * Creates a new #GVariantType corresponding to the type string given 248 * by @type_string. It is appropriate to call g_variant_type_free() on 249 * the return value. 250 * 251 * It is a programmer error to call this function with an invalid type 252 * string. Use g_variant_type_string_is_valid() if you are unsure. 253 * 254 * Params: 255 * typeString = a valid GVariant type string 256 * 257 * Returns: a new #GVariantType 258 * 259 * Since: 2.24 260 * 261 * Throws: ConstructionException GTK+ fails to create the object. 262 */ 263 public this(string typeString) 264 { 265 auto p = g_variant_type_new(Str.toStringz(typeString)); 266 267 if(p is null) 268 { 269 throw new ConstructionException("null returned by new"); 270 } 271 272 this(cast(GVariantType*) p); 273 } 274 275 /** 276 * Constructs the type corresponding to an array of elements of the 277 * type @type. 278 * 279 * It is appropriate to call g_variant_type_free() on the return value. 280 * 281 * Params: 282 * element = a #GVariantType 283 * 284 * Returns: a new array #GVariantType 285 * 286 * Since 2.24 287 * 288 * Throws: ConstructionException GTK+ fails to create the object. 289 */ 290 public this(VariantType element) 291 { 292 auto p = g_variant_type_new_array((element is null) ? null : element.getVariantTypeStruct()); 293 294 if(p is null) 295 { 296 throw new ConstructionException("null returned by new_array"); 297 } 298 299 this(cast(GVariantType*) p); 300 } 301 302 /** 303 * Constructs the type corresponding to a dictionary entry with a key 304 * of type @key and a value of type @value. 305 * 306 * It is appropriate to call g_variant_type_free() on the return value. 307 * 308 * Params: 309 * key = a basic #GVariantType 310 * value = a #GVariantType 311 * 312 * Returns: a new dictionary entry #GVariantType 313 * 314 * Since 2.24 315 * 316 * Throws: ConstructionException GTK+ fails to create the object. 317 */ 318 public this(VariantType key, VariantType value) 319 { 320 auto p = g_variant_type_new_dict_entry((key is null) ? null : key.getVariantTypeStruct(), (value is null) ? null : value.getVariantTypeStruct()); 321 322 if(p is null) 323 { 324 throw new ConstructionException("null returned by new_dict_entry"); 325 } 326 327 this(cast(GVariantType*) p); 328 } 329 330 /** 331 * Constructs a new tuple type, from @items. 332 * 333 * @length is the number of items in @items, or -1 to indicate that 334 * @items is %NULL-terminated. 335 * 336 * It is appropriate to call g_variant_type_free() on the return value. 337 * 338 * Params: 339 * items = an array of #GVariantTypes, one for each item 340 * 341 * Returns: a new tuple #GVariantType 342 * 343 * Since 2.24 344 * 345 * Throws: ConstructionException GTK+ fails to create the object. 346 */ 347 public this(VariantType[] items) 348 { 349 GVariantType*[] itemsArray = new GVariantType*[items.length]; 350 for ( int i = 0; i < items.length; i++ ) 351 { 352 itemsArray[i] = items[i].getVariantTypeStruct(); 353 } 354 355 auto p = g_variant_type_new_tuple(itemsArray.ptr, cast(int)items.length); 356 357 if(p is null) 358 { 359 throw new ConstructionException("null returned by new_tuple"); 360 } 361 362 this(cast(GVariantType*) p); 363 } 364 365 /** 366 * Makes a copy of a #GVariantType. It is appropriate to call 367 * g_variant_type_free() on the return value. @type may not be %NULL. 368 * 369 * Returns: a new #GVariantType 370 * 371 * Since 2.24 372 */ 373 public VariantType copy() 374 { 375 auto p = g_variant_type_copy(gVariantType); 376 377 if(p is null) 378 { 379 return null; 380 } 381 382 return new VariantType(cast(GVariantType*) p, true); 383 } 384 385 /** 386 * Returns a newly-allocated copy of the type string corresponding to 387 * @type. The returned string is nul-terminated. It is appropriate to 388 * call g_free() on the return value. 389 * 390 * Returns: the corresponding type string 391 * 392 * Since 2.24 393 */ 394 public string dupString() 395 { 396 auto retStr = g_variant_type_dup_string(gVariantType); 397 398 scope(exit) Str.freeString(retStr); 399 return Str.toString(retStr); 400 } 401 402 /** 403 * Determines the element type of an array or maybe type. 404 * 405 * This function may only be used with array or maybe types. 406 * 407 * Returns: the element type of @type 408 * 409 * Since 2.24 410 */ 411 public VariantType element() 412 { 413 auto p = g_variant_type_element(gVariantType); 414 415 if(p is null) 416 { 417 return null; 418 } 419 420 return new VariantType(cast(GVariantType*) p); 421 } 422 423 /** 424 * Compares @type1 and @type2 for equality. 425 * 426 * Only returns %TRUE if the types are exactly equal. Even if one type 427 * is an indefinite type and the other is a subtype of it, %FALSE will 428 * be returned if they are not exactly equal. If you want to check for 429 * subtypes, use g_variant_type_is_subtype_of(). 430 * 431 * The argument types of @type1 and @type2 are only #gconstpointer to 432 * allow use with #GHashTable without function pointer casting. For 433 * both arguments, a valid #GVariantType must be provided. 434 * 435 * Params: 436 * type2 = a #GVariantType 437 * 438 * Returns: %TRUE if @type1 and @type2 are exactly equal 439 * 440 * Since 2.24 441 */ 442 public bool equal(VariantType type2) 443 { 444 return g_variant_type_equal(gVariantType, (type2 is null) ? null : type2.getVariantTypeStruct()) != 0; 445 } 446 447 /** 448 * Determines the first item type of a tuple or dictionary entry 449 * type. 450 * 451 * This function may only be used with tuple or dictionary entry types, 452 * but must not be used with the generic tuple type 453 * %G_VARIANT_TYPE_TUPLE. 454 * 455 * In the case of a dictionary entry type, this returns the type of 456 * the key. 457 * 458 * %NULL is returned in case of @type being %G_VARIANT_TYPE_UNIT. 459 * 460 * This call, together with g_variant_type_next() provides an iterator 461 * interface over tuple and dictionary entry types. 462 * 463 * Returns: the first item type of @type, or %NULL 464 * 465 * Since 2.24 466 */ 467 public VariantType first() 468 { 469 auto p = g_variant_type_first(gVariantType); 470 471 if(p is null) 472 { 473 return null; 474 } 475 476 return new VariantType(cast(GVariantType*) p); 477 } 478 479 /** 480 * Frees a #GVariantType that was allocated with 481 * g_variant_type_copy(), g_variant_type_new() or one of the container 482 * type constructor functions. 483 * 484 * In the case that @type is %NULL, this function does nothing. 485 * 486 * Since 2.24 487 */ 488 public void free() 489 { 490 g_variant_type_free(gVariantType); 491 ownedRef = false; 492 } 493 494 /** 495 * Returns the length of the type string corresponding to the given 496 * @type. This function must be used to determine the valid extent of 497 * the memory region returned by g_variant_type_peek_string(). 498 * 499 * Returns: the length of the corresponding type string 500 * 501 * Since 2.24 502 */ 503 public size_t getStringLength() 504 { 505 return g_variant_type_get_string_length(gVariantType); 506 } 507 508 /** 509 * Hashes @type. 510 * 511 * The argument type of @type is only #gconstpointer to allow use with 512 * #GHashTable without function pointer casting. A valid 513 * #GVariantType must be provided. 514 * 515 * Returns: the hash value 516 * 517 * Since 2.24 518 */ 519 public uint hash() 520 { 521 return g_variant_type_hash(gVariantType); 522 } 523 524 /** 525 * Determines if the given @type is an array type. This is true if the 526 * type string for @type starts with an 'a'. 527 * 528 * This function returns %TRUE for any indefinite type for which every 529 * definite subtype is an array type -- %G_VARIANT_TYPE_ARRAY, for 530 * example. 531 * 532 * Returns: %TRUE if @type is an array type 533 * 534 * Since 2.24 535 */ 536 public bool isArray() 537 { 538 return g_variant_type_is_array(gVariantType) != 0; 539 } 540 541 /** 542 * Determines if the given @type is a basic type. 543 * 544 * Basic types are booleans, bytes, integers, doubles, strings, object 545 * paths and signatures. 546 * 547 * Only a basic type may be used as the key of a dictionary entry. 548 * 549 * This function returns %FALSE for all indefinite types except 550 * %G_VARIANT_TYPE_BASIC. 551 * 552 * Returns: %TRUE if @type is a basic type 553 * 554 * Since 2.24 555 */ 556 public bool isBasic() 557 { 558 return g_variant_type_is_basic(gVariantType) != 0; 559 } 560 561 /** 562 * Determines if the given @type is a container type. 563 * 564 * Container types are any array, maybe, tuple, or dictionary 565 * entry types plus the variant type. 566 * 567 * This function returns %TRUE for any indefinite type for which every 568 * definite subtype is a container -- %G_VARIANT_TYPE_ARRAY, for 569 * example. 570 * 571 * Returns: %TRUE if @type is a container type 572 * 573 * Since 2.24 574 */ 575 public bool isContainer() 576 { 577 return g_variant_type_is_container(gVariantType) != 0; 578 } 579 580 /** 581 * Determines if the given @type is definite (ie: not indefinite). 582 * 583 * A type is definite if its type string does not contain any indefinite 584 * type characters ('*', '?', or 'r'). 585 * 586 * A #GVariant instance may not have an indefinite type, so calling 587 * this function on the result of g_variant_get_type() will always 588 * result in %TRUE being returned. Calling this function on an 589 * indefinite type like %G_VARIANT_TYPE_ARRAY, however, will result in 590 * %FALSE being returned. 591 * 592 * Returns: %TRUE if @type is definite 593 * 594 * Since 2.24 595 */ 596 public bool isDefinite() 597 { 598 return g_variant_type_is_definite(gVariantType) != 0; 599 } 600 601 /** 602 * Determines if the given @type is a dictionary entry type. This is 603 * true if the type string for @type starts with a '{'. 604 * 605 * This function returns %TRUE for any indefinite type for which every 606 * definite subtype is a dictionary entry type -- 607 * %G_VARIANT_TYPE_DICT_ENTRY, for example. 608 * 609 * Returns: %TRUE if @type is a dictionary entry type 610 * 611 * Since 2.24 612 */ 613 public bool isDictEntry() 614 { 615 return g_variant_type_is_dict_entry(gVariantType) != 0; 616 } 617 618 /** 619 * Determines if the given @type is a maybe type. This is true if the 620 * type string for @type starts with an 'm'. 621 * 622 * This function returns %TRUE for any indefinite type for which every 623 * definite subtype is a maybe type -- %G_VARIANT_TYPE_MAYBE, for 624 * example. 625 * 626 * Returns: %TRUE if @type is a maybe type 627 * 628 * Since 2.24 629 */ 630 public bool isMaybe() 631 { 632 return g_variant_type_is_maybe(gVariantType) != 0; 633 } 634 635 /** 636 * Checks if @type is a subtype of @supertype. 637 * 638 * This function returns %TRUE if @type is a subtype of @supertype. All 639 * types are considered to be subtypes of themselves. Aside from that, 640 * only indefinite types can have subtypes. 641 * 642 * Params: 643 * supertype = a #GVariantType 644 * 645 * Returns: %TRUE if @type is a subtype of @supertype 646 * 647 * Since 2.24 648 */ 649 public bool isSubtypeOf(VariantType supertype) 650 { 651 return g_variant_type_is_subtype_of(gVariantType, (supertype is null) ? null : supertype.getVariantTypeStruct()) != 0; 652 } 653 654 /** 655 * Determines if the given @type is a tuple type. This is true if the 656 * type string for @type starts with a '(' or if @type is 657 * %G_VARIANT_TYPE_TUPLE. 658 * 659 * This function returns %TRUE for any indefinite type for which every 660 * definite subtype is a tuple type -- %G_VARIANT_TYPE_TUPLE, for 661 * example. 662 * 663 * Returns: %TRUE if @type is a tuple type 664 * 665 * Since 2.24 666 */ 667 public bool isTuple() 668 { 669 return g_variant_type_is_tuple(gVariantType) != 0; 670 } 671 672 /** 673 * Determines if the given @type is the variant type. 674 * 675 * Returns: %TRUE if @type is the variant type 676 * 677 * Since 2.24 678 */ 679 public bool isVariant() 680 { 681 return g_variant_type_is_variant(gVariantType) != 0; 682 } 683 684 /** 685 * Determines the key type of a dictionary entry type. 686 * 687 * This function may only be used with a dictionary entry type. Other 688 * than the additional restriction, this call is equivalent to 689 * g_variant_type_first(). 690 * 691 * Returns: the key type of the dictionary entry 692 * 693 * Since 2.24 694 */ 695 public VariantType key() 696 { 697 auto p = g_variant_type_key(gVariantType); 698 699 if(p is null) 700 { 701 return null; 702 } 703 704 return new VariantType(cast(GVariantType*) p); 705 } 706 707 /** 708 * Determines the number of items contained in a tuple or 709 * dictionary entry type. 710 * 711 * This function may only be used with tuple or dictionary entry types, 712 * but must not be used with the generic tuple type 713 * %G_VARIANT_TYPE_TUPLE. 714 * 715 * In the case of a dictionary entry type, this function will always 716 * return 2. 717 * 718 * Returns: the number of items in @type 719 * 720 * Since 2.24 721 */ 722 public size_t nItems() 723 { 724 return g_variant_type_n_items(gVariantType); 725 } 726 727 /** 728 * Determines the next item type of a tuple or dictionary entry 729 * type. 730 * 731 * @type must be the result of a previous call to 732 * g_variant_type_first() or g_variant_type_next(). 733 * 734 * If called on the key type of a dictionary entry then this call 735 * returns the value type. If called on the value type of a dictionary 736 * entry then this call returns %NULL. 737 * 738 * For tuples, %NULL is returned when @type is the last item in a tuple. 739 * 740 * Returns: the next #GVariantType after @type, or %NULL 741 * 742 * Since 2.24 743 */ 744 public VariantType next() 745 { 746 auto p = g_variant_type_next(gVariantType); 747 748 if(p is null) 749 { 750 return null; 751 } 752 753 return new VariantType(cast(GVariantType*) p); 754 } 755 756 /** 757 * Returns the type string corresponding to the given @type. The 758 * result is not nul-terminated; in order to determine its length you 759 * must call g_variant_type_get_string_length(). 760 * 761 * To get a nul-terminated string, see g_variant_type_dup_string(). 762 * 763 * Returns: the corresponding type string (not nul-terminated) 764 * 765 * Since 2.24 766 */ 767 public string peekString() 768 { 769 return Str.toString(g_variant_type_peek_string(gVariantType)); 770 } 771 772 /** 773 * Determines the value type of a dictionary entry type. 774 * 775 * This function may only be used with a dictionary entry type. 776 * 777 * Returns: the value type of the dictionary entry 778 * 779 * Since 2.24 780 */ 781 public VariantType value() 782 { 783 auto p = g_variant_type_value(gVariantType); 784 785 if(p is null) 786 { 787 return null; 788 } 789 790 return new VariantType(cast(GVariantType*) p); 791 } 792 793 /** */ 794 public static VariantType checked(string arg0) 795 { 796 auto p = g_variant_type_checked_(Str.toStringz(arg0)); 797 798 if(p is null) 799 { 800 return null; 801 } 802 803 return new VariantType(cast(GVariantType*) p); 804 } 805 806 /** 807 * Checks if @type_string is a valid GVariant type string. This call is 808 * equivalent to calling g_variant_type_string_scan() and confirming 809 * that the following character is a nul terminator. 810 * 811 * Params: 812 * typeString = a pointer to any string 813 * 814 * Returns: %TRUE if @type_string is exactly one valid type string 815 * 816 * Since 2.24 817 */ 818 public static bool stringIsValid(string typeString) 819 { 820 return g_variant_type_string_is_valid(Str.toStringz(typeString)) != 0; 821 } 822 823 /** 824 * Scan for a single complete and valid GVariant type string in @string. 825 * The memory pointed to by @limit (or bytes beyond it) is never 826 * accessed. 827 * 828 * If a valid type string is found, @endptr is updated to point to the 829 * first character past the end of the string that was found and %TRUE 830 * is returned. 831 * 832 * If there is no valid type string starting at @string, or if the type 833 * string does not end before @limit then %FALSE is returned. 834 * 835 * For the simple case of checking if a string is a valid type string, 836 * see g_variant_type_string_is_valid(). 837 * 838 * Params: 839 * str = a pointer to any string 840 * limit = the end of @string, or %NULL 841 * endptr = location to store the end pointer, or %NULL 842 * 843 * Returns: %TRUE if a valid type string was found 844 * 845 * Since: 2.24 846 */ 847 public static bool stringScan(string str, string limit, out string endptr) 848 { 849 char* outendptr = null; 850 851 auto p = g_variant_type_string_scan(Str.toStringz(str), Str.toStringz(limit), &outendptr) != 0; 852 853 endptr = Str.toString(outendptr); 854 855 return p; 856 } 857 }