RAVE
rave_list.h File Reference

Implementation of a simple list. More...

#include "rave_object.h"

Go to the source code of this file.

Typedefs

typedef struct _RaveList_t RaveList_t
 Defines a list.
 

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.
 

Detailed Description

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

Typedef Documentation

◆ RaveList_t

typedef struct _RaveList_t RaveList_t

Defines a list.

Function Documentation

◆ RaveList_add()

int RaveList_add ( RaveList_t * list,
void * ob )

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()

void * RaveList_getLast ( RaveList_t * list)

Returns the item at the end.

Parameters
[in]list- the list
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()

void * RaveList_removeLast ( RaveList_t * list)

Removes the last item.

Parameters
[in]list- the list
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()

int RaveList_size ( RaveList_t * list)

Returns the number of items in this list.

Parameters
[in]list- the list
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.

Variable Documentation

◆ RaveList_TYPE

RaveCoreObjectType RaveList_TYPE
extern

Type definition to use when creating a rave object.