Implementation of a simple list.
More...
Go to the source code of this file.
|
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.
|
|
Implementation of a simple list.
This object does NOT support RAVE_OBJECT_CLONE.
- Author
- Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
- Date
- 2009-11-20
◆ RaveList_t
◆ RaveList_add()
Add one instance to the list.
- Parameters
-
[in] | list | - the list |
[in] | ob | - the object |
- Returns
- 1 on success, otherwise 0
◆ RaveList_find()
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.
- Parameters
-
[in] | list | - the list |
[in] | expected | - the expected data value |
[in] | findfunc | - the finder function that takes expected value and data value as arguments. |
- Returns
- the found item or NULL if none was found.
◆ RaveList_freeAndDestroy()
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/...
- Parameters
-
[in,out] | list | - self, when leaving this function, *list will be NULL. |
◆ RaveList_get()
void * RaveList_get |
( |
RaveList_t * | list, |
|
|
int | index ) |
Returns the item at the specified position.
- Parameters
-
[in] | list | - the list |
[in] | index | - the index of the requested item |
- Returns
- the object
◆ RaveList_getLast()
Returns the item at the end.
- Parameters
-
- Returns
- the object
◆ RaveList_insert()
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.
- Parameters
-
[in] | list | - the list |
[in] | index | - the index where to insert the object |
[in] | ob | - the object to insert. |
◆ RaveList_remove()
void * RaveList_remove |
( |
RaveList_t * | list, |
|
|
int | index ) |
Removes the item at the specified position and returns it.
- Parameters
-
[in] | list | - the list |
[in] | index | - the index of the requested item |
- Returns
- the object
◆ RaveList_removeLast()
Removes the last item.
- Parameters
-
- Returns
- the object or NULL if there are no objects
◆ RaveList_removeObject()
void RaveList_removeObject |
( |
RaveList_t * | list, |
|
|
void * | object ) |
Removes the object that is equal to the provided object.
I.e. pointer comparission is made.
- Parameters
-
[in] | list | - the list |
[in] | object | - the object to remove |
◆ RaveList_size()
Returns the number of items in this list.
- Parameters
-
- Returns
- the number of items in this list.
◆ RaveList_sort()
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.
- Parameters
-
[in] | list | - the list |
[in] | sortfun | - the sorting function. |
◆ RaveList_TYPE
Type definition to use when creating a rave object.