Skip to content

GObject.ValueArray

record (struct)

:::warning Deprecated since 2.32 This API is deprecated. :::

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 Value.unset as the clear function using GLib.Array.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

new

@classmethod
def new(cls, n_prealloced: int) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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.

Parameters:

  • n_prealloced — number of values to preallocate space for

Methods

append

def append(self, value: Value | None = ...) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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

Parameters:

copy

def copy(self) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

Construct an exact copy of a ValueArray by duplicating all its contents.

get_nth

def get_nth(self, index_: int) -> Value

:::warning Deprecated since 2.32 This API is deprecated. :::

Return a pointer to the value at index_ contained in value_array.

Parameters:

  • index_ — index of the value of interest

insert

def insert(self, index_: int, value: Value | None = ...) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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

Parameters:

  • index_ — insertion position, must be <= value_array->;n_values
  • valueValue to copy into ValueArray, or None

prepend

def prepend(self, value: Value | None = ...) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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

Parameters:

remove

def remove(self, index_: int) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

Remove the value at position index_ from value_array.

Parameters:

  • index_ — position of value to remove, which must be less than value_array->n_values

sort

def sort(self, compare_func: GLib.CompareFunc) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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

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

Parameters:

  • compare_func — function to compare elements

sort_with_data

def sort_with_data(self, compare_func: GLib.CompareDataFunc) -> ValueArray

:::warning Deprecated since 2.32 This API is deprecated. :::

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

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

Parameters:

  • compare_func — function to compare elements

Properties

n_values

n_values: int  # read/write

values

values: Value  # read/write

n_prealloced

n_prealloced: int  # read/write