RAVE
raveobject_list.c File Reference

Implementation of a rave object list that ensures that the objects contained within the list are released upon destruction etc. More...

#include "rave_list.h"
#include "raveobject_list.h"
#include "rave_debug.h"
#include "rave_alloc.h"
#include <string.h>
#include <stdio.h>

Classes

struct  _RaveObjectList_t
 Represents a list. More...
 

Functions

int RaveObjectList_add (RaveObjectList_t *list, RaveCoreObject *obj)
 Add one instance to the list.
 
int RaveObjectList_insert (RaveObjectList_t *list, int index, RaveCoreObject *obj)
 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 RaveObjectList_size (RaveObjectList_t *list)
 Returns the number of items in this list.
 
RaveCoreObjectRaveObjectList_get (RaveObjectList_t *list, int index)
 Returns the item at the specified position.
 
RaveCoreObjectRaveObjectList_getLast (RaveObjectList_t *list)
 Returns the item at the end.
 
RaveCoreObjectRaveObjectList_remove (RaveObjectList_t *list, int index)
 Removes the item at the specified position and returns it.
 
void RaveObjectList_release (RaveObjectList_t *list, int index)
 Removes the item at the specified position and releases it.
 
void RaveObjectList_clear (RaveObjectList_t *list)
 Removes all entries from the list.
 
RaveCoreObjectRaveObjectList_removeLast (RaveObjectList_t *list)
 Removes the last item.
 
void RaveObjectList_sort (RaveObjectList_t *list, int(*sortfun)(const void *, const void *))
 Sorts the list according to the provided sort function.
 
int RaveObjectList_indexOf (RaveObjectList_t *list, RaveCoreObject *obj)
 Locates the object at returns the index in the list.
 

Variables

RaveCoreObjectType RaveObjectList_TYPE
 Type definition to use when creating a rave object.
 

Detailed Description

Implementation of a rave object list that ensures that the objects contained within the list are released upon destruction etc.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2009-11-26

Function Documentation

◆ RaveObjectList_add()

int RaveObjectList_add ( RaveObjectList_t * list,
RaveCoreObject * obj )

Add one instance to the list.

Parameters
[in]list- the list
[in]obj- the object
Returns
1 on success, otherwise 0

◆ RaveObjectList_clear()

void RaveObjectList_clear ( RaveObjectList_t * list)

Removes all entries from the list.

Parameters
[in]list- the list

◆ RaveObjectList_get()

RaveCoreObject * RaveObjectList_get ( RaveObjectList_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

◆ RaveObjectList_getLast()

RaveCoreObject * RaveObjectList_getLast ( RaveObjectList_t * list)

Returns the item at the end.

Parameters
[in]list- the list
Returns
the object

◆ RaveObjectList_indexOf()

int RaveObjectList_indexOf ( RaveObjectList_t * list,
RaveCoreObject * obj )

Locates the object at returns the index in the list.

The comparision is based on addresses.

Parameters
[in]list- the list @obj[in] the object to find
Returns
the index if found, otherwise -1

◆ RaveObjectList_insert()

int RaveObjectList_insert ( RaveObjectList_t * list,
int index,
RaveCoreObject * obj )

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]obj- the object to insert.

◆ RaveObjectList_release()

void RaveObjectList_release ( RaveObjectList_t * list,
int index )

Removes the item at the specified position and releases it.

Parameters
[in]list- the list
[in]index- the index of the requested item
Returns
the object

◆ RaveObjectList_remove()

RaveCoreObject * RaveObjectList_remove ( RaveObjectList_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

◆ RaveObjectList_removeLast()

RaveCoreObject * RaveObjectList_removeLast ( RaveObjectList_t * list)

Removes the last item.

Parameters
[in]list- the list
Returns
the object or NULL if there are no objects

◆ RaveObjectList_size()

int RaveObjectList_size ( RaveObjectList_t * list)

Returns the number of items in this list.

Parameters
[in]list- the list
Returns
the number of items in this list.

◆ RaveObjectList_sort()

void RaveObjectList_sort ( RaveObjectList_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

◆ RaveObjectList_TYPE

RaveCoreObjectType RaveObjectList_TYPE
Initial value:
= {
"RaveObjectList",
RaveObjectList_constructor,
RaveObjectList_destructor,
RaveObjectList_copyconstructor
}
struct _RaveObjectList_t RaveObjectList_t
Defines a list.
Definition raveobject_list.h:38

Type definition to use when creating a rave object.