RAVE
|
Implementation of a simple list. More...
Classes | |
struct | _RaveList_t |
Represents a list. More... | |
Macros | |
#define | LIST_EXPAND_NR_ENTRIES 20 |
Expand the list array with this number of entries / reallocation. | |
#define | DEFAULT_NR_RAVE_LIST_ENTRIES 20 |
Default number of list entries. | |
Functions | |
int | RaveList_add (RaveList_t *list, void *ob) |
Add one instance to the list. | |
int | RaveList_insert (RaveList_t *list, int index, void *ob) |
Inserts the object at the specified index, if index < 0 or index > size, then this function will add the object to the end of the list. | |
int | RaveList_size (RaveList_t *list) |
Returns the number of items in this list. | |
void * | RaveList_get (RaveList_t *list, int index) |
Returns the item at the specified position. | |
void * | RaveList_getLast (RaveList_t *list) |
Returns the item at the end. | |
void * | RaveList_remove (RaveList_t *list, int index) |
Removes the item at the specified position and returns it. | |
void * | RaveList_removeLast (RaveList_t *list) |
Removes the last item. | |
void | RaveList_removeObject (RaveList_t *list, void *object) |
Removes the object that is equal to the provided object. | |
void * | RaveList_find (RaveList_t *list, void *expected, int(*findfunc)(void *, void *)) |
Finds the object in the list. | |
void | RaveList_sort (RaveList_t *list, int(*sortfun)(const void *, const void *)) |
Sorts the list according to the provided sort function. | |
void | RaveList_freeAndDestroy (RaveList_t **list) |
This is a specialized version that can be used to destroy the list when it contains single pointers allocated with RAVE_MALLOC. | |
Variables | |
RaveCoreObjectType | RaveList_TYPE |
Type definition to use when creating a rave object. | |
Implementation of a simple list.
#define DEFAULT_NR_RAVE_LIST_ENTRIES 20 |
Default number of list entries.
#define LIST_EXPAND_NR_ENTRIES 20 |
Expand the list array with this number of entries / reallocation.
int RaveList_add | ( | RaveList_t * | list, |
void * | ob ) |
Add one instance to the list.
[in] | list | - the list |
[in] | ob | - the object |
void * RaveList_find | ( | RaveList_t * | list, |
void * | expected, | ||
int(* | findfunc )(void *, void *) ) |
Finds the object in the list.
If findfunc returns 1, then it is assumed to be a match and that object will be returned. The prototype for findfunc is int findfunc(void* expected, void* datavalue). where expected is passed to findfunc for each item (datavalue) in the list until a match is found.
[in] | list | - the list |
[in] | expected | - the expected data value |
[in] | findfunc | - the finder function that takes expected value and data value as arguments. |
void RaveList_freeAndDestroy | ( | RaveList_t ** | list | ) |
This is a specialized version that can be used to destroy the list when it contains single pointers allocated with RAVE_MALLOC.
For example char arrays and similar. NOTE! Before using this function, ensure that the list you are atempting to destroy really contains entries that has been allocated with RAVE_MALLOC/RAVE_STRDUP/...
[in,out] | list | - self, when leaving this function, *list will be NULL. |
void * RaveList_get | ( | RaveList_t * | list, |
int | index ) |
Returns the item at the specified position.
[in] | list | - the list |
[in] | index | - the index of the requested item |
void * RaveList_getLast | ( | RaveList_t * | list | ) |
Returns the item at the end.
[in] | list | - the list |
int RaveList_insert | ( | RaveList_t * | list, |
int | index, | ||
void * | ob ) |
Inserts the object at the specified index, if index < 0 or index > size, then this function will add the object to the end of the list.
[in] | list | - the list |
[in] | index | - the index where to insert the object |
[in] | ob | - the object to insert. |
void * RaveList_remove | ( | RaveList_t * | list, |
int | index ) |
Removes the item at the specified position and returns it.
[in] | list | - the list |
[in] | index | - the index of the requested item |
void * RaveList_removeLast | ( | RaveList_t * | list | ) |
Removes the last item.
[in] | list | - the list |
void RaveList_removeObject | ( | RaveList_t * | list, |
void * | object ) |
Removes the object that is equal to the provided object.
I.e. pointer comparission is made.
[in] | list | - the list |
[in] | object | - the object to remove |
int RaveList_size | ( | RaveList_t * | list | ) |
Returns the number of items in this list.
[in] | list | - the list |
void RaveList_sort | ( | RaveList_t * | list, |
int(* | sortfun )(const void *, const void *) ) |
Sorts the list according to the provided sort function.
The sort function should return an integer less than, equal to or greater than zero depending on how the first argument is in relation to the second argument.
[in] | list | - the list |
[in] | sortfun | - the sorting function. |
RaveCoreObjectType RaveList_TYPE |
Type definition to use when creating a rave object.