Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file gvariant.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283(**************************************************************************)(* ocgtk - OCaml bindings for GTK4 *)(* *)(* This program is free software; you can redistribute it *)(* and/or modify it under the terms of the GNU Library General *)(* Public License version 2, as published by the *)(* Free Software Foundation with the exception described in file *)(* COPYING which comes with the library. *)(* *)(* Based on lablgtk3 (https://github.com/garrigue/lablgtk) *)(* *)(**************************************************************************)(** GVariant - GLib's variant type for structured data serialization
GVariant is a variant data type used for:
- GSettings value storage and retrieval
- GAction parameters and state
- GDBus structured data
- GtkActionable action targets
This module provides opaque wrapper type [t] with reference counting,
plus typed constructors and accessors for all GVariant types.
Type Codes:
- b: boolean
- y: byte (uint8)
- n: int16
- q: uint16
- i: int32
- u: uint32
- x: int64
- t: uint64
- d: double
- s: string
- o: object_path
- g: signature
- h: handle (file descriptor)
- v: variant
- m*: maybe (nullable)
- a*: array
- () : tuple
- {} : dictionary entry
*)(** {2 Unsigned Integer Types} *)typeuint32=UInt32.t(** Unsigned 32-bit integer *)typeuint64=UInt64.t(** Unsigned 64-bit integer *)typeuint16=UInt16.t(** Unsigned 16-bit integer *)typeint16=int(** Signed 16-bit integer - stored as OCaml int *)(** {2 Opaque GVariant Type} *)typet(** Opaque GVariant type - backed by GVariant* with g_variant_unref finalizer *)(** {2 Type Introspection} *)externaltype_string:t->string="ml_g_variant_get_type_string"(** Get the type string of the variant (e.g., "i" for int32, "s" for string) *)externalis_of_type:t->string->bool="ml_g_variant_is_of_type"(** Check if the variant is of the given type string *)(** {2 Boolean} *)externalof_boolean:bool->t="ml_g_variant_new_boolean"(** Create a boolean variant. *)externalto_boolean:t->bool="ml_g_variant_get_boolean"(** Get the boolean value. Raises Failure if the variant is not a boolean. *)(** {2 Byte (uint8)} *)externalof_byte:int->t="ml_g_variant_new_byte"(** Create a byte variant. *)externalto_byte:t->int="ml_g_variant_get_byte"(** Get the byte value. Raises Failure if the variant is not a byte. *)(** {2 Signed Integers} *)externalof_int16:int16->t="ml_g_variant_new_int16"(** Create an int16 variant. *)externalto_int16:t->int16="ml_g_variant_get_int16"(** Get the int16 value. Raises Failure if the variant is not an int16. *)externalof_int32:int32->t="ml_g_variant_new_int32"(** Create an int32 variant. *)externalto_int32:t->int32="ml_g_variant_get_int32"(** Get the int32 value. Raises Failure if the variant is not an int32. *)externalof_int64:int64->t="ml_g_variant_new_int64"(** Create an int64 variant. *)externalto_int64:t->int64="ml_g_variant_get_int64"(** Get the int64 value. Raises Failure if the variant is not an int64. *)(** {2 Unsigned Integers} *)externalof_uint16:uint16->t="ml_g_variant_new_uint16"(** Create a uint16 variant. *)externalto_uint16:t->uint16="ml_g_variant_get_uint16"(** Get the uint16 value. Raises Failure if the variant is not a uint16. *)externalof_uint32:uint32->t="ml_g_variant_new_uint32"(** Create a uint32 variant. *)externalto_uint32:t->uint32="ml_g_variant_get_uint32"(** Get the uint32 value. Raises Failure if the variant is not a uint32. *)externalof_uint64:uint64->t="ml_g_variant_new_uint64"(** Create a uint64 variant. *)externalto_uint64:t->uint64="ml_g_variant_get_uint64"(** Get the uint64 value. Raises Failure if the variant is not a uint64. *)(** {2 Floating Point} *)externalof_double:float->t="ml_g_variant_new_double"(** Create a double variant. *)externalto_double:t->float="ml_g_variant_get_double"(** Get the double value. Raises Failure if the variant is not a double. *)(** {2 Text Types} *)externalof_string:string->t="ml_g_variant_new_string"(** Create a string variant. *)externalto_string:t->string="ml_g_variant_get_string"(** Get the string value. Raises Failure if the variant is not a string. *)externalof_object_path:string->t="ml_g_variant_new_object_path"(** D-Bus object path - validated to be a valid object path; use to_string to
read back *)externalof_signature:string->t="ml_g_variant_new_signature"(** D-Bus type signature; use to_string to read back *)(** {2 Handle (File Descriptor)} *)externalof_handle:int->t="ml_g_variant_new_handle"(** Create a handle (file descriptor) variant. *)externalto_handle:t->int="ml_g_variant_get_handle"(** Get the handle value. Raises Failure if the variant is not a handle. *)(** {2 Variant (Boxed Value)} *)externalof_variant:t->t="ml_g_variant_new_variant"(** Create a variant containing another variant (type 'v'). *)externalto_variant:t->t="ml_g_variant_get_variant"(** Unwrap a variant inside a variant. Raises Failure if the variant is not a
variant type. *)(** {2 Maybe (Nullable)} *)externalof_maybe:Gvariant_type.t->toption->t="ml_g_variant_new_maybe"(** Create a maybe type variant. [of_maybe ty None] creates a null variant,
[of_maybe ty (Some v)] wraps the value. *)externalto_maybe:t->toption="ml_g_variant_get_maybe"(** Unwrap a maybe type variant. Returns [None] for null, [Some v] for wrapped
value. Raises Failure if the variant is not a maybe type. *)(** {2 Arrays} *)externalof_string_array:stringarray->t="ml_g_variant_new_strv"(** Create a string array variant. *)externalto_string_array:t->stringarray="ml_g_variant_get_strv"(** Get the string array value. Raises Failure if the variant is not a string
array. *)externalof_object_path_array:stringarray->t="ml_g_variant_new_objv"(** Create an object path array variant. *)externalto_object_path_array:t->stringarray="ml_g_variant_get_objv"(** Get the object path array value. Raises Failure if the variant is not an
object path array. *)(** {2 Dictionary Lookups (a{sv} pattern)}
These functions look up values in a{sv} (string->variant) dictionaries.
They return [None] if the key is not found or if the value is not of the expected type.
For dictionaries with different value types, use [get_child_value] with the appropriate index.
*)externallookup_string:t->string->stringoption="ml_g_variant_lookup_string"(** Lookup a string value in a dictionary. Returns [None] if the key is not
found or the value is not a string. *)externallookup_int32:t->string->int32option="ml_g_variant_lookup_int32"(** Lookup an int32 value in a dictionary. Returns [None] if the key is not
found or the value is not an int32. *)externallookup_boolean:t->string->booloption="ml_g_variant_lookup_boolean"(** Lookup a boolean value in a dictionary. Returns [None] if the key is not
found or the value is not a boolean. *)externallookup_byte:t->string->intoption="ml_g_variant_lookup_byte"(** Lookup a byte (uint8) value in a dictionary. Returns [None] if the key is
not found or the value is not a byte. *)externallookup_int16:t->string->intoption="ml_g_variant_lookup_int16"(** Lookup an int16 value in a dictionary. Returns [None] if the key is not
found or the value is not an int16. *)externallookup_uint16:t->string->intoption="ml_g_variant_lookup_uint16"(** Lookup a uint16 value in a dictionary. Returns [None] if the key is not
found or the value is not a uint16. *)externallookup_uint32:t->string->uint32option="ml_g_variant_lookup_uint32"(** Lookup a uint32 value in a dictionary. Returns [None] if the key is not
found or the value is not a uint32. *)externallookup_int64:t->string->int64option="ml_g_variant_lookup_int64"(** Lookup an int64 value in a dictionary. Returns [None] if the key is not
found or the value is not an int64. *)externallookup_uint64:t->string->uint64option="ml_g_variant_lookup_uint64"(** Lookup a uint64 value in a dictionary. Returns [None] if the key is not
found or the value is not a uint64. *)externallookup_double:t->string->floatoption="ml_g_variant_lookup_double"(** Lookup a double value in a dictionary. Returns [None] if the key is not
found or the value is not a double. *)externallookup_object_path:t->string->stringoption="ml_g_variant_lookup_object_path"(** Lookup an object path value in a dictionary. Returns [None] if the key is
not found or the value is not an object path. *)externallookup_signature:t->string->stringoption="ml_g_variant_lookup_signature"(** Lookup a signature value in a dictionary. Returns [None] if the key is not
found or the value is not a signature. *)externallookup_handle:t->string->intoption="ml_g_variant_lookup_handle"(** Lookup a handle (file descriptor) value in a dictionary. Returns [None] if
the key is not found or the value is not a handle. *)(** {2 Child Access} *)externaln_children:t->int="ml_g_variant_n_children"(** Get the number of children in a tuple, array, or dictionary *)externalget_child_value:t->int->t="ml_g_variant_get_child_value"(** Get the nth child value. The returned value is a new reference and must be
unreferenced by the caller (handled by GC). *)(** {2 Serialization} *)externalprint:t->bool->string="ml_g_variant_print"(** Print the variant in GVariant text format. First arg is the variant, second
is whether to annotate types. *)externalparse:string->t="ml_g_variant_parse"(** Parse a GVariant from its text format representation. Raises Failure on
parse error. *)