ValueArray

Deprecated since version 2.32: Use GArray instead, if possible for the given use case, as described above.

class ValueArray(*args, **kwargs)

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 unset as the clear function using set_clear_func, for instance, the following code:

GValueArray *array = g_value_array_new (10);

can be replaced by:

GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 10);
g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);

Constructors

class ValueArray
classmethod new(n_prealloced: int) ValueArray

Allocate and initialize a new ValueArray, optionally preserve space for n_prealloced elements. New arrays always contain 0 elements, regardless of the value of n_prealloced.

Deprecated since version 2.32: Use GArray and sized_new() instead.

Parameters:

n_prealloced – number of values to preallocate space for

Methods

class ValueArray
append(value: Any | None = None) ValueArray

Insert a copy of value as last element of value_array. If value is None, an uninitialized value is appended.

Deprecated since version 2.32: Use GArray and array_append_val() instead.

Parameters:

valueValue to copy into ValueArray, or None

get_nth(index_: int) Any

Return a pointer to the value at @``index_`` containd in value_array.

Deprecated since version 2.32: Use array_index() instead.

Parameters:

index – index of the value of interest

insert(index_: int, value: Any | None = None) ValueArray

Insert a copy of value at specified position into value_array. If value is None, an uninitialized value is inserted.

Deprecated since version 2.32: Use GArray and array_insert_val() instead.

Parameters:
  • index – insertion position, must be <= value_array->;n_values

  • valueValue to copy into ValueArray, or None

prepend(value: Any | None = None) ValueArray

Insert a copy of value as first element of value_array. If value is None, an uninitialized value is prepended.

Deprecated since version 2.32: Use GArray and array_prepend_val() instead.

Parameters:

valueValue to copy into ValueArray, or None

remove(index_: int) ValueArray

Remove the value at position @``index_`` from value_array.

Deprecated since version 2.32: Use GArray and remove_index() instead.

Parameters:

index – position of value to remove, which must be less than value_array->n_values

sort(compare_func: Callable[[...], int], *user_data: Any) ValueArray

Sort value_array using compare_func to compare the elements according to the semantics of CompareFunc.

The current implementation uses the same sorting algorithm as standard C qsort() function.

Deprecated since version 2.32: Use GArray and sort().

Parameters:
  • compare_func – function to compare elements

  • user_data

Fields

class ValueArray
n_prealloced
n_values

Number of values contained in the array

values

Array of values