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