:right-sidebar: True ValueArray =================================================================== .. currentmodule:: gi.repository.GObject .. deprecated:: 2.32 Use ``GArray`` instead, if possible for the given use case, as described above. .. class:: ValueArray(*args, **kwargs) :no-contents-entry: A ``GValueArray`` is a container structure to hold an array of generic values. The prime purpose of a ``GValueArray`` is for it to be used as an object property that holds an array of values. A ``GValueArray`` wraps an array of ``GValue`` elements in order for it to be used as a boxed type through ``G_TYPE_VALUE_ARRAY``\. ``GValueArray`` is deprecated in favour of ``GArray`` since GLib 2.32. It is possible to create a ``GArray`` that behaves like a ``GValueArray`` by using the size of ``GValue`` as the element size, and by setting :obj:`~gi.repository.GObject.Value.unset` as the clear function using :obj:`~gi.repository.GLib.Array.set_clear_func`\, for instance, the following code: .. code-block:: c :dedent: GValueArray *array = g_value_array_new (10); can be replaced by: .. code-block:: c :dedent: GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 10); g_array_set_clear_func (array, (GDestroyNotify) g_value_unset); Constructors ------------ .. rst-class:: interim-class .. class:: ValueArray :no-index: .. classmethod:: new(n_prealloced: int) -> ~gi.repository.GObject.ValueArray Allocate and initialize a new :obj:`~gi.repository.GObject.ValueArray`\, optionally preserve space for ``n_prealloced`` elements. New arrays always contain 0 elements, regardless of the value of ``n_prealloced``\. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.Array.sized_new` instead. :param n_prealloced: number of values to preallocate space for Methods ------- .. rst-class:: interim-class .. class:: ValueArray :no-index: .. method:: append(value: ~gi.repository.GObject.Value | None = None) -> ~gi.repository.GObject.ValueArray Insert a copy of ``value`` as last element of ``value_array``\. If ``value`` is :const:`None`, an uninitialized value is appended. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.array_append_val` instead. :param value: :obj:`~gi.repository.GObject.Value` to copy into :obj:`~gi.repository.GObject.ValueArray`\, or :const:`None` .. method:: get_nth(index_: int) -> ~gi.repository.GObject.Value Return a pointer to the value at ``index_`` contained in ``value_array``\. .. deprecated:: 2.32 Use :func:`~gi.repository.GLib.array_index` instead. :param index_: index of the value of interest .. method:: insert(index_: int, value: ~gi.repository.GObject.Value | None = None) -> ~gi.repository.GObject.ValueArray Insert a copy of ``value`` at specified position into ``value_array``\. If ``value`` is :const:`None`, an uninitialized value is inserted. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.array_insert_val` instead. :param index_: insertion position, must be <= value_array->;n_values :param value: :obj:`~gi.repository.GObject.Value` to copy into :obj:`~gi.repository.GObject.ValueArray`\, or :const:`None` .. method:: prepend(value: ~gi.repository.GObject.Value | None = None) -> ~gi.repository.GObject.ValueArray Insert a copy of ``value`` as first element of ``value_array``\. If ``value`` is :const:`None`, an uninitialized value is prepended. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.array_prepend_val` instead. :param value: :obj:`~gi.repository.GObject.Value` to copy into :obj:`~gi.repository.GObject.ValueArray`\, or :const:`None` .. method:: remove(index_: int) -> ~gi.repository.GObject.ValueArray Remove the value at position ``index_`` from ``value_array``\. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.Array.remove_index` instead. :param index_: position of value to remove, which must be less than ``value_array``\->n_values .. method:: sort(compare_func: ~typing.Callable[[~typing.Any, ~typing.Any, ~typing.Any], int], user_data: ~typing.Any = None) -> ~gi.repository.GObject.ValueArray Sort ``value_array`` using ``compare_func`` to compare the elements according to the semantics of :obj:`~gi.repository.GLib.CompareFunc`\. The current implementation uses the same sorting algorithm as standard C qsort() function. .. deprecated:: 2.32 Use ``GArray`` and :func:`~gi.repository.GLib.Array.sort`. :param compare_func: function to compare elements :param user_data: Fields ------ .. rst-class:: interim-class .. class:: ValueArray :no-index: .. attribute:: n_prealloced .. attribute:: n_values Number of values contained in the array .. attribute:: values Array of values