Typedefs | |
typedef void(* | ref_array_fn )(void *elem, ref_array_del_enum type, void *data) |
Element cleanup callback. | |
Enumerations | |
enum | ref_array_del_enum |
Enumeration of the delete modes. More... | |
Functions | |
int | ref_array_create (struct ref_array **ra, size_t elem, uint32_t grow_by, ref_array_fn cb, void *data) |
Create referenced array. | |
struct ref_array * | ref_array_getref (struct ref_array *ra) |
Get new reference to an array. | |
void | ref_array_destroy (struct ref_array *ra) |
Delete the array. | |
int | ref_array_append (struct ref_array *ra, void *element) |
Add new element to the array. | |
void * | ref_array_get (struct ref_array *ra, uint32_t idx, void *acptr) |
Get element data. | |
int | ref_array_getlen (struct ref_array *ra, uint32_t *len) |
Get array length. | |
uint32_t | ref_array_len (struct ref_array *ra) |
Array length. |
typedef void(* ref_array_fn)(void *elem, ref_array_del_enum type, void *data) |
Element cleanup callback.
Callback that can be provided by a caller to free data when the storage is actually destroyed.
enum ref_array_del_enum |
Enumeration of the delete modes.
When the array is destroyed each element of the array most likely needs to be freed. Same is true when an element is removed from the array. However the caller might need to do different things with the data depending on whether the array is destroyed or whether the element is removed. This enumeration defines constants that you used to indicate which operation was performed.
int ref_array_append | ( | struct ref_array * | ra, | |
void * | element | |||
) |
Add new element to the array.
Appends an element to the end of the array.
[in] | ra | Existing array object. |
[in] | element | Pointer to data. The number of bytes defined at the array creation as the array size will be copied into the array element. |
int ref_array_create | ( | struct ref_array ** | ra, | |
size_t | elem, | |||
uint32_t | grow_by, | |||
ref_array_fn | cb, | |||
void * | data | |||
) |
Create referenced array.
[out] | ra | Newly created array object. |
[in] | elem | Element size in bytes. |
[in] | grow_by | Defines how many elements should be allocated together as one chunk. |
[in] | cb | Cleanup callback. |
[in] | data | Caller supplied data passed to cleanup callback. |
void ref_array_destroy | ( | struct ref_array * | ra | ) |
Delete the array.
[in] | ra | Existing array object or a reference. |
void* ref_array_get | ( | struct ref_array * | ra, | |
uint32_t | idx, | |||
void * | acptr | |||
) |
Get element data.
Retrieves data from the array element.
[in] | ra | Existing array object. |
[in] | idx | Index of the array element. |
[in] | acptr | Pointer to the memory where the element's data will be copied. Can be NULL. In this case nothing is copied. |
int ref_array_getlen | ( | struct ref_array * | ra, | |
uint32_t * | len | |||
) |
Get array length.
Determines length of the array.
[in] | ra | Existing array object. |
[out] | len | Variable will receive the length of the array. |
struct ref_array* ref_array_getref | ( | struct ref_array * | ra | ) | [read] |
Get new reference to an array.
[in] | ra | Existing array object. |
uint32_t ref_array_len | ( | struct ref_array * | ra | ) |
Array length.
Alternative function to get length.
[in] | ra | Existing array object. |