Package ch.bailu.gtk.glib
Class Array
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Array
- All Implemented Interfaces:
PointerInterface
Contains the public fields of a GArray.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Array
_new
(boolean zero_terminated, boolean clear_, int element_size) Creates a new #GArray with a reference count of 1.static Array
appendVals
(Array array, Pointer data, int len) Adds @len elements onto the end of the array.static Array
Create a shallow copy of a #GArray.static Str
Frees the memory allocated for the #GArray.static ClassHandler
static int
getElementSize
(Array array) Gets the size of the elements in @array.a pointer to the element data.int
the number of elements in the #GArray not including the
possible terminating zero element.static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
static Array
insertVals
(Array array, int index_, Pointer data, int len) Inserts @len elements into a #GArray at the given index.static Array
prependVals
(Array array, Pointer data, int len) Adds @len elements onto the start of the array.static Array
Atomically increments the reference count of @array by one.static Array
removeIndex
(Array array, int index_) Removes the element at the given index from a #GArray.static Array
removeIndexFast
(Array array, int index_) Removes the element at the given index from a #GArray.static Array
removeRange
(Array array, int index_, int length) Removes the given number of elements starting at the given index
from a #GArray.static void
setClearFunc
(Array array, Array.OnDestroyNotify clear_func) Sets a function to clear an element of @array.void
setFieldData
(Str data) a pointer to the element data.void
setFieldLen
(int len) the number of elements in the #GArray not including the
possible terminating zero element.static Array
Sets the size of the array, expanding it if necessary.static Array
sizedNew
(boolean zero_terminated, boolean clear_, int element_size, int reserved_size) Creates a new #GArray with @reserved_size elements preallocated and
a reference count of 1.static void
sort
(Array array, Array.OnCompareFunc compare_func) Sorts a #GArray using @compare_func which should be a qsort()-style
comparison function (returns less than zero for first arg is less
than second arg, zero for equal, greater zero if first arg is
greater than second arg).static void
sortWithData
(Array array, Array.OnCompareDataFunc compare_func, Pointer user_data) Like g_array_sort(), but the comparison function receives an extra
user data argument.static Pointer
Frees the data in the array and resets the size to zero, while
the underlying array is preserved for use elsewhere and returned
to the caller.static void
Atomically decrements the reference count of @array by one.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
DATA
a pointer to the element data. The data may be moved as
elements are added to the #GArray.- See Also:
-
LEN
the number of elements in the #GArray not including the
possible terminating zero element.- See Also:
-
-
Constructor Details
-
Array
-
Array
public Array()
-
-
Method Details
-
getClassHandler
-
setFieldData
a pointer to the element data. The data may be moved as
elements are added to the #GArray. -
getFieldData
a pointer to the element data. The data may be moved as
elements are added to the #GArray. -
setFieldLen
public void setFieldLen(int len) the number of elements in the #GArray not including the
possible terminating zero element. -
getFieldLen
public int getFieldLen()the number of elements in the #GArray not including the
possible terminating zero element. -
appendVals
Adds @len elements onto the end of the array.- Parameters:
array
- a #GArraydata
- a pointer to the elements to append to the end of the arraylen
- the number of elements to append- Returns:
- the #GArray
-
copy
Create a shallow copy of a #GArray. If the array elements consist of
pointers to data, the pointers are copied but the actual data is not.- Parameters:
array
- A #GArray.- Returns:
- A copy of @array.
-
free
Frees the memory allocated for the #GArray. If @free_segment is
%TRUE it frees the memory block holding the elements as well. Pass
%FALSE if you want to free the #GArray wrapper but preserve the
underlying array for use elsewhere. If the reference count of
@array is greater than one, the #GArray wrapper is preserved but
the size of @array will be set to zero.
If array contents point to dynamically-allocated memory, they should
be freed separately if @free_seg is %TRUE and no @clear_func
function has been set for @array.
This function is not thread-safe. If using a #GArray from multiple
threads, use only the atomic g_array_ref() and g_array_unref()
functions.- Parameters:
array
- a #GArrayfree_segment
- if %TRUE the actual element data is freed as well- Returns:
- the element data if @free_segment is %FALSE, otherwise %NULL. The element data should be freed using g_free().
-
getElementSize
Gets the size of the elements in @array.- Parameters:
array
- A #GArray- Returns:
- Size of each element, in bytes
-
insertVals
Inserts @len elements into a #GArray at the given index.
If @index_ is greater than the array’s current length, the array is expanded.
The elements between the old end of the array and the newly inserted elements
will be initialised to zero if the array was configured to clear elements;
otherwise their values will be undefined.
If @index_ is less than the array’s current length, new entries will be
inserted into the array, and the existing entries above @index_ will be moved
upwards.
@data may be %NULL if (and only if) @len is zero. If @len is zero, this
function is a no-op.- Parameters:
array
- a #GArrayindex_
- the index to place the elements atdata
- a pointer to the elements to insertlen
- the number of elements to insert- Returns:
- the #GArray
-
_new
Creates a new #GArray with a reference count of 1.- Parameters:
zero_terminated
- %TRUE if the array should have an extra element at the end which is set to 0clear_
- %TRUE if #GArray elements should be automatically cleared to 0 when they are allocatedelement_size
- the size of each element in bytes- Returns:
- the new #GArray
-
prependVals
Adds @len elements onto the start of the array.
@data may be %NULL if (and only if) @len is zero. If @len is zero, this
function is a no-op.
This operation is slower than g_array_append_vals() since the
existing elements in the array have to be moved to make space for
the new elements.- Parameters:
array
- a #GArraydata
- a pointer to the elements to prepend to the start of the arraylen
- the number of elements to prepend, which may be zero- Returns:
- the #GArray
-
ref
Atomically increments the reference count of @array by one.
This function is thread-safe and may be called from any thread.- Parameters:
array
- A #GArray- Returns:
- The passed in #GArray
-
removeIndex
Removes the element at the given index from a #GArray. The following
elements are moved down one place.- Parameters:
array
- a #GArrayindex_
- the index of the element to remove- Returns:
- the #GArray
-
removeIndexFast
Removes the element at the given index from a #GArray. The last
element in the array is used to fill in the space, so this function
does not preserve the order of the #GArray. But it is faster than
g_array_remove_index().- Parameters:
array
- a @GArrayindex_
- the index of the element to remove- Returns:
- the #GArray
-
removeRange
Removes the given number of elements starting at the given index
from a #GArray. The following elements are moved to close the gap.- Parameters:
array
- a @GArrayindex_
- the index of the first element to removelength
- the number of elements to remove- Returns:
- the #GArray
-
setClearFunc
Sets a function to clear an element of @array.
The @clear_func will be called when an element in the array
data segment is removed and when the array is freed and data
segment is deallocated as well. @clear_func will be passed a
pointer to the element to clear, rather than the element itself.
Note that in contrast with other uses of #GDestroyNotify
functions, @clear_func is expected to clear the contents of
the array element it is given, but not free the element itself.
<!-- language="C" --> typedef struct { gchar *str; GObject *obj; } ArrayElement; static void array_element_clear (ArrayElement *element) { g_clear_pointer (&element->str, g_free); g_clear_object (&element->obj); } // main code GArray *garray = g_array_new (FALSE, FALSE, sizeof (ArrayElement)); g_array_set_clear_func (garray, (GDestroyNotify) array_element_clear); // assign data to the structure g_array_free (garray, TRUE);
- Parameters:
array
- A #GArrayclear_func
- a function to clear an element of @array
-
setSize
Sets the size of the array, expanding it if necessary. If the array
was created with @clear_ set to %TRUE, the new elements are set to 0.- Parameters:
array
- a #GArraylength
- the new size of the #GArray- Returns:
- the #GArray
-
sizedNew
public static Array sizedNew(boolean zero_terminated, boolean clear_, int element_size, int reserved_size) Creates a new #GArray with @reserved_size elements preallocated and
a reference count of 1. This avoids frequent reallocation, if you
are going to add many elements to the array. Note however that the
size of the array is still 0.- Parameters:
zero_terminated
- %TRUE if the array should have an extra element at the end with all bits clearedclear_
- %TRUE if all bits in the array should be cleared to 0 on allocationelement_size
- size of each element in the arrayreserved_size
- number of elements preallocated- Returns:
- the new #GArray
-
sort
Sorts a #GArray using @compare_func which should be a qsort()-style
comparison function (returns less than zero for first arg is less
than second arg, zero for equal, greater zero if first arg is
greater than second arg).
This is guaranteed to be a stable sort since version 2.32.- Parameters:
array
- a #GArraycompare_func
- comparison function
-
sortWithData
public static void sortWithData(@Nonnull Array array, Array.OnCompareDataFunc compare_func, @Nullable Pointer user_data) Like g_array_sort(), but the comparison function receives an extra
user data argument.
This is guaranteed to be a stable sort since version 2.32.
There used to be a comment here about making the sort stable by
using the addresses of the elements in the comparison function.
This did not actually work, so any such code should be removed.- Parameters:
array
- a #GArraycompare_func
- comparison functionuser_data
- data to pass to @compare_func
-
steal
Frees the data in the array and resets the size to zero, while
the underlying array is preserved for use elsewhere and returned
to the caller.
If the array was created with the @zero_terminate property
set to %TRUE, the returned data is zero terminated too.
If array elements contain dynamically-allocated memory,
the array elements should also be freed by the caller.
A short example of use:<!-- language="C" --> ... gpointer data; gsize data_len; data = g_array_steal (some_array, &data_len); ...
- Parameters:
array
- a #GArray.len
- pointer to retrieve the number of elements of the original array- Returns:
- the element data, which should be freed using g_free().
-
unref
Atomically decrements the reference count of @array by one. If the
reference count drops to 0, all memory allocated by the array is
released. This function is thread-safe and may be called from any
thread.- Parameters:
array
- A #GArray
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-