sphore 0.0.1
SPH openGL rendering engine

src/list.h File Reference

Code for generic lists. More...

#include "node.h"
#include "sphore.h"

Go to the source code of this file.

Typedefs

typedef struct _list list_t
 public access to the list data structure.
typedef struct _list_iterator list_iterator_t
 public access to the list iterator data structure.

Functions

list_tlist_create (void)
 Creates a new list.
void list_destroy (list_t *list)
 Cleans up the memory accosiated with a list object.
void list_destroy_data (list_t *list, void(*destroy_func)(void *))
 Cleans up the memory accosiated with a list object as well as the data contained at each node.
_SREnodeID list_add_first (list_t *list, void *data)
 Adds a new item to the start of the given list.
_SREnodeID list_add_last (list_t *list, void *data)
 Adds a new item to the end of the given list.
SREbool list_remove (list_t *list, _SREnodeID id)
 Removes a node from a list.
SREbool list_remove_data (list_t *list, _SREnodeID id, void(*destroy_func)(void *))
 Removes a node from a list, as well as freeing the associated data.
list_iterator_tlist_iterator_create (list_t *list)
 Creates a list_iterator_t.
void list_iterator_destroy (list_iterator_t *it)
 Cleans up the memory accosiated with a list_iterator_t.
_SREnodeID list_iterator_get_id (list_iterator_t *it)
 Gets the id of the node currently selected by the iterator.
void * list_iterator_get_data (list_iterator_t *it)
 Gets the data of the node currently selected by the iterator.
void list_iterator_remove (list_iterator_t *it)
 Removes the node currently selected by the iterator.
void list_iterator_remove_data (list_iterator_t *it, void(*destroy_func)(void *))
 Removes the node currently selected by the iterator, aswell as the data contained in te node.
_SREnodeID list_iterator_add (list_iterator_t *it, void *data)
 Adds a new node at the position of the iterator.
SREbool list_iterator_find (list_iterator_t *it, _SREnodeID id)
 Moves the iterator to the node containing id.
void list_iterator_reset (list_iterator_t *it)
 Resets the given iterator.
SREbool list_iterator_move (list_iterator_t *it)
 Moves the iterator one place through the list.
SREbool list_iterator_has_next (list_iterator_t *it)

Detailed Description

Code for generic lists.


Typedef Documentation

public access to the list iterator data structure.

Memory mamagment should be peformed with list_iterator_create and list_iterator_destroy. When ever a list is modified all associated iterators will be broken and should be reset or destoryed.

typedef struct _list list_t

public access to the list data structure.

Memory mamagment should be peformed with list_create and list_destroy


Function Documentation

_SREnodeID list_add_first ( list_t list,
void *  data 
)

Adds a new item to the start of the given list.

Parameters:
[in]listThe list to be added to.
[in]dataThe data for the new node.
Returns:
The identifier accoiated to the new node.
_SREnodeID list_add_last ( list_t list,
void *  data 
)

Adds a new item to the end of the given list.

Parameters:
[in]listThe list to be added to.
[in]dataThe data for the new node.
Returns:
The identifier accosiated to the new node.
list_t* list_create ( void  )

Creates a new list.

The list should be cleaned up by list_destroy.

Returns:
A pointer to the new list.
void list_destroy ( list_t list)

Cleans up the memory accosiated with a list object.

Parameters:
[in]listThe list to be destroyed.
void list_destroy_data ( list_t list,
void(*)(void *)  destroy_func 
)

Cleans up the memory accosiated with a list object as well as the data contained at each node.

Parameters:
[in]listThe list to be destroyed.
[in]destroy_funcThe function used to clean up the data.
_SREnodeID list_iterator_add ( list_iterator_t it,
void *  data 
)

Adds a new node at the position of the iterator.

The iterator will be broken and should be reset or deleted.

Parameters:
[in]itThe iterator to be used.
[in]dataThe data for the new node.
Returns:
The id of the new node.
list_iterator_t* list_iterator_create ( list_t list)

Creates a list_iterator_t.

Creates a new iterator for the given list, initialised at the start of the list. The iterator should be cleaned up by list_iterator_destroy.

Parameters:
[in]listThe list for which to create an iterator.
Returns:
A pointer to the new iterator.
void list_iterator_destroy ( list_iterator_t it)

Cleans up the memory accosiated with a list_iterator_t.

Parameters:
[in]itThe iterator to be destroyed.
SREbool list_iterator_find ( list_iterator_t it,
_SREnodeID  id 
)

Moves the iterator to the node containing id.

Parameters:
[in]itThe iterator to be used.
[in]idThe id of the node to find.
Returns:
The success of the search:
  • SRE_TRUE if a node with id was found.
  • SRE_FALSE if the node was not found.
void* list_iterator_get_data ( list_iterator_t it)

Gets the data of the node currently selected by the iterator.

Parameters:
[in]itThe iterator to be checked.
Returns:
The data of the node. NULL means that the iterator doesn't exist or the list is empty.
_SREnodeID list_iterator_get_id ( list_iterator_t it)

Gets the id of the node currently selected by the iterator.

Parameters:
[in]itThe iterator to be checked.
Returns:
The id of the node. 0 means that the iterator doesn't exist or the list is empty.
SREbool list_iterator_has_next ( list_iterator_t it)
SREbool list_iterator_move ( list_iterator_t it)

Moves the iterator one place through the list.

Parameters:
[in]itThe iterator to be moved.
Returns:
The success of the move:
  • SRE_TRUE if the iterator was moved.
  • SRE_FALSE if the iterator was not moved (due to an empty list or already being at the end of the list).
void list_iterator_remove ( list_iterator_t it)

Removes the node currently selected by the iterator.

This routine does not remove the data in the node, for this you must use list_iterator_remove_data. The iterator will be broken and should be reset or deleted.

Parameters:
[in]itThe iterator to check.
void list_iterator_remove_data ( list_iterator_t it,
void(*)(void *)  destroy_func 
)

Removes the node currently selected by the iterator, aswell as the data contained in te node.

The iterator will be broken and should be reset or deleted.

Parameters:
[in]itThe iterator to check.
[in]destroy_funcThis function is used to clean up the data held by the node.
void list_iterator_reset ( list_iterator_t it)

Resets the given iterator.

A reset iterator has the first node selected.

Parameters:
[in]itThe iterator to be reset.
SREbool list_remove ( list_t list,
_SREnodeID  id 
)

Removes a node from a list.

This routine will not clean up the data contained in the node, for this you should use list_remove_data.

Parameters:
[in]listThe list to remove the item from.
[in]idThe id for accosiated to the node to be removed.
Returns:
The success of the removal:
  • SRE_TRUE if a node was removed.
  • SRE_FALSE if the node was not found.
SREbool list_remove_data ( list_t list,
_SREnodeID  id,
void(*)(void *)  destroy_func 
)

Removes a node from a list, as well as freeing the associated data.

This routine will call destroy_func (node->data) to clean up the data contained in the node.

Parameters:
[in]listThe list to remove the item from.
[in]idThe id for accosiated to the node to be removed.
[in]destroy_funcThe function used to clean up the data.
Returns:
The success of the removal:
  • SRE_TRUE if a node was removed.
  • SRE_FALSE if the node was not found.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines