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 * Conversion parameters: 26 * inFile = glib-GVariant.html 27 * outPack = glib 28 * outFile = Variant 29 * strct = GVariant 30 * realStrct= 31 * ctorStrct= 32 * clss = Variant 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_variant_ 41 * omit structs: 42 * omit prefixes: 43 * - g_variant_iter_ 44 * - g_variant_builder_ 45 * omit code: 46 * - g_variant_new_boolean 47 * - g_variant_new_bytestring_array 48 * - g_variant_new_object_path 49 * - g_variant_new_signature 50 * - g_variant_new_objv 51 * - g_variant_new_bytestring 52 * - g_variant_new_handle 53 * - g_variant_new_take_string 54 * omit signals: 55 * imports: 56 * - glib.Str 57 * - glib.ErrorG 58 * - glib.GException 59 * - glib.Bytes 60 * - glib.StringG 61 * - glib.VariantType 62 * structWrap: 63 * - GBytes* -> Bytes 64 * - GString* -> StringG 65 * - GVariant* -> Variant 66 * - GVariantType* -> VariantType 67 * module aliases: 68 * local aliases: 69 * - byte -> b 70 * overrides: 71 */ 72 73 module glib.Variant; 74 75 public import gtkc.glibtypes; 76 77 private import gtkc.glib; 78 private import glib.ConstructionException; 79 80 81 private import glib.Str; 82 private import glib.ErrorG; 83 private import glib.GException; 84 private import glib.Bytes; 85 private import glib.StringG; 86 private import glib.VariantType; 87 88 89 90 91 /** 92 * GVariant is a variant datatype; it stores a value along with 93 * information about the type of that value. The range of possible 94 * values is determined by the type. The type system used by GVariant 95 * is GVariantType. 96 * 97 * GVariant instances always have a type and a value (which are given 98 * at construction time). The type and value of a GVariant instance 99 * can never change other than by the GVariant itself being 100 * destroyed. A GVariant cannot contain a pointer. 101 * 102 * GVariant is reference counted using g_variant_ref() and 103 * g_variant_unref(). GVariant also has floating reference counts -- 104 * see g_variant_ref_sink(). 105 * 106 * GVariant is completely threadsafe. A GVariant instance can be 107 * concurrently accessed in any way from any number of threads without 108 * problems. 109 * 110 * GVariant is heavily optimised for dealing with data in serialised 111 * form. It works particularly well with data located in memory-mapped 112 * files. It can perform nearly all deserialisation operations in a 113 * small constant time, usually touching only a single memory page. 114 * Serialised GVariant data can also be sent over the network. 115 * 116 * GVariant is largely compatible with D-Bus. Almost all types of 117 * GVariant instances can be sent over D-Bus. See GVariantType for 118 * exceptions. (However, GVariant's serialisation format is not the same 119 * as the serialisation format of a D-Bus message body: use GDBusMessage, 120 * in the gio library, for those.) 121 * 122 * For space-efficiency, the GVariant serialisation format does not 123 * automatically include the variant's type or endianness, which must 124 * either be implied from context (such as knowledge that a particular 125 * file format always contains a little-endian G_VARIANT_TYPE_VARIANT) 126 * or supplied out-of-band (for instance, a type and/or endianness 127 * indicator could be placed at the beginning of a file, network message 128 * or network stream). 129 * 130 * A GVariant's size is limited mainly by any lower level operating 131 * system constraints, such as the number of bits in gsize. For 132 * example, it is reasonable to have a 2GB file mapped into memory 133 * with GMappedFile, and call g_variant_new_from_data() on it. 134 * 135 * For convenience to C programmers, GVariant features powerful 136 * varargs-based value construction and destruction. This feature is 137 * designed to be embedded in other libraries. 138 * 139 * There is a Python-inspired text language for describing GVariant 140 * values. GVariant includes a printer for this language and a parser 141 * with type inferencing. 142 * 143 * Memory Use 144 * 145 * GVariant tries to be quite efficient with respect to memory use. 146 * This section gives a rough idea of how much memory is used by the 147 * current implementation. The information here is subject to change 148 * in the future. 149 * 150 * The memory allocated by GVariant can be grouped into 4 broad 151 * purposes: memory for serialised data, memory for the type 152 * information cache, buffer management memory and memory for the 153 * GVariant structure itself. 154 * 155 * Serialised Data Memory 156 * 157 * This is the memory that is used for storing GVariant data in 158 * serialised form. This is what would be sent over the network or 159 * what would end up on disk. 160 * 161 * The amount of memory required to store a boolean is 1 byte. 16, 162 * 32 and 64 bit integers and double precision floating point numbers 163 * use their "natural" size. Strings (including object path and 164 * signature strings) are stored with a nul terminator, and as such 165 * use the length of the string plus 1 byte. 166 * 167 * Maybe types use no space at all to represent the null value and 168 * use the same amount of space (sometimes plus one byte) as the 169 * equivalent non-maybe-typed value to represent the non-null case. 170 * 171 * Arrays use the amount of space required to store each of their 172 * members, concatenated. Additionally, if the items stored in an 173 * array are not of a fixed-size (ie: strings, other arrays, etc) 174 * then an additional framing offset is stored for each item. The 175 * size of this offset is either 1, 2 or 4 bytes depending on the 176 * overall size of the container. Additionally, extra padding bytes 177 * are added as required for alignment of child values. 178 * 179 * Tuples (including dictionary entries) use the amount of space 180 * required to store each of their members, concatenated, plus one 181 * framing offset (as per arrays) for each non-fixed-sized item in 182 * the tuple, except for the last one. Additionally, extra padding 183 * bytes are added as required for alignment of child values. 184 * 185 * Variants use the same amount of space as the item inside of the 186 * variant, plus 1 byte, plus the length of the type string for the 187 * item inside the variant. 188 * 189 * As an example, consider a dictionary mapping strings to variants. 190 * In the case that the dictionary is empty, 0 bytes are required for 191 * the serialisation. 192 * 193 * If we add an item "width" that maps to the int32 value of 500 then 194 * we will use 4 byte to store the int32 (so 6 for the variant 195 * containing it) and 6 bytes for the string. The variant must be 196 * aligned to 8 after the 6 bytes of the string, so that's 2 extra 197 * bytes. 6 (string) + 2 (padding) + 6 (variant) is 14 bytes used 198 * for the dictionary entry. An additional 1 byte is added to the 199 * array as a framing offset making a total of 15 bytes. 200 * 201 * If we add another entry, "title" that maps to a nullable string 202 * that happens to have a value of null, then we use 0 bytes for the 203 * null value (and 3 bytes for the variant to contain it along with 204 * its type string) plus 6 bytes for the string. Again, we need 2 205 * padding bytes. That makes a total of 6 + 2 + 3 = 11 bytes. 206 * 207 * We now require extra padding between the two items in the array. 208 * After the 14 bytes of the first item, that's 2 bytes required. We 209 * now require 2 framing offsets for an extra two bytes. 14 + 2 + 11 210 * + 2 = 29 bytes to encode the entire two-item dictionary. 211 * 212 * Type Information Cache 213 * 214 * For each GVariant type that currently exists in the program a type 215 * information structure is kept in the type information cache. The 216 * type information structure is required for rapid deserialisation. 217 * 218 * Continuing with the above example, if a GVariant exists with the 219 * type "a{sv}" then a type information struct will exist for 220 * "a{sv}", "{sv}", "s", and "v". Multiple uses of the same type 221 * will share the same type information. Additionally, all 222 * single-digit types are stored in read-only static memory and do 223 * not contribute to the writable memory footprint of a program using 224 * GVariant. 225 * 226 * Aside from the type information structures stored in read-only 227 * memory, there are two forms of type information. One is used for 228 * container types where there is a single element type: arrays and 229 * maybe types. The other is used for container types where there 230 * are multiple element types: tuples and dictionary entries. 231 * 232 * Array type info structures are 6 * sizeof (void *), plus the 233 * memory required to store the type string itself. This means that 234 * on 32bit systems, the cache entry for "a{sv}" would require 30 235 * bytes of memory (plus malloc overhead). 236 * 237 * Tuple type info structures are 6 * sizeof (void *), plus 4 * 238 * sizeof (void *) for each item in the tuple, plus the memory 239 * required to store the type string itself. A 2-item tuple, for 240 * example, would have a type information structure that consumed 241 * writable memory in the size of 14 * sizeof (void *) (plus type 242 * string) This means that on 32bit systems, the cache entry for 243 * "{sv}" would require 61 bytes of memory (plus malloc overhead). 244 * 245 * This means that in total, for our "a{sv}" example, 91 bytes of 246 * type information would be allocated. 247 * 248 * The type information cache, additionally, uses a GHashTable to 249 * store and lookup the cached items and stores a pointer to this 250 * hash table in static storage. The hash table is freed when there 251 * are zero items in the type cache. 252 * 253 * Although these sizes may seem large it is important to remember 254 * that a program will probably only have a very small number of 255 * different types of values in it and that only one type information 256 * structure is required for many different values of the same type. 257 * 258 * Buffer Management Memory 259 * 260 * GVariant uses an internal buffer management structure to deal 261 * with the various different possible sources of serialised data 262 * that it uses. The buffer is responsible for ensuring that the 263 * correct call is made when the data is no longer in use by 264 * GVariant. This may involve a g_free() or a g_slice_free() or 265 * even g_mapped_file_unref(). 266 * 267 * One buffer management structure is used for each chunk of 268 * serialised data. The size of the buffer management structure is 4 269 * * (void *). On 32bit systems, that's 16 bytes. 270 * 271 * GVariant structure 272 * 273 * The size of a GVariant structure is 6 * (void *). On 32 bit 274 * systems, that's 24 bytes. 275 * 276 * GVariant structures only exist if they are explicitly created 277 * with API calls. For example, if a GVariant is constructed out of 278 * serialised data for the example given above (with the dictionary) 279 * then although there are 9 individual values that comprise the 280 * entire dictionary (two keys, two values, two variants containing 281 * the values, two dictionary entries, plus the dictionary itself), 282 * only 1 GVariant instance exists -- the one referring to the 283 * dictionary. 284 * 285 * If calls are made to start accessing the other values then 286 * GVariant instances will exist for those values only for as long 287 * as they are in use (ie: until you call g_variant_unref()). The 288 * type information is shared. The serialised data and the buffer 289 * management structure for that serialised data is shared by the 290 * child. 291 * 292 * Summary 293 * 294 * To put the entire example together, for our dictionary mapping 295 * strings to variants (with two entries, as given above), we are 296 * using 91 bytes of memory for type information, 29 byes of memory 297 * for the serialised data, 16 bytes for buffer management and 24 298 * bytes for the GVariant instance, or a total of 160 bytes, plus 299 * malloc overhead. If we were to use g_variant_get_child_value() to 300 * access the two dictionary entries, we would use an additional 48 301 * bytes. If we were to have other dictionaries of the same type, we 302 * would use more memory for the serialised data and buffer 303 * management for those dictionaries, but the type information would 304 * be shared. 305 */ 306 public class Variant 307 { 308 309 /** the main Gtk struct */ 310 protected GVariant* gVariant; 311 312 313 public GVariant* getVariantStruct() 314 { 315 return gVariant; 316 } 317 318 319 /** the main Gtk struct as a void* */ 320 protected void* getStruct() 321 { 322 return cast(void*)gVariant; 323 } 324 325 /** 326 * Sets our main struct and passes it to the parent class 327 */ 328 public this (GVariant* gVariant) 329 { 330 this.gVariant = gVariant; 331 } 332 333 /** 334 * Creates a new boolean GVariant instance -- either TRUE or FALSE. 335 * Since 2.24 336 * Params: 337 * boolean = a gboolean value 338 * Throws: ConstructionException GTK+ fails to create the object. 339 */ 340 public this (bool boolean) 341 { 342 // GVariant * g_variant_new_boolean (gboolean boolean); 343 auto p = g_variant_new_boolean(boolean); 344 if(p is null) 345 { 346 throw new ConstructionException("null returned by g_variant_new_boolean(boolean)"); 347 } 348 this(cast(GVariant*) p); 349 } 350 351 /** 352 * Creates a DBus object path GVariant with the contents of string. 353 * string must be a valid DBus object path. 354 * Use Variant.isObjectPath() if you're not sure. 355 * Since 2.24 356 * 357 * Throws: ConstructionException GTK+ fails to create the object. 358 */ 359 public static Variant fromObjectPath(string path) 360 { 361 auto p = g_variant_new_object_path(Str.toStringz(path)); 362 if(p is null) 363 { 364 throw new ConstructionException("null returned by g_variant_new_object_path"); 365 } 366 return new Variant(cast(GVariant*) p); 367 } 368 369 /** 370 * Creates a DBus type signature GVariant with the contents of string. 371 * string must be a valid DBus type signature. 372 * Use Variant.isSignature() if you're not sure. 373 * Since 2.24 374 * 375 * Throws: ConstructionException GTK+ fails to create the object. 376 */ 377 public static Variant fromSignature(string signature) 378 { 379 auto p = g_variant_new_signature(Str.toStringz(signature)); 380 if(p is null) 381 { 382 throw new ConstructionException("null returned by g_variant_new_signature"); 383 } 384 return new Variant(cast(GVariant*) p); 385 } 386 387 /** 388 * Creates an array-of-bytes GVariant with the contents of string. 389 * This function is just like new Variant(string) except that the string 390 * need not be valid utf8. 391 * 392 * The nul terminator character at the end of the string is stored in 393 * the array. 394 * 395 * Throws: ConstructionException GTK+ fails to create the object. 396 */ 397 public static Variant fromByteString(string byteString) 398 { 399 auto p = g_variant_new_bytestring(Str.toStringz(byteString)); 400 if(p is null) 401 { 402 throw new ConstructionException("null returned by g_variant_new_bytestring"); 403 } 404 return new Variant(cast(GVariant*) p); 405 } 406 407 /** 408 * Constructs an array of object paths Variant from the given array 409 * of strings. 410 * 411 * Each string must be a valid Variant object path. 412 * 413 * Since: 2.30 414 * 415 * Params: 416 * strv = an array of strings. 417 * 418 * Throws: ConstructionException GTK+ fails to create the object. 419 */ 420 public static Variant fromObjv(string[] strv) 421 { 422 // GVariant * g_variant_new_objv (const gchar * const *strv, gssize length); 423 auto p = g_variant_new_objv(Str.toStringzArray(strv), strv.length); 424 if(p is null) 425 { 426 throw new ConstructionException("null returned by g_variant_new_objv(strv, length)"); 427 } 428 return new Variant(cast(GVariant*) p); 429 } 430 431 /** 432 * Constructs an array of bytestring GVariant from the given array of 433 * strings. If length is -1 then strv is NULL-terminated. 434 * Since 2.26 435 * 436 * Params: 437 * strv = an array of strings. 438 * 439 * Throws: ConstructionException GTK+ fails to create the object. 440 */ 441 public static Variant fromByteStringArray(string[] strv) 442 { 443 // GVariant * g_variant_new_bytestring_array (const gchar * const *strv, gssize length); 444 auto p = g_variant_new_bytestring_array(Str.toStringzArray(strv), strv.length); 445 if(p is null) 446 { 447 throw new ConstructionException("null returned by g_variant_new_bytestring_array(strv, length)"); 448 } 449 return new Variant(cast(GVariant*) p); 450 } 451 452 /** 453 */ 454 455 /** 456 * Decreases the reference count of value. When its reference count 457 * drops to 0, the memory used by the variant is freed. 458 * Since 2.24 459 */ 460 public void unref() 461 { 462 // void g_variant_unref (GVariant *value); 463 g_variant_unref(gVariant); 464 } 465 466 /** 467 * Increases the reference count of value. 468 * Since 2.24 469 * Returns: the same value 470 */ 471 public Variant doref() 472 { 473 // GVariant * g_variant_ref (GVariant *value); 474 auto p = g_variant_ref(gVariant); 475 476 if(p is null) 477 { 478 return null; 479 } 480 481 return new Variant(cast(GVariant*) p); 482 } 483 484 /** 485 * GVariant uses a floating reference count system. All functions with 486 * names starting with g_variant_new_ return floating 487 * references. 488 * Calling g_variant_ref_sink() on a GVariant with a floating reference 489 * will convert the floating reference into a full reference. Calling 490 * g_variant_ref_sink() on a non-floating GVariant results in an 491 * additional normal reference being added. 492 * In other words, if the value is floating, then this call "assumes 493 * ownership" of the floating reference, converting it to a normal 494 * reference. If the value is not floating, then this call adds a 495 * new normal reference increasing the reference count by one. 496 * All calls that result in a GVariant instance being inserted into a 497 * container will call g_variant_ref_sink() on the instance. This means 498 * that if the value was just created (and has only its floating 499 * reference) then the container will assume sole ownership of the value 500 * at that point and the caller will not need to unreference it. This 501 * makes certain common styles of programming much easier while still 502 * maintaining normal refcounting semantics in situations where values 503 * are not floating. 504 * Since 2.24 505 * Returns: the same value 506 */ 507 public Variant refSink() 508 { 509 // GVariant * g_variant_ref_sink (GVariant *value); 510 auto p = g_variant_ref_sink(gVariant); 511 512 if(p is null) 513 { 514 return null; 515 } 516 517 return new Variant(cast(GVariant*) p); 518 } 519 520 /** 521 * Checks whether value has a floating reference count. 522 * This function should only ever be used to assert that a given variant 523 * is or is not floating, or for debug purposes. To acquire a reference 524 * to a variant that might be floating, always use g_variant_ref_sink() 525 * or g_variant_take_ref(). 526 * See g_variant_ref_sink() for more information about floating reference 527 * counts. 528 * Since 2.26 529 * Returns: whether value is floating 530 */ 531 public int isFloating() 532 { 533 // gboolean g_variant_is_floating (GVariant *value); 534 return g_variant_is_floating(gVariant); 535 } 536 537 /** 538 * If value is floating, sink it. Otherwise, do nothing. 539 * Typically you want to use g_variant_ref_sink() in order to 540 * automatically do the correct thing with respect to floating or 541 * non-floating references, but there is one specific scenario where 542 * this function is helpful. 543 * The situation where this function is helpful is when creating an API 544 * that allows the user to provide a callback function that returns a 545 * GVariant. We certainly want to allow the user the flexibility to 546 * return a non-floating reference from this callback (for the case 547 * where the value that is being returned already exists). 548 * At the same time, the style of the GVariant API makes it likely that 549 * for newly-created GVariant instances, the user can be saved some 550 * typing if they are allowed to return a GVariant with a floating 551 * reference. 552 * Using this function on the return value of the user's callback allows 553 * the user to do whichever is more convenient for them. The caller 554 * will alway receives exactly one full reference to the value: either 555 * the one that was returned in the first place, or a floating reference 556 * that has been converted to a full reference. 557 * This function has an odd interaction when combined with 558 * g_variant_ref_sink() running at the same time in another thread on 559 * the same GVariant instance. If g_variant_ref_sink() runs first then 560 * the result will be that the floating reference is converted to a hard 561 * reference. If g_variant_take_ref() runs first then the result will 562 * be that the floating reference is converted to a hard reference and 563 * an additional reference on top of that one is added. It is best to 564 * avoid this situation. 565 * Returns: the same value 566 */ 567 public Variant takeRef() 568 { 569 // GVariant * g_variant_take_ref (GVariant *value); 570 auto p = g_variant_take_ref(gVariant); 571 572 if(p is null) 573 { 574 return null; 575 } 576 577 return new Variant(cast(GVariant*) p); 578 } 579 580 /** 581 * Determines the type of value. 582 * The return value is valid for the lifetime of value and must not 583 * be freed. 584 * Since 2.24 585 * Returns: a GVariantType 586 */ 587 public VariantType getType() 588 { 589 // const GVariantType * g_variant_get_type (GVariant *value); 590 auto p = g_variant_get_type(gVariant); 591 592 if(p is null) 593 { 594 return null; 595 } 596 597 return new VariantType(cast(GVariantType*) p); 598 } 599 600 /** 601 * Returns the type string of value. Unlike the result of calling 602 * g_variant_type_peek_string(), this string is nul-terminated. This 603 * string belongs to GVariant and must not be freed. 604 * Since 2.24 605 * Returns: the type string for the type of value 606 */ 607 public string getTypeString() 608 { 609 // const gchar * g_variant_get_type_string (GVariant *value); 610 return Str.toString(g_variant_get_type_string(gVariant)); 611 } 612 613 /** 614 * Checks if a value has a type matching the provided type. 615 * Since 2.24 616 * Params: 617 * type = a GVariantType 618 * Returns: TRUE if the type of value matches type 619 */ 620 public int isOfType(VariantType type) 621 { 622 // gboolean g_variant_is_of_type (GVariant *value, const GVariantType *type); 623 return g_variant_is_of_type(gVariant, (type is null) ? null : type.getVariantTypeStruct()); 624 } 625 626 /** 627 * Checks if value is a container. 628 * Since 2.24 629 * Returns: TRUE if value is a container 630 */ 631 public int isContainer() 632 { 633 // gboolean g_variant_is_container (GVariant *value); 634 return g_variant_is_container(gVariant); 635 } 636 637 /** 638 * Compares one and two. 639 * The types of one and two are gconstpointer only to allow use of 640 * this function with GTree, GPtrArray, etc. They must each be a 641 * GVariant. 642 * Comparison is only defined for basic types (ie: booleans, numbers, 643 * strings). For booleans, FALSE is less than TRUE. Numbers are 644 * ordered in the usual way. Strings are in ASCII lexographical order. 645 * It is a programmer error to attempt to compare container values or 646 * two values that have types that are not exactly equal. For example, 647 * you cannot compare a 32-bit signed integer with a 32-bit unsigned 648 * integer. Also note that this function is not particularly 649 * well-behaved when it comes to comparison of doubles; in particular, 650 * the handling of incomparable values (ie: NaN) is undefined. 651 * If you only require an equality comparison, g_variant_equal() is more 652 * general. 653 * Since 2.26 654 * Params: 655 * one = a basic-typed GVariant instance. [type GVariant] 656 * two = a GVariant instance of the same type. [type GVariant] 657 * Returns: negative value if a < b; zero if a = b; positive value if a > b. 658 */ 659 public static int compare(void* one, void* two) 660 { 661 // gint g_variant_compare (gconstpointer one, gconstpointer two); 662 return g_variant_compare(one, two); 663 } 664 665 /** 666 * Classifies value according to its top-level type. 667 * Since 2.24 668 * Returns: the GVariantClass of value 669 */ 670 public GVariantClass classify() 671 { 672 // GVariantClass g_variant_classify (GVariant *value); 673 return g_variant_classify(gVariant); 674 } 675 676 /** 677 * Checks if calling g_variant_get() with format_string on value would 678 * be valid from a type-compatibility standpoint. format_string is 679 * assumed to be a valid format string (from a syntactic standpoint). 680 * If copy_only is TRUE then this function additionally checks that it 681 * would be safe to call g_variant_unref() on value immediately after 682 * the call to g_variant_get() without invalidating the result. This is 683 * only possible if deep copies are made (ie: there are no pointers to 684 * the data inside of the soon-to-be-freed GVariant instance). If this 685 * check fails then a g_critical() is printed and FALSE is returned. 686 * This function is meant to be used by functions that wish to provide 687 * Since 2.34 688 * Params: 689 * formatString = a valid GVariant format string 690 * copyOnly = TRUE to ensure the format string makes deep copies 691 * Returns: TRUE if format_string is safe to use 692 */ 693 public int checkFormatString(string formatString, int copyOnly) 694 { 695 // gboolean g_variant_check_format_string (GVariant *value, const gchar *format_string, gboolean copy_only); 696 return g_variant_check_format_string(gVariant, Str.toStringz(formatString), copyOnly); 697 } 698 699 /** 700 * This function is intended to be used by libraries based on GVariant 701 * that want to provide g_variant_get()-like functionality to their 702 * users. 703 * The API is more general than g_variant_get() to allow a wider range 704 * of possible uses. 705 * format_string must still point to a valid format string, but it only 706 * need to be nul-terminated if endptr is NULL. If endptr is 707 * non-NULL then it is updated to point to the first character past the 708 * end of the format string. 709 * app is a pointer to a va_list. The arguments, according to 710 * format_string, are collected from this va_list and the list is left 711 * pointing to the argument following the last. 712 * These two generalisations allow mixing of multiple calls to 713 * g_variant_new_va() and g_variant_get_va() within a single actual 714 * varargs call by the user. 715 * format_string determines the C types that are used for unpacking 716 * the values and also determines if the values are copied or borrowed, 717 * see the section on 718 * GVariant Format Strings. 719 * Since 2.24 720 * Params: 721 * formatString = a string that is prefixed with a format string 722 * endptr = location to store the end pointer, 723 * or NULL. [allow-none][default NULL] 724 * app = a pointer to a va_list 725 */ 726 public void getVa(string formatString, out string endptr, void** app) 727 { 728 // void g_variant_get_va (GVariant *value, const gchar *format_string, const gchar **endptr, va_list *app); 729 char* outendptr = null; 730 731 g_variant_get_va(gVariant, Str.toStringz(formatString), &outendptr, app); 732 733 endptr = Str.toString(outendptr); 734 } 735 736 /** 737 * This function is intended to be used by libraries based on 738 * GVariant that want to provide g_variant_new()-like functionality 739 * to their users. 740 * The API is more general than g_variant_new() to allow a wider range 741 * of possible uses. 742 * format_string must still point to a valid format string, but it only 743 * needs to be nul-terminated if endptr is NULL. If endptr is 744 * non-NULL then it is updated to point to the first character past the 745 * end of the format string. 746 * app is a pointer to a va_list. The arguments, according to 747 * format_string, are collected from this va_list and the list is left 748 * pointing to the argument following the last. 749 * These two generalisations allow mixing of multiple calls to 750 * g_variant_new_va() and g_variant_get_va() within a single actual 751 * varargs call by the user. 752 * The return value will be floating if it was a newly created GVariant 753 * instance (for example, if the format string was "(ii)"). In the case 754 * that the format_string was '*', '?', 'r', or a format starting with 755 * '@' then the collected GVariant pointer will be returned unmodified, 756 * without adding any additional references. 757 * In order to behave correctly in all cases it is necessary for the 758 * calling function to g_variant_ref_sink() the return result before 759 * returning control to the user that originally provided the pointer. 760 * At this point, the caller will have their own full reference to the 761 * result. This can also be done by adding the result to a container, 762 * or by passing it to another g_variant_new() call. 763 * Since 2.24 764 * Params: 765 * formatString = a string that is prefixed with a format string 766 * endptr = location to store the end pointer, 767 * or NULL. [allow-none][default NULL] 768 * app = a pointer to a va_list 769 * Throws: ConstructionException GTK+ fails to create the object. 770 */ 771 public this (string formatString, out string endptr, void** app) 772 { 773 // GVariant * g_variant_new_va (const gchar *format_string, const gchar **endptr, va_list *app); 774 char* outendptr = null; 775 776 auto p = g_variant_new_va(Str.toStringz(formatString), &outendptr, app); 777 if(p is null) 778 { 779 throw new ConstructionException("null returned by g_variant_new_va(Str.toStringz(formatString), &outendptr, app)"); 780 } 781 782 endptr = Str.toString(outendptr); 783 this(cast(GVariant*) p); 784 } 785 786 /** 787 * Creates a new byte GVariant instance. 788 * Since 2.24 789 * Params: 790 * value = a guint8 value 791 * Throws: ConstructionException GTK+ fails to create the object. 792 */ 793 public this (char value) 794 { 795 // GVariant * g_variant_new_byte (guchar value); 796 auto p = g_variant_new_byte(value); 797 if(p is null) 798 { 799 throw new ConstructionException("null returned by g_variant_new_byte(value)"); 800 } 801 this(cast(GVariant*) p); 802 } 803 804 /** 805 * Creates a new int16 GVariant instance. 806 * Since 2.24 807 * Params: 808 * value = a gint16 value 809 * Throws: ConstructionException GTK+ fails to create the object. 810 */ 811 public this (short value) 812 { 813 // GVariant * g_variant_new_int16 (gint16 value); 814 auto p = g_variant_new_int16(value); 815 if(p is null) 816 { 817 throw new ConstructionException("null returned by g_variant_new_int16(value)"); 818 } 819 this(cast(GVariant*) p); 820 } 821 822 /** 823 * Creates a new uint16 GVariant instance. 824 * Since 2.24 825 * Params: 826 * value = a guint16 value 827 * Throws: ConstructionException GTK+ fails to create the object. 828 */ 829 public this (ushort value) 830 { 831 // GVariant * g_variant_new_uint16 (guint16 value); 832 auto p = g_variant_new_uint16(value); 833 if(p is null) 834 { 835 throw new ConstructionException("null returned by g_variant_new_uint16(value)"); 836 } 837 this(cast(GVariant*) p); 838 } 839 840 /** 841 * Creates a new int32 GVariant instance. 842 * Since 2.24 843 * Params: 844 * value = a gint32 value 845 * Throws: ConstructionException GTK+ fails to create the object. 846 */ 847 public this (int value) 848 { 849 // GVariant * g_variant_new_int32 (gint32 value); 850 auto p = g_variant_new_int32(value); 851 if(p is null) 852 { 853 throw new ConstructionException("null returned by g_variant_new_int32(value)"); 854 } 855 this(cast(GVariant*) p); 856 } 857 858 /** 859 * Creates a new uint32 GVariant instance. 860 * Since 2.24 861 * Params: 862 * value = a guint32 value 863 * Throws: ConstructionException GTK+ fails to create the object. 864 */ 865 public this (uint value) 866 { 867 // GVariant * g_variant_new_uint32 (guint32 value); 868 auto p = g_variant_new_uint32(value); 869 if(p is null) 870 { 871 throw new ConstructionException("null returned by g_variant_new_uint32(value)"); 872 } 873 this(cast(GVariant*) p); 874 } 875 876 /** 877 * Creates a new int64 GVariant instance. 878 * Since 2.24 879 * Params: 880 * value = a gint64 value 881 * Throws: ConstructionException GTK+ fails to create the object. 882 */ 883 public this (long value) 884 { 885 // GVariant * g_variant_new_int64 (gint64 value); 886 auto p = g_variant_new_int64(value); 887 if(p is null) 888 { 889 throw new ConstructionException("null returned by g_variant_new_int64(value)"); 890 } 891 this(cast(GVariant*) p); 892 } 893 894 /** 895 * Creates a new uint64 GVariant instance. 896 * Since 2.24 897 * Params: 898 * value = a guint64 value 899 * Throws: ConstructionException GTK+ fails to create the object. 900 */ 901 public this (ulong value) 902 { 903 // GVariant * g_variant_new_uint64 (guint64 value); 904 auto p = g_variant_new_uint64(value); 905 if(p is null) 906 { 907 throw new ConstructionException("null returned by g_variant_new_uint64(value)"); 908 } 909 this(cast(GVariant*) p); 910 } 911 912 /** 913 * Creates a new double GVariant instance. 914 * Since 2.24 915 * Params: 916 * value = a gdouble floating point value 917 * Throws: ConstructionException GTK+ fails to create the object. 918 */ 919 public this (double value) 920 { 921 // GVariant * g_variant_new_double (gdouble value); 922 auto p = g_variant_new_double(value); 923 if(p is null) 924 { 925 throw new ConstructionException("null returned by g_variant_new_double(value)"); 926 } 927 this(cast(GVariant*) p); 928 } 929 930 /** 931 * Creates a string GVariant with the contents of string. 932 * string must be valid utf8. 933 * Since 2.24 934 * Params: 935 * string = a normal utf8 nul-terminated string 936 * Throws: ConstructionException GTK+ fails to create the object. 937 */ 938 public this (string string) 939 { 940 // GVariant * g_variant_new_string (const gchar *string); 941 auto p = g_variant_new_string(Str.toStringz(string)); 942 if(p is null) 943 { 944 throw new ConstructionException("null returned by g_variant_new_string(Str.toStringz(string))"); 945 } 946 this(cast(GVariant*) p); 947 } 948 949 /** 950 * Determines if a given string is a valid D-Bus object path. You 951 * should ensure that a string is a valid D-Bus object path before 952 * passing it to g_variant_new_object_path(). 953 * A valid object path starts with '/' followed by zero or more 954 * sequences of characters separated by '/' characters. Each sequence 955 * must contain only the characters "[A-Z][a-z][0-9]_". No sequence 956 * (including the one following the final '/' character) may be empty. 957 * Since 2.24 958 * Params: 959 * string = a normal C nul-terminated string 960 * Returns: TRUE if string is a D-Bus object path 961 */ 962 public static int isObjectPath(string string) 963 { 964 // gboolean g_variant_is_object_path (const gchar *string); 965 return g_variant_is_object_path(Str.toStringz(string)); 966 } 967 968 /** 969 * Determines if a given string is a valid D-Bus type signature. You 970 * should ensure that a string is a valid D-Bus type signature before 971 * passing it to g_variant_new_signature(). 972 * D-Bus type signatures consist of zero or more definite GVariantType 973 * strings in sequence. 974 * Since 2.24 975 * Params: 976 * string = a normal C nul-terminated string 977 * Returns: TRUE if string is a D-Bus type signature 978 */ 979 public static int isSignature(string string) 980 { 981 // gboolean g_variant_is_signature (const gchar *string); 982 return g_variant_is_signature(Str.toStringz(string)); 983 } 984 985 /** 986 * Boxes value. The result is a GVariant instance representing a 987 * variant containing the original value. 988 * If child is a floating reference (see g_variant_ref_sink()), the new 989 * instance takes ownership of child. 990 * Since 2.24 991 * Params: 992 * value = a GVariant instance 993 * Throws: ConstructionException GTK+ fails to create the object. 994 */ 995 public this (Variant value) 996 { 997 // GVariant * g_variant_new_variant (GVariant *value); 998 auto p = g_variant_new_variant((value is null) ? null : value.getVariantStruct()); 999 if(p is null) 1000 { 1001 throw new ConstructionException("null returned by g_variant_new_variant((value is null) ? null : value.getVariantStruct())"); 1002 } 1003 this(cast(GVariant*) p); 1004 } 1005 1006 /** 1007 * Constructs an array of strings GVariant from the given array of 1008 * strings. 1009 * If length is -1 then strv is NULL-terminated. 1010 * Since 2.24 1011 * Params: 1012 * strv = an array of strings. [array length=length][element-type utf8] 1013 * Throws: ConstructionException GTK+ fails to create the object. 1014 */ 1015 public this (string[] strv) 1016 { 1017 // GVariant * g_variant_new_strv (const gchar * const *strv, gssize length); 1018 auto p = g_variant_new_strv(Str.toStringzArray(strv), cast(int) strv.length); 1019 if(p is null) 1020 { 1021 throw new ConstructionException("null returned by g_variant_new_strv(Str.toStringzArray(strv), cast(int) strv.length)"); 1022 } 1023 this(cast(GVariant*) p); 1024 } 1025 1026 /** 1027 * Returns the boolean value of value. 1028 * It is an error to call this function with a value of any type 1029 * other than G_VARIANT_TYPE_BOOLEAN. 1030 * Since 2.24 1031 * Returns: TRUE or FALSE 1032 */ 1033 public int getBoolean() 1034 { 1035 // gboolean g_variant_get_boolean (GVariant *value); 1036 return g_variant_get_boolean(gVariant); 1037 } 1038 1039 /** 1040 * Returns the byte value of value. 1041 * It is an error to call this function with a value of any type 1042 * other than G_VARIANT_TYPE_BYTE. 1043 * Since 2.24 1044 * Returns: a guchar 1045 */ 1046 public char getByte() 1047 { 1048 // guchar g_variant_get_byte (GVariant *value); 1049 return g_variant_get_byte(gVariant); 1050 } 1051 1052 /** 1053 * Returns the 16-bit signed integer value of value. 1054 * It is an error to call this function with a value of any type 1055 * other than G_VARIANT_TYPE_INT16. 1056 * Since 2.24 1057 * Returns: a gint16 1058 */ 1059 public short getInt16() 1060 { 1061 // gint16 g_variant_get_int16 (GVariant *value); 1062 return g_variant_get_int16(gVariant); 1063 } 1064 1065 /** 1066 * Returns the 16-bit unsigned integer value of value. 1067 * It is an error to call this function with a value of any type 1068 * other than G_VARIANT_TYPE_UINT16. 1069 * Since 2.24 1070 * Returns: a guint16 1071 */ 1072 public ushort getUint16() 1073 { 1074 // guint16 g_variant_get_uint16 (GVariant *value); 1075 return g_variant_get_uint16(gVariant); 1076 } 1077 1078 /** 1079 * Returns the 32-bit signed integer value of value. 1080 * It is an error to call this function with a value of any type 1081 * other than G_VARIANT_TYPE_INT32. 1082 * Since 2.24 1083 * Returns: a gint32 1084 */ 1085 public int getInt32() 1086 { 1087 // gint32 g_variant_get_int32 (GVariant *value); 1088 return g_variant_get_int32(gVariant); 1089 } 1090 1091 /** 1092 * Returns the 32-bit unsigned integer value of value. 1093 * It is an error to call this function with a value of any type 1094 * other than G_VARIANT_TYPE_UINT32. 1095 * Since 2.24 1096 * Returns: a guint32 1097 */ 1098 public uint getUint32() 1099 { 1100 // guint32 g_variant_get_uint32 (GVariant *value); 1101 return g_variant_get_uint32(gVariant); 1102 } 1103 1104 /** 1105 * Returns the 64-bit signed integer value of value. 1106 * It is an error to call this function with a value of any type 1107 * other than G_VARIANT_TYPE_INT64. 1108 * Since 2.24 1109 * Returns: a gint64 1110 */ 1111 public long getInt64() 1112 { 1113 // gint64 g_variant_get_int64 (GVariant *value); 1114 return g_variant_get_int64(gVariant); 1115 } 1116 1117 /** 1118 * Returns the 64-bit unsigned integer value of value. 1119 * It is an error to call this function with a value of any type 1120 * other than G_VARIANT_TYPE_UINT64. 1121 * Since 2.24 1122 * Returns: a guint64 1123 */ 1124 public ulong getUint64() 1125 { 1126 // guint64 g_variant_get_uint64 (GVariant *value); 1127 return g_variant_get_uint64(gVariant); 1128 } 1129 1130 /** 1131 * Returns the 32-bit signed integer value of value. 1132 * It is an error to call this function with a value of any type other 1133 * than G_VARIANT_TYPE_HANDLE. 1134 * By convention, handles are indexes into an array of file descriptors 1135 * that are sent alongside a D-Bus message. If you're not interacting 1136 * with D-Bus, you probably don't need them. 1137 * Since 2.24 1138 * Returns: a gint32 1139 */ 1140 public int getHandle() 1141 { 1142 // gint32 g_variant_get_handle (GVariant *value); 1143 return g_variant_get_handle(gVariant); 1144 } 1145 1146 /** 1147 * Returns the double precision floating point value of value. 1148 * It is an error to call this function with a value of any type 1149 * other than G_VARIANT_TYPE_DOUBLE. 1150 * Since 2.24 1151 * Returns: a gdouble 1152 */ 1153 public double getDouble() 1154 { 1155 // gdouble g_variant_get_double (GVariant *value); 1156 return g_variant_get_double(gVariant); 1157 } 1158 1159 /** 1160 * Returns the string value of a GVariant instance with a string 1161 * type. This includes the types G_VARIANT_TYPE_STRING, 1162 * G_VARIANT_TYPE_OBJECT_PATH and G_VARIANT_TYPE_SIGNATURE. 1163 * The string will always be utf8 encoded. 1164 * If length is non-NULL then the length of the string (in bytes) is 1165 * returned there. For trusted values, this information is already 1166 * known. For untrusted values, a strlen() will be performed. 1167 * It is an error to call this function with a value of any type 1168 * other than those three. 1169 * The return value remains valid as long as value exists. 1170 * Since 2.24 1171 * Params: 1172 * length = a pointer to a gsize, 1173 * to store the length. [allow-none][default 0][out] 1174 * Returns: the constant string, utf8 encoded. [transfer none] 1175 */ 1176 public string getString(out gsize length) 1177 { 1178 // const gchar * g_variant_get_string (GVariant *value, gsize *length); 1179 return Str.toString(g_variant_get_string(gVariant, &length)); 1180 } 1181 1182 /** 1183 * Similar to g_variant_get_string() except that instead of returning 1184 * a constant string, the string is duplicated. 1185 * The string will always be utf8 encoded. 1186 * The return value must be freed using g_free(). 1187 * Since 2.24 1188 * Returns: a newly allocated string, utf8 encoded. [transfer full] 1189 */ 1190 public string dupString() 1191 { 1192 // gchar * g_variant_dup_string (GVariant *value, gsize *length); 1193 gsize length; 1194 auto p = g_variant_dup_string(gVariant, &length); 1195 return Str.toString(p, length); 1196 } 1197 1198 /** 1199 * Unboxes value. The result is the GVariant instance that was 1200 * contained in value. 1201 * Since 2.24 1202 * Returns: the item contained in the variant. [transfer full] 1203 */ 1204 public Variant getVariant() 1205 { 1206 // GVariant * g_variant_get_variant (GVariant *value); 1207 auto p = g_variant_get_variant(gVariant); 1208 1209 if(p is null) 1210 { 1211 return null; 1212 } 1213 1214 return new Variant(cast(GVariant*) p); 1215 } 1216 1217 /** 1218 * Gets the contents of an array of strings GVariant. This call 1219 * makes a shallow copy; the return result should be released with 1220 * g_free(), but the individual strings must not be modified. 1221 * If length is non-NULL then the number of elements in the result 1222 * is stored there. In any case, the resulting array will be 1223 * NULL-terminated. 1224 * For an empty array, length will be set to 0 and a pointer to a 1225 * NULL pointer will be returned. 1226 * Since 2.24 1227 * Returns: an array of constant strings. [array length=length zero-terminated=1][transfer container] 1228 */ 1229 public string[] getStrv() 1230 { 1231 // const gchar ** g_variant_get_strv (GVariant *value, gsize *length); 1232 gsize length; 1233 auto p = g_variant_get_strv(gVariant, &length); 1234 1235 string[] strArray = null; 1236 foreach ( cstr; p[0 .. length] ) 1237 { 1238 strArray ~= Str.toString(cstr); 1239 } 1240 1241 return strArray; 1242 } 1243 1244 /** 1245 * Gets the contents of an array of strings GVariant. This call 1246 * makes a deep copy; the return result should be released with 1247 * g_strfreev(). 1248 * If length is non-NULL then the number of elements in the result 1249 * is stored there. In any case, the resulting array will be 1250 * NULL-terminated. 1251 * For an empty array, length will be set to 0 and a pointer to a 1252 * NULL pointer will be returned. 1253 * Since 2.24 1254 * Returns: an array of strings. [array length=length zero-terminated=1][transfer full] 1255 */ 1256 public string[] dupStrv() 1257 { 1258 // gchar ** g_variant_dup_strv (GVariant *value, gsize *length); 1259 gsize length; 1260 auto p = g_variant_dup_strv(gVariant, &length); 1261 1262 string[] strArray = null; 1263 foreach ( cstr; p[0 .. length] ) 1264 { 1265 strArray ~= Str.toString(cstr); 1266 } 1267 1268 return strArray; 1269 } 1270 1271 /** 1272 * Gets the contents of an array of object paths GVariant. This call 1273 * makes a shallow copy; the return result should be released with 1274 * g_free(), but the individual strings must not be modified. 1275 * If length is non-NULL then the number of elements in the result 1276 * is stored there. In any case, the resulting array will be 1277 * NULL-terminated. 1278 * For an empty array, length will be set to 0 and a pointer to a 1279 * NULL pointer will be returned. 1280 * Since 2.30 1281 * Returns: an array of constant strings. [array length=length zero-terminated=1][transfer container] 1282 */ 1283 public string[] getObjv() 1284 { 1285 // const gchar ** g_variant_get_objv (GVariant *value, gsize *length); 1286 gsize length; 1287 auto p = g_variant_get_objv(gVariant, &length); 1288 1289 string[] strArray = null; 1290 foreach ( cstr; p[0 .. length] ) 1291 { 1292 strArray ~= Str.toString(cstr); 1293 } 1294 1295 return strArray; 1296 } 1297 1298 /** 1299 * Gets the contents of an array of object paths GVariant. This call 1300 * makes a deep copy; the return result should be released with 1301 * g_strfreev(). 1302 * If length is non-NULL then the number of elements in the result 1303 * is stored there. In any case, the resulting array will be 1304 * NULL-terminated. 1305 * For an empty array, length will be set to 0 and a pointer to a 1306 * NULL pointer will be returned. 1307 * Since 2.30 1308 * Returns: an array of strings. [array length=length zero-terminated=1][transfer full] 1309 */ 1310 public string[] dupObjv() 1311 { 1312 // gchar ** g_variant_dup_objv (GVariant *value, gsize *length); 1313 gsize length; 1314 auto p = g_variant_dup_objv(gVariant, &length); 1315 1316 string[] strArray = null; 1317 foreach ( cstr; p[0 .. length] ) 1318 { 1319 strArray ~= Str.toString(cstr); 1320 } 1321 1322 return strArray; 1323 } 1324 1325 /** 1326 * Returns the string value of a GVariant instance with an 1327 * array-of-bytes type. The string has no particular encoding. 1328 * If the array does not end with a nul terminator character, the empty 1329 * string is returned. For this reason, you can always trust that a 1330 * non-NULL nul-terminated string will be returned by this function. 1331 * If the array contains a nul terminator character somewhere other than 1332 * the last byte then the returned string is the string, up to the first 1333 * such nul character. 1334 * It is an error to call this function with a value that is not an 1335 * array of bytes. 1336 * The return value remains valid as long as value exists. 1337 * Since 2.26 1338 * Returns: the constant string. [transfer none][array zero-terminated=1][element-type guint8] 1339 */ 1340 public string getBytestring() 1341 { 1342 // const gchar * g_variant_get_bytestring (GVariant *value); 1343 return Str.toString(g_variant_get_bytestring(gVariant)); 1344 } 1345 1346 /** 1347 * Similar to g_variant_get_bytestring() except that instead of 1348 * returning a constant string, the string is duplicated. 1349 * The return value must be freed using g_free(). 1350 * Since 2.26 1351 * Returns: a newly allocated string. [transfer full][array zero-terminated=1 length=length][element-type guint8] 1352 */ 1353 public string dupBytestring() 1354 { 1355 // gchar * g_variant_dup_bytestring (GVariant *value, gsize *length); 1356 gsize length; 1357 auto p = g_variant_dup_bytestring(gVariant, &length); 1358 return Str.toString(p, length); 1359 } 1360 1361 /** 1362 * Gets the contents of an array of array of bytes GVariant. This call 1363 * makes a shallow copy; the return result should be released with 1364 * g_free(), but the individual strings must not be modified. 1365 * If length is non-NULL then the number of elements in the result is 1366 * stored there. In any case, the resulting array will be 1367 * NULL-terminated. 1368 * For an empty array, length will be set to 0 and a pointer to a 1369 * NULL pointer will be returned. 1370 * Since 2.26 1371 * Returns: an array of constant strings. [array length=length][transfer container] 1372 */ 1373 public string[] getBytestringArray() 1374 { 1375 // const gchar ** g_variant_get_bytestring_array (GVariant *value, gsize *length); 1376 gsize length; 1377 auto p = g_variant_get_bytestring_array(gVariant, &length); 1378 1379 string[] strArray = null; 1380 foreach ( cstr; p[0 .. length] ) 1381 { 1382 strArray ~= Str.toString(cstr); 1383 } 1384 1385 return strArray; 1386 } 1387 1388 /** 1389 * Gets the contents of an array of array of bytes GVariant. This call 1390 * makes a deep copy; the return result should be released with 1391 * g_strfreev(). 1392 * If length is non-NULL then the number of elements in the result is 1393 * stored there. In any case, the resulting array will be 1394 * NULL-terminated. 1395 * For an empty array, length will be set to 0 and a pointer to a 1396 * NULL pointer will be returned. 1397 * Since 2.26 1398 * Returns: an array of strings. [array length=length][transfer full] 1399 */ 1400 public string[] dupBytestringArray() 1401 { 1402 // gchar ** g_variant_dup_bytestring_array (GVariant *value, gsize *length); 1403 gsize length; 1404 auto p = g_variant_dup_bytestring_array(gVariant, &length); 1405 1406 string[] strArray = null; 1407 foreach ( cstr; p[0 .. length] ) 1408 { 1409 strArray ~= Str.toString(cstr); 1410 } 1411 1412 return strArray; 1413 } 1414 1415 /** 1416 * Depending on if child is NULL, either wraps child inside of a 1417 * maybe container or creates a Nothing instance for the given type. 1418 * At least one of child_type and child must be non-NULL. 1419 * If child_type is non-NULL then it must be a definite type. 1420 * If they are both non-NULL then child_type must be the type 1421 * of child. 1422 * If child is a floating reference (see g_variant_ref_sink()), the new 1423 * instance takes ownership of child. 1424 * Since 2.24 1425 * Params: 1426 * childType = the GVariantType of the child, or NULL. [allow-none] 1427 * child = the child value, or NULL. [allow-none] 1428 * Throws: ConstructionException GTK+ fails to create the object. 1429 */ 1430 public this (VariantType childType, Variant child) 1431 { 1432 // GVariant * g_variant_new_maybe (const GVariantType *child_type, GVariant *child); 1433 auto p = g_variant_new_maybe((childType is null) ? null : childType.getVariantTypeStruct(), (child is null) ? null : child.getVariantStruct()); 1434 if(p is null) 1435 { 1436 throw new ConstructionException("null returned by g_variant_new_maybe((childType is null) ? null : childType.getVariantTypeStruct(), (child is null) ? null : child.getVariantStruct())"); 1437 } 1438 this(cast(GVariant*) p); 1439 } 1440 1441 /** 1442 * Creates a new GVariant array from children. 1443 * child_type must be non-NULL if n_children is zero. Otherwise, the 1444 * child type is determined by inspecting the first element of the 1445 * children array. If child_type is non-NULL then it must be a 1446 * definite type. 1447 * The items of the array are taken from the children array. No entry 1448 * in the children array may be NULL. 1449 * All items in the array must have the same type, which must be the 1450 * same as child_type, if given. 1451 * If the children are floating references (see g_variant_ref_sink()), the 1452 * new instance takes ownership of them as if via g_variant_ref_sink(). 1453 * Since 2.24 1454 * Params: 1455 * childType = the element type of the new array. [allow-none] 1456 * children = an array of 1457 * GVariant pointers, the children. [allow-none][array length=n_children] 1458 * Throws: ConstructionException GTK+ fails to create the object. 1459 */ 1460 public this (VariantType childType, Variant[] children) 1461 { 1462 // GVariant * g_variant_new_array (const GVariantType *child_type, GVariant * const *children, gsize n_children); 1463 1464 GVariant*[] childrenArray = new GVariant*[children.length]; 1465 for ( int i = 0; i < children.length ; i++ ) 1466 { 1467 childrenArray[i] = children[i].getVariantStruct(); 1468 } 1469 1470 auto p = g_variant_new_array((childType is null) ? null : childType.getVariantTypeStruct(), childrenArray.ptr, cast(int) children.length); 1471 if(p is null) 1472 { 1473 throw new ConstructionException("null returned by g_variant_new_array((childType is null) ? null : childType.getVariantTypeStruct(), childrenArray.ptr, cast(int) children.length)"); 1474 } 1475 this(cast(GVariant*) p); 1476 } 1477 1478 /** 1479 * Creates a new tuple GVariant out of the items in children. The 1480 * type is determined from the types of children. No entry in the 1481 * children array may be NULL. 1482 * If n_children is 0 then the unit tuple is constructed. 1483 * If the children are floating references (see g_variant_ref_sink()), the 1484 * new instance takes ownership of them as if via g_variant_ref_sink(). 1485 * Since 2.24 1486 * Params: 1487 * children = the items to make the tuple out of. [array length=n_children] 1488 * Throws: ConstructionException GTK+ fails to create the object. 1489 */ 1490 public this (Variant[] children) 1491 { 1492 // GVariant * g_variant_new_tuple (GVariant * const *children, gsize n_children); 1493 1494 GVariant*[] childrenArray = new GVariant*[children.length]; 1495 for ( int i = 0; i < children.length ; i++ ) 1496 { 1497 childrenArray[i] = children[i].getVariantStruct(); 1498 } 1499 1500 auto p = g_variant_new_tuple(childrenArray.ptr, cast(int) children.length); 1501 if(p is null) 1502 { 1503 throw new ConstructionException("null returned by g_variant_new_tuple(childrenArray.ptr, cast(int) children.length)"); 1504 } 1505 this(cast(GVariant*) p); 1506 } 1507 1508 /** 1509 * Creates a new dictionary entry GVariant. key and value must be 1510 * non-NULL. key must be a value of a basic type (ie: not a container). 1511 * If the key or value are floating references (see g_variant_ref_sink()), 1512 * the new instance takes ownership of them as if via g_variant_ref_sink(). 1513 * Since 2.24 1514 * Params: 1515 * key = a basic GVariant, the key 1516 * value = a GVariant, the value 1517 * Throws: ConstructionException GTK+ fails to create the object. 1518 */ 1519 public this (Variant key, Variant value) 1520 { 1521 // GVariant * g_variant_new_dict_entry (GVariant *key, GVariant *value); 1522 auto p = g_variant_new_dict_entry((key is null) ? null : key.getVariantStruct(), (value is null) ? null : value.getVariantStruct()); 1523 if(p is null) 1524 { 1525 throw new ConstructionException("null returned by g_variant_new_dict_entry((key is null) ? null : key.getVariantStruct(), (value is null) ? null : value.getVariantStruct())"); 1526 } 1527 this(cast(GVariant*) p); 1528 } 1529 1530 /** 1531 * Provides access to the serialised data for an array of fixed-sized 1532 * items. 1533 * value must be an array with fixed-sized elements. Numeric types are 1534 * fixed-size as are tuples containing only other fixed-sized types. 1535 * element_size must be the size of a single element in the array. For 1536 * example, if calling this function for an array of 32 bit integers, 1537 * you might say sizeof (gint32). This value isn't used 1538 * except for the purpose of a double-check that the form of the 1539 * serialised data matches the caller's expectation. 1540 * n_elements, which must be non-NULL is set equal to the number of 1541 * items in the array. 1542 * Since 2.32 1543 * Params: 1544 * elementType = the GVariantType of each element 1545 * elements = a pointer to the fixed array of contiguous elements 1546 * elementSize = the size of each element 1547 * Throws: ConstructionException GTK+ fails to create the object. 1548 */ 1549 public this (VariantType elementType, void[] elements, gsize elementSize) 1550 { 1551 // GVariant * g_variant_new_fixed_array (const GVariantType *element_type, gconstpointer elements, gsize n_elements, gsize element_size); 1552 auto p = g_variant_new_fixed_array((elementType is null) ? null : elementType.getVariantTypeStruct(), elements.ptr, cast(int) elements.length, elementSize); 1553 if(p is null) 1554 { 1555 throw new ConstructionException("null returned by g_variant_new_fixed_array((elementType is null) ? null : elementType.getVariantTypeStruct(), elements.ptr, cast(int) elements.length, elementSize)"); 1556 } 1557 this(cast(GVariant*) p); 1558 } 1559 1560 /** 1561 * Given a maybe-typed GVariant instance, extract its value. If the 1562 * value is Nothing, then this function returns NULL. 1563 * Since 2.24 1564 * Returns: the contents of value, or NULL. [allow-none][transfer full] 1565 */ 1566 public Variant getMaybe() 1567 { 1568 // GVariant * g_variant_get_maybe (GVariant *value); 1569 auto p = g_variant_get_maybe(gVariant); 1570 1571 if(p is null) 1572 { 1573 return null; 1574 } 1575 1576 return new Variant(cast(GVariant*) p); 1577 } 1578 1579 /** 1580 * Determines the number of children in a container GVariant instance. 1581 * This includes variants, maybes, arrays, tuples and dictionary 1582 * entries. It is an error to call this function on any other type of 1583 * GVariant. 1584 * For variants, the return value is always 1. For values with maybe 1585 * types, it is always zero or one. For arrays, it is the length of the 1586 * array. For tuples it is the number of tuple items (which depends 1587 * only on the type). For dictionary entries, it is always 2 1588 * This function is O(1). 1589 * Since 2.24 1590 * Returns: the number of children in the container 1591 */ 1592 public gsize nChildren() 1593 { 1594 // gsize g_variant_n_children (GVariant *value); 1595 return g_variant_n_children(gVariant); 1596 } 1597 1598 /** 1599 * Reads a child item out of a container GVariant instance. This 1600 * includes variants, maybes, arrays, tuples and dictionary 1601 * entries. It is an error to call this function on any other type of 1602 * GVariant. 1603 * It is an error if index_ is greater than the number of child items 1604 * in the container. See g_variant_n_children(). 1605 * The returned value is never floating. You should free it with 1606 * g_variant_unref() when you're done with it. 1607 * This function is O(1). 1608 * Since 2.24 1609 * Params: 1610 * index = the index of the child to fetch 1611 * Returns: the child at the specified index. [transfer full] 1612 */ 1613 public Variant getChildValue(gsize index) 1614 { 1615 // GVariant * g_variant_get_child_value (GVariant *value, gsize index_); 1616 auto p = g_variant_get_child_value(gVariant, index); 1617 1618 if(p is null) 1619 { 1620 return null; 1621 } 1622 1623 return new Variant(cast(GVariant*) p); 1624 } 1625 1626 /** 1627 * Looks up a value in a dictionary GVariant. 1628 * This function works with dictionaries of the type 1629 * a{s*} (and equally well with type 1630 * a{o*}, but we only further discuss the string case 1631 * for sake of clarity). 1632 * In the event that dictionary has the type a{sv}, 1633 * the expected_type string specifies what type of value is expected to 1634 * be inside of the variant. If the value inside the variant has a 1635 * different type then NULL is returned. In the event that dictionary 1636 * has a value type other than v then expected_type 1637 * must directly match the key type and it is used to unpack the value 1638 * directly or an error occurs. 1639 * In either case, if key is not found in dictionary, NULL is 1640 * returned. 1641 * If the key is found and the value has the correct type, it is 1642 * returned. If expected_type was specified then any non-NULL return 1643 * value will have this type. 1644 * Since 2.28 1645 * Params: 1646 * key = the key to lookup in the dictionary 1647 * expectedType = a GVariantType, or NULL. [allow-none] 1648 * Returns: the value of the dictionary key, or NULL. [transfer full] 1649 */ 1650 public Variant lookupValue(string key, VariantType expectedType) 1651 { 1652 // GVariant * g_variant_lookup_value (GVariant *dictionary, const gchar *key, const GVariantType *expected_type); 1653 auto p = g_variant_lookup_value(gVariant, Str.toStringz(key), (expectedType is null) ? null : expectedType.getVariantTypeStruct()); 1654 1655 if(p is null) 1656 { 1657 return null; 1658 } 1659 1660 return new Variant(cast(GVariant*) p); 1661 } 1662 1663 /** 1664 * Provides access to the serialised data for an array of fixed-sized 1665 * items. 1666 * value must be an array with fixed-sized elements. Numeric types are 1667 * fixed-size, as are tuples containing only other fixed-sized types. 1668 * element_size must be the size of a single element in the array, 1669 * as given by the section on 1670 * Serialised Data 1671 * Memory. 1672 * In particular, arrays of these fixed-sized types can be interpreted 1673 * as an array of the given C type, with element_size set to 1674 * Since 2.24 1675 * Params: 1676 * nElements = a pointer to the location to store the number of items. [out] 1677 * elementSize = the size of each element 1678 * Returns: a pointer to the fixed array. [array length=n_elements][transfer none] 1679 */ 1680 public void* getFixedArray(gsize* nElements, gsize elementSize) 1681 { 1682 // gconstpointer g_variant_get_fixed_array (GVariant *value, gsize *n_elements, gsize element_size); 1683 return g_variant_get_fixed_array(gVariant, nElements, elementSize); 1684 } 1685 1686 /** 1687 * Determines the number of bytes that would be required to store value 1688 * with g_variant_store(). 1689 * If value has a fixed-sized type then this function always returned 1690 * that fixed size. 1691 * In the case that value is already in serialised form or the size has 1692 * already been calculated (ie: this function has been called before) 1693 * then this function is O(1). Otherwise, the size is calculated, an 1694 * operation which is approximately O(n) in the number of values 1695 * involved. 1696 * Since 2.24 1697 * Returns: the serialised size of value 1698 */ 1699 public gsize getSize() 1700 { 1701 // gsize g_variant_get_size (GVariant *value); 1702 return g_variant_get_size(gVariant); 1703 } 1704 1705 /** 1706 * Returns a pointer to the serialised form of a GVariant instance. 1707 * The returned data may not be in fully-normalised form if read from an 1708 * untrusted source. The returned data must not be freed; it remains 1709 * valid for as long as value exists. 1710 * If value is a fixed-sized value that was deserialised from a 1711 * corrupted serialised container then NULL may be returned. In this 1712 * case, the proper thing to do is typically to use the appropriate 1713 * number of nul bytes in place of value. If value is not fixed-sized 1714 * then NULL is never returned. 1715 * In the case that value is already in serialised form, this function 1716 * is O(1). If the value is not already in serialised form, 1717 * serialisation occurs implicitly and is approximately O(n) in the size 1718 * of the result. 1719 * To deserialise the data returned by this function, in addition to the 1720 * serialised data, you must know the type of the GVariant, and (if the 1721 * machine might be different) the endianness of the machine that stored 1722 * it. As a result, file formats or network messages that incorporate 1723 * serialised GVariants must include this information either 1724 * implicitly (for instance "the file always contains a 1725 * G_VARIANT_TYPE_VARIANT and it is always in little-endian order") or 1726 * explicitly (by storing the type and/or endianness in addition to the 1727 * serialised data). 1728 * Since 2.24 1729 * Returns: the serialised form of value, or NULL. [transfer none] 1730 */ 1731 public void* getData() 1732 { 1733 // gconstpointer g_variant_get_data (GVariant *value); 1734 return g_variant_get_data(gVariant); 1735 } 1736 1737 /** 1738 * Returns a pointer to the serialised form of a GVariant instance. 1739 * The semantics of this function are exactly the same as 1740 * g_variant_get_data(), except that the returned GBytes holds 1741 * a reference to the variant data. 1742 * Since 2.36 1743 * Returns: A new GBytes representing the variant data. [transfer full] 1744 */ 1745 public Bytes getDataAsBytes() 1746 { 1747 // GBytes * g_variant_get_data_as_bytes (GVariant *value); 1748 auto p = g_variant_get_data_as_bytes(gVariant); 1749 1750 if(p is null) 1751 { 1752 return null; 1753 } 1754 1755 return new Bytes(cast(GBytes*) p); 1756 } 1757 1758 /** 1759 * Stores the serialised form of value at data. data should be 1760 * large enough. See g_variant_get_size(). 1761 * The stored data is in machine native byte order but may not be in 1762 * fully-normalised form if read from an untrusted source. See 1763 * g_variant_get_normal_form() for a solution. 1764 * As with g_variant_get_data(), to be able to deserialise the 1765 * serialised variant successfully, its type and (if the destination 1766 * machine might be different) its endianness must also be available. 1767 * This function is approximately O(n) in the size of data. 1768 * Since 2.24 1769 * Params: 1770 * data = the location to store the serialised data at 1771 */ 1772 public void store(void* data) 1773 { 1774 // void g_variant_store (GVariant *value, gpointer data); 1775 g_variant_store(gVariant, data); 1776 } 1777 1778 /** 1779 * Creates a new GVariant instance from serialised data. 1780 * type is the type of GVariant instance that will be constructed. 1781 * The interpretation of data depends on knowing the type. 1782 * data is not modified by this function and must remain valid with an 1783 * unchanging value until such a time as notify is called with 1784 * user_data. If the contents of data change before that time then 1785 * the result is undefined. 1786 * If data is trusted to be serialised data in normal form then 1787 * trusted should be TRUE. This applies to serialised data created 1788 * within this process or read from a trusted location on the disk (such 1789 * as a file installed in /usr/lib alongside your application). You 1790 * should set trusted to FALSE if data is read from the network, a 1791 * file in the user's home directory, etc. 1792 * If data was not stored in this machine's native endianness, any multi-byte 1793 * numeric values in the returned variant will also be in non-native 1794 * endianness. g_variant_byteswap() can be used to recover the original values. 1795 * notify will be called with user_data when data is no longer 1796 * needed. The exact time of this call is unspecified and might even be 1797 * before this function returns. 1798 * Since 2.24 1799 * Params: 1800 * type = a definite GVariantType 1801 * data = the serialised data. [array length=size][element-type guint8] 1802 * size = the size of data 1803 * trusted = TRUE if data is definitely in normal form 1804 * notify = function to call when data is no longer needed. [scope async] 1805 * userData = data for notify 1806 * Throws: ConstructionException GTK+ fails to create the object. 1807 */ 1808 public this (VariantType type, void* data, gsize size, int trusted, GDestroyNotify notify, void* userData) 1809 { 1810 // GVariant * g_variant_new_from_data (const GVariantType *type, gconstpointer data, gsize size, gboolean trusted, GDestroyNotify notify, gpointer user_data); 1811 auto p = g_variant_new_from_data((type is null) ? null : type.getVariantTypeStruct(), data, size, trusted, notify, userData); 1812 if(p is null) 1813 { 1814 throw new ConstructionException("null returned by g_variant_new_from_data((type is null) ? null : type.getVariantTypeStruct(), data, size, trusted, notify, userData)"); 1815 } 1816 this(cast(GVariant*) p); 1817 } 1818 1819 /** 1820 * Constructs a new serialised-mode GVariant instance. This is the 1821 * inner interface for creation of new serialised values that gets 1822 * called from various functions in gvariant.c. 1823 * A reference is taken on bytes. 1824 * Since 2.36 1825 * Params: 1826 * type = a GVariantType 1827 * bytes = a GBytes 1828 * trusted = if the contents of bytes are trusted 1829 * Throws: ConstructionException GTK+ fails to create the object. 1830 */ 1831 public this (VariantType type, Bytes bytes, int trusted) 1832 { 1833 // GVariant * g_variant_new_from_bytes (const GVariantType *type, GBytes *bytes, gboolean trusted); 1834 auto p = g_variant_new_from_bytes((type is null) ? null : type.getVariantTypeStruct(), (bytes is null) ? null : bytes.getBytesStruct(), trusted); 1835 if(p is null) 1836 { 1837 throw new ConstructionException("null returned by g_variant_new_from_bytes((type is null) ? null : type.getVariantTypeStruct(), (bytes is null) ? null : bytes.getBytesStruct(), trusted)"); 1838 } 1839 this(cast(GVariant*) p); 1840 } 1841 1842 /** 1843 * Performs a byteswapping operation on the contents of value. The 1844 * result is that all multi-byte numeric data contained in value is 1845 * byteswapped. That includes 16, 32, and 64bit signed and unsigned 1846 * integers as well as file handles and double precision floating point 1847 * values. 1848 * This function is an identity mapping on any value that does not 1849 * contain multi-byte numeric data. That include strings, booleans, 1850 * bytes and containers containing only these things (recursively). 1851 * The returned value is always in normal form and is marked as trusted. 1852 * Since 2.24 1853 * Returns: the byteswapped form of value. [transfer full] 1854 */ 1855 public Variant byteswap() 1856 { 1857 // GVariant * g_variant_byteswap (GVariant *value); 1858 auto p = g_variant_byteswap(gVariant); 1859 1860 if(p is null) 1861 { 1862 return null; 1863 } 1864 1865 return new Variant(cast(GVariant*) p); 1866 } 1867 1868 /** 1869 * Gets a GVariant instance that has the same value as value and is 1870 * trusted to be in normal form. 1871 * If value is already trusted to be in normal form then a new 1872 * reference to value is returned. 1873 * If value is not already trusted, then it is scanned to check if it 1874 * is in normal form. If it is found to be in normal form then it is 1875 * marked as trusted and a new reference to it is returned. 1876 * If value is found not to be in normal form then a new trusted 1877 * GVariant is created with the same value as value. 1878 * It makes sense to call this function if you've received GVariant 1879 * data from untrusted sources and you want to ensure your serialised 1880 * output is definitely in normal form. 1881 * Since 2.24 1882 * Returns: a trusted GVariant. [transfer full] 1883 */ 1884 public Variant getNormalForm() 1885 { 1886 // GVariant * g_variant_get_normal_form (GVariant *value); 1887 auto p = g_variant_get_normal_form(gVariant); 1888 1889 if(p is null) 1890 { 1891 return null; 1892 } 1893 1894 return new Variant(cast(GVariant*) p); 1895 } 1896 1897 /** 1898 * Checks if value is in normal form. 1899 * The main reason to do this is to detect if a given chunk of 1900 * serialised data is in normal form: load the data into a GVariant 1901 * using g_variant_new_from_data() and then use this function to 1902 * check. 1903 * If value is found to be in normal form then it will be marked as 1904 * being trusted. If the value was already marked as being trusted then 1905 * this function will immediately return TRUE. 1906 * Since 2.24 1907 * Returns: TRUE if value is in normal form 1908 */ 1909 public int isNormalForm() 1910 { 1911 // gboolean g_variant_is_normal_form (GVariant *value); 1912 return g_variant_is_normal_form(gVariant); 1913 } 1914 1915 /** 1916 * Generates a hash value for a GVariant instance. 1917 * The output of this function is guaranteed to be the same for a given 1918 * value only per-process. It may change between different processor 1919 * architectures or even different versions of GLib. Do not use this 1920 * function as a basis for building protocols or file formats. 1921 * The type of value is gconstpointer only to allow use of this 1922 * function with GHashTable. value must be a GVariant. 1923 * Since 2.24 1924 * Params: 1925 * value = a basic GVariant value as a gconstpointer. [type GVariant] 1926 * Returns: a hash value corresponding to value 1927 */ 1928 public static uint hash(void* value) 1929 { 1930 // guint g_variant_hash (gconstpointer value); 1931 return g_variant_hash(value); 1932 } 1933 1934 /** 1935 * Checks if one and two have the same type and value. 1936 * The types of one and two are gconstpointer only to allow use of 1937 * this function with GHashTable. They must each be a GVariant. 1938 * Since 2.24 1939 * Params: 1940 * one = a GVariant instance. [type GVariant] 1941 * two = a GVariant instance. [type GVariant] 1942 * Returns: TRUE if one and two are equal 1943 */ 1944 public static int equal(void* one, void* two) 1945 { 1946 // gboolean g_variant_equal (gconstpointer one, gconstpointer two); 1947 return g_variant_equal(one, two); 1948 } 1949 1950 /** 1951 * Pretty-prints value in the format understood by g_variant_parse(). 1952 * The format is described here. 1953 * If type_annotate is TRUE, then type information is included in 1954 * the output. 1955 * Since 2.24 1956 * Params: 1957 * typeAnnotate = TRUE if type information should be included in 1958 * the output 1959 * Returns: a newly-allocated string holding the result. [transfer full] 1960 */ 1961 public string print(int typeAnnotate) 1962 { 1963 // gchar * g_variant_print (GVariant *value, gboolean type_annotate); 1964 return Str.toString(g_variant_print(gVariant, typeAnnotate)); 1965 } 1966 1967 /** 1968 * Behaves as g_variant_print(), but operates on a GString. 1969 * If string is non-NULL then it is appended to and returned. Else, 1970 * a new empty GString is allocated and it is returned. 1971 * Since 2.24 1972 * Params: 1973 * string = a GString, or NULL. [allow-none][default NULL] 1974 * typeAnnotate = TRUE if type information should be included in 1975 * the output 1976 * Returns: a GString containing the string 1977 */ 1978 public StringG printString(StringG string, int typeAnnotate) 1979 { 1980 // GString * g_variant_print_string (GVariant *value, GString *string, gboolean type_annotate); 1981 auto p = g_variant_print_string(gVariant, (string is null) ? null : string.getStringGStruct(), typeAnnotate); 1982 1983 if(p is null) 1984 { 1985 return null; 1986 } 1987 1988 return new StringG(cast(GString*) p); 1989 } 1990 1991 /** 1992 * Parses a GVariant from a text representation. 1993 * A single GVariant is parsed from the content of text. 1994 * The format is described here. 1995 * The memory at limit will never be accessed and the parser behaves as 1996 * if the character at limit is the nul terminator. This has the 1997 * effect of bounding text. 1998 * If endptr is non-NULL then text is permitted to contain data 1999 * following the value that this function parses and endptr will be 2000 * updated to point to the first character past the end of the text 2001 * parsed by this function. If endptr is NULL and there is extra data 2002 * then an error is returned. 2003 * If type is non-NULL then the value will be parsed to have that 2004 * type. This may result in additional parse errors (in the case that 2005 * the parsed value doesn't fit the type) but may also result in fewer 2006 * errors (in the case that the type would have been ambiguous, such as 2007 * with empty arrays). 2008 * In the event that the parsing is successful, the resulting GVariant 2009 * is returned. 2010 * In case of any error, NULL will be returned. If error is non-NULL 2011 * then it will be set to reflect the error that occurred. 2012 * Officially, the language understood by the parser is "any string 2013 * produced by g_variant_print()". 2014 * Params: 2015 * type = a GVariantType, or NULL. [allow-none] 2016 * text = a string containing a GVariant in text form 2017 * limit = a pointer to the end of text, or NULL. [allow-none] 2018 * endptr = a location to store the end pointer, or NULL. [allow-none] 2019 * Returns: a reference to a GVariant, or NULL 2020 * Throws: GException on failure. 2021 */ 2022 public static Variant parse(VariantType type, string text, string limit, out string endptr) 2023 { 2024 // GVariant * g_variant_parse (const GVariantType *type, const gchar *text, const gchar *limit, const gchar **endptr, GError **error); 2025 char* outendptr = null; 2026 GError* err = null; 2027 2028 auto p = g_variant_parse((type is null) ? null : type.getVariantTypeStruct(), Str.toStringz(text), Str.toStringz(limit), &outendptr, &err); 2029 2030 if (err !is null) 2031 { 2032 throw new GException( new ErrorG(err) ); 2033 } 2034 2035 endptr = Str.toString(outendptr); 2036 2037 if(p is null) 2038 { 2039 return null; 2040 } 2041 2042 return new Variant(cast(GVariant*) p); 2043 } 2044 2045 /** 2046 * Parses format and returns the result. 2047 * This is the version of g_variant_new_parsed() intended to be used 2048 * from libraries. 2049 * The return value will be floating if it was a newly created GVariant 2050 * instance. In the case that format simply specified the collection 2051 * of a GVariant pointer (eg: format was "%*") then the collected 2052 * GVariant pointer will be returned unmodified, without adding any 2053 * additional references. 2054 * In order to behave correctly in all cases it is necessary for the 2055 * calling function to g_variant_ref_sink() the return result before 2056 * returning control to the user that originally provided the pointer. 2057 * At this point, the caller will have their own full reference to the 2058 * result. This can also be done by adding the result to a container, 2059 * or by passing it to another g_variant_new() call. 2060 * Params: 2061 * format = a text format GVariant 2062 * app = a pointer to a va_list 2063 * Throws: ConstructionException GTK+ fails to create the object. 2064 */ 2065 public this (string format, void** app) 2066 { 2067 // GVariant * g_variant_new_parsed_va (const gchar *format, va_list *app); 2068 auto p = g_variant_new_parsed_va(Str.toStringz(format), app); 2069 if(p is null) 2070 { 2071 throw new ConstructionException("null returned by g_variant_new_parsed_va(Str.toStringz(format), app)"); 2072 } 2073 this(cast(GVariant*) p); 2074 } 2075 }