18#ifndef __R_PTR_ARRAY_H__
19#define __R_PTR_ARRAY_H__
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
56#define R_PTR_ARRAY_INVALID_IDX RSIZE_MAX
65#define R_PTR_ARRAY_INIT { R_REF_STATIC_INIT (NULL), 0, 0, NULL }
72#define r_ptr_array_new() r_ptr_array_new_sized (0)
76#define r_ptr_array_ref r_ref_ref
78#define r_ptr_array_unref r_ref_unref
81#define r_ptr_array_size(array) (array)->nsize
83#define r_ptr_array_alloc_size(array) (array)->nalloc
96#define r_ptr_array_find(array, data) r_ptr_array_find_range (array, data, 0, -1)
139#define r_ptr_array_clear_idx(array, idx) r_ptr_array_update_idx (array, idx, NULL, NULL)
162#define r_ptr_array_remove_all(array) r_ptr_array_remove_range_clear_full (array, 0, -1, NULL, NULL)
164#define r_ptr_array_remove_all_full(array, func, user) r_ptr_array_remove_range_clear_full (array, 0, -1, func, user)
167#define r_ptr_array_remove_idx(array, idx) r_ptr_array_remove_idx_full (array, idx, NULL, NULL)
169#define r_ptr_array_remove_idx_fast(array, idx) r_ptr_array_remove_idx_fast_full (array, idx, NULL, NULL)
171#define r_ptr_array_remove_idx_clear(array, idx) r_ptr_array_remove_idx_clear_full (array, idx, NULL, NULL)
183#define r_ptr_array_remove_first_full(array, data, func, user) r_ptr_array_remove_idx_full (array, r_ptr_array_find (array, data), func, user)
185#define r_ptr_array_remove_first_fast_full(array, data, func, user) r_ptr_array_remove_idx_fast_full (array, r_ptr_array_find (array, data), func, user)
187#define r_ptr_array_remove_first_clear_full(array, data, func, user) r_ptr_array_remove_idx_clear_full (array, r_ptr_array_find (array, data), func, user)
189#define r_ptr_array_remove_first(array, data) r_ptr_array_remove_first_full (array, data, NULL, NULL)
191#define r_ptr_array_remove_first_fast(array, data) r_ptr_array_remove_first_fast_full (array, data, NULL, NULL)
193#define r_ptr_array_remove_first_clear(array, data) r_ptr_array_remove_first_clear_full (array, data, NULL, NULL)
196#define r_ptr_array_remove_range(array, idx, inc) r_ptr_array_remove_range_full (array, idx, inc, NULL, NULL)
198#define r_ptr_array_remove_range_fast(array, idx, inc) r_ptr_array_remove_range_fast_full (array, idx, inc, NULL, NULL)
200#define r_ptr_array_remove_range_clear(array, idx, inc) r_ptr_array_remove_range_clear_full (array, idx, inc, NULL, NULL)
217#define r_ptr_array_foreach(array, func, user) r_ptr_array_foreach_range (array, 0, -1, func, user)
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
rsize r_ptr_array_remove_idx_full(RPtrArray *array, rsize idx, RFunc func, rpointer user)
Stable remove of slot idx; func runs on the displaced item.
rsize r_ptr_array_foreach_range(RPtrArray *array, rsize idx, rssize size, RFunc func, rpointer user)
Invoke func on each item in the range [idx, idx+size).
rsize r_ptr_array_update_idx(RPtrArray *array, rsize idx, rpointer data, RDestroyNotify notify)
Overwrite the slot at idx.
rsize r_ptr_array_remove_idx_fast_full(RPtrArray *array, rsize idx, RFunc func, rpointer user)
Swap-with-last remove of slot idx; func runs on the displaced item.
rsize r_ptr_array_remove_range_fast_full(RPtrArray *array, rsize idx, rssize size, RFunc func, rpointer user)
Swap-with-last range remove with per-item function.
rsize r_ptr_array_clear_range(RPtrArray *array, rsize idx, rssize size)
Write NULL into every slot in the range; previous values run through their destroy notifiers.
rpointer r_ptr_array_get(RPtrArray *array, rsize idx)
Return the pointer stored at idx.
rsize r_ptr_array_remove_range_clear_full(RPtrArray *array, rsize idx, rssize size, RFunc func, rpointer user)
Clear-in-place over the range with per-item function.
void r_ptr_array_init(RPtrArray *array)
Initialise an embedded / stack RPtrArray to empty.
void r_ptr_array_sort(RPtrArray *array, RCmpFunc cmp)
In-place sort using comparator cmp.
rconstpointer r_ptr_array_get_const(const RPtrArray *array, rsize idx)
Const-correct variant of r_ptr_array_get.
rsize r_ptr_array_remove_range_full(RPtrArray *array, rsize idx, rssize size, RFunc func, rpointer user)
Stable range remove with per-item function.
rsize r_ptr_array_remove_idx_clear_full(RPtrArray *array, rsize idx, RFunc func, rpointer user)
Clear-in-place at slot idx; func runs on the displaced item.
RPtrArray * r_ptr_array_new_sized(rsize size)
Heap-allocate an array with a preset initial capacity.
rsize r_ptr_array_add(RPtrArray *array, rpointer data, RDestroyNotify notify)
Append data to the array.
rsize r_ptr_array_insert(RPtrArray *array, rsize idx, rpointer data, RDestroyNotify notify)
Insert data at idx, shifting later items up by one.
rsize r_ptr_array_find_range(RPtrArray *array, rpointer data, rsize idx, rssize size)
Find first occurrence of data within the range starting at idx for size items.
void r_ptr_array_clear(RPtrArray *array)
Drop every item and release backing storage; destroy notifiers run.
void(* RFunc)(rpointer data, rpointer user)
Generic iteration callback over (data, user) pairs.
Definition rtypes.h:403
int(* RCmpFunc)(rconstpointer a, rconstpointer b)
Comparison callback returning <0 / 0 / >0 for a vs b.
Definition rtypes.h:405
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
const void * rconstpointer
Generic const pointer (alias for const void *).
Definition rtypes.h:329
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
signed long rssize
Signed pointer-sized size type (like ssize_t).
Definition rtypes.h:291
Refcount base struct shared by every refcounted type in rlib.
Foundational type aliases used by every rlib header.
Public definition of RPtrArray.
Definition rptrarray.h:234
rsize nalloc
Definition rptrarray.h:237
rpointer mem
Definition rptrarray.h:239
RRef ref
Definition rptrarray.h:235
rsize nsize
Definition rptrarray.h:238
Refcount base struct.
Definition rref.h:58