Interface

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 Documentation

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.


Enumeration Type Documentation

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.


Function Documentation

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.

Parameters:
[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.
Returns:
0 - Success.
ENOMEM - No memory.
EINVAL - Invalid argument.
int ref_array_create ( struct ref_array **  ra,
size_t  elem,
uint32_t  grow_by,
ref_array_fn  cb,
void *  data 
)

Create referenced array.

Parameters:
[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.
Returns:
0 - Success.
ENOMEM - No memory.
EINVAL - Invalid argument.
void ref_array_destroy ( struct ref_array *  ra  ) 

Delete the array.

Parameters:
[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.

Parameters:
[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.
Returns:
Pointer to the data stored in the element. Conventionally it should be a const pointer, however such declaration would make using variable that receives the result of this function immutable. This is very inconvenient because such variable should be able to point to data related to multiple elements of the array.
Pointer to the element's data.
NULL if index is out of range.
int ref_array_getlen ( struct ref_array *  ra,
uint32_t *  len 
)

Get array length.

Determines length of the array.

Parameters:
[in] ra Existing array object.
[out] len Variable will receive the length of the array.
Returns:
0 - Success.
EINVAL - Invalid argument.
struct ref_array* ref_array_getref ( struct ref_array *  ra  )  [read]

Get new reference to an array.

Parameters:
[in] ra Existing array object.
Returns:
A new reference to an array object.
NULL - Invalid argument.
uint32_t ref_array_len ( struct ref_array *  ra  ) 

Array length.

Alternative function to get length.

Parameters:
[in] ra Existing array object.
Returns:
Length of the array. Returns 0 if the array is invalid.

Generated on 16 Dec 2010 for libref_array by  doxygen 1.6.1