An opaque structure used to hold different types of values.
Before it can be used, a `GValue` has to be initialized to a specific type by calling [method@GObject.Value.init] on it.
Many types which are stored within a `GValue` need to allocate data on the heap, so [method@GObject.Value.unset] must always be called on a
`GValue` to free any such data once you’re finished with the `GValue`, even if the `GValue` itself is stored on the stack.
The data within the structure has protected scope: it is accessible only to functions within a [struct@GObject.TypeValueTable] structure, or
implementations of the `g_value_*()` API. That is, code which implements new fundamental types.
`GValue` users cannot make any assumptions about how data is stored within the 2 element data union, and the g_type
member should only be accessed through the [func@GObject.VALUE_TYPE] macro and related macros.
Example: GLib.Value and strings:
public static int main (string[] args) {
Value value1 = Value (typeof (string));
value1.set_string ("My string");
// Output: ``My string``
print ("%s\n", value1.get_string ());
// Output: ``My string``
print ("%s\n", value1.dup_string ());
// Output: ``My string``
print ("%s\n", (string) value1);
// Output: ``My string 2``
value1 = "My string 2";
print ("%s\n", (string) value1);
return 0;
}
valac --pkg gobject-2.0 GLib.Value.vala
- public void copy (ref Value dest_value)
Copies the value of this into
dest_value.
- public void* dup_boxed ()
Get the contents of a g_type_boxed derived
Value.
- public Object? dup_object ()
Get the contents of a g_type_object
derived Value, increasing its reference count.
- public ParamSpec dup_param ()
Get the contents of a g_type_param
Value, increasing its reference count.
- public string? dup_string ()
Get a copy the contents of a g_type_string
Value.
- public Variant? dup_variant ()
Get the contents of a variant Value, increasing
its refcount.
- public bool fits_pointer ()
Determines if this will fit inside the
size of a pointer value.
- public bool get_boolean ()
Get the contents of a g_type_boolean
Value.
- public void* get_boxed ()
Get the contents of a g_type_boxed derived
Value.
- public char get_char ()
Do not use this function; it is broken on platforms where the
char type is unsigned, such as ARM and PowerPC.
- public double get_double ()
Get the contents of a g_type_double
Value.
- public int get_enum ()
Get the contents of a g_type_enum
Value.
- public uint get_flags ()
Get the contents of a g_type_flags
Value.
- public float get_float ()
Get the contents of a g_type_float
Value.
- public Type get_gtype ()
Get the contents of a g_type_gtype
Value.
- public int get_int ()
Get the contents of a g_type_int
Value.
- public int64 get_int64 ()
Get the contents of a g_type_int64
Value.
- public long get_long ()
Get the contents of a g_type_long
Value.
- public unowned Object? get_object ()
Get the contents of a g_type_object
derived Value.
- public unowned ParamSpec get_param ()
Get the contents of a g_type_param
Value.
- public void* get_pointer ()
Get the contents of a pointer Value.
- public int8 get_schar ()
Get the contents of a g_type_char
Value.
- public unowned string? get_string ()
Get the contents of a g_type_string
Value.
- public uchar get_uchar ()
Get the contents of a g_type_uchar
Value.
- public uint get_uint ()
Get the contents of a g_type_uint
Value.
- public uint64 get_uint64 ()
Get the contents of a g_type_uint64
Value.
- public ulong get_ulong ()
Get the contents of a g_type_ulong
Value.
- public unowned Variant? get_variant ()
Get the contents of a variant Value.
- public bool holds (Type type)
- public unowned Value? init (Type g_type)
- public void init_from_instance (void* instance)
Initializes and sets this from an
instantiatable type.
- public void* peek_pointer ()
Returns the value contents as a pointer.
- public unowned Value? reset ()
Clears the current value in this and
resets it to the initial value (as if the value had just been initialized using [method@GObject.
- public void set_boolean (bool v_boolean)
Set the contents of a g_type_boolean
Value to v_boolean.
- public void set_boxed (void* v_boxed)
Set the contents of a g_type_boxed derived
Value to v_boxed.
- public void set_char (char v_char)
Set the contents of a g_type_char
Value to v_char.
- public void set_double (double v_double)
Set the contents of a g_type_double
Value to v_double.
- public void set_enum (int v_enum)
Set the contents of a g_type_enum
Value to v_enum.
- public void set_flags (uint v_flags)
Set the contents of a g_type_flags
Value to v_flags.
- public void set_float (float v_float)
Set the contents of a g_type_float
Value to v_float.
- public void set_gtype (Type v_gtype)
Set the contents of a g_type_gtype
Value to v_gtype.
- public void set_instance (void* instance)
Sets this from an instantiatable type.
- public void set_int (int v_int)
Set the contents of a g_type_int
Value to v_int.
- public void set_int64 (int64 v_int64)
Set the contents of a g_type_int64
Value to v_int64.
- public void set_interned_string (string? v_string)
Set the contents of a g_type_string
Value to v_string.
- public void set_long (long v_long)
Set the contents of a g_type_long
Value to v_long.
- public void set_object (Object? v_object)
Set the contents of a g_type_object
derived Value to v_object.
- public void set_param (ParamSpec? param)
Set the contents of a g_type_param
Value to param.
- public void set_param_take_ownership (owned ParamSpec? param)
This is an internal function introduced mainly for C marshallers.
- public void set_pointer (void* v_pointer)
Set the contents of a pointer Value to
v_pointer.
- public void set_schar (int8 v_char)
Set the contents of a g_type_char
Value to v_char.
- public void set_static_string (string? v_string)
Set the contents of a g_type_string
Value to v_string.
- public void set_string (string? v_string)
Set the contents of a g_type_string
Value to a copy of v_string.
- public void set_uchar (uchar v_uchar)
Set the contents of a g_type_uchar
Value to v_uchar.
- public void set_uint (uint v_uint)
Set the contents of a g_type_uint
Value to v_uint.
- public void set_uint64 (uint64 v_uint64)
Set the contents of a g_type_uint64
Value to v_uint64.
- public void set_ulong (ulong v_ulong)
Set the contents of a g_type_ulong
Value to v_ulong.
- public void set_variant (Variant? variant)
Set the contents of a variant Value to
variant.
- public string? steal_string ()
Steal ownership on contents of a g_type_string
Value.
- public string strdup_contents ()
Return a newly allocated string, which describes the contents of a
Value.
- public void take_boxed (void* v_boxed)
Sets the contents of a g_type_boxed
derived Value to v_boxed and takes over the ownership of the caller’s reference to v_boxed
; the caller doesn’t have to unref it any more.
- public void take_object (owned Object? v_object)
Sets the contents of a g_type_object
derived Value to v_object and takes over the ownership of the caller’s reference to
v_object; the caller doesn’t have to unref it any more (i.
- public void take_param (owned ParamSpec? param)
Sets the contents of a g_type_param
Value to param and takes over the ownership of the caller’s reference to param; the
caller doesn’t have to unref it any more.
- public void take_string (owned string? v_string)
Sets the contents of a g_type_string
Value to v_string.
- public void take_variant (owned Variant? variant)
Set the contents of a variant Value to
variant, and takes over the ownership of the caller's reference to variant; the caller doesn't have to unref it any
more (i.
- public bool transform (ref Value dest_value)
Tries to cast the contents of this into a
type appropriate to store in dest_value.
- public Type type ()
- public unowned string type_name ()
- public void unset ()
Clears the current value in this (if any)
and ‘unsets’ the type.