Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

All Data Structures Files Functions Variables Typedefs Macros Groups
Data Structures | Macros | Typedefs | Functions
LIST: generic type list

## Data Structures

struct | LIST_NODE
struct | LIST

## Macros

#define | link_node(__NODE_1, __NODE_2)
#define | list_foreach(__ITEM_, __LIST_)
#define | list_pop(__LIST_, __TYPE_) ( __TYPE_ *)list_pop_f( __LIST_ )
#define | list_shift(__LIST_, __TYPE_) (__TYPE_ *)list_shift_f( __LIST_ )
#define | remove_list_node(__LIST_,__NODE_, __TYPE_) (__TYPE_ *)remove_list_node_f( __LIST_ , __NODE_ )

## Typedefs

typedef struct LIST_NODE | LIST_NODE
typedef struct LIST | LIST

## Functions

LIST * | new_generic_list (int max_items)
| Initialiaze a generic list container to max_items pointers. More...
LIST_NODE * | new_list_node (void *ptr, void(*destructor)(void *ptr))
| Allocate a new node to link in a list. More...
void * | remove_list_node_f (LIST *list, LIST_NODE *node)
| Internal function called each time we need to get a node out of a list. More...
int | list_push (LIST *list, void *ptr, void(*destructor)(void *ptr))
| Add a pointer to the end of the list. More...
int | list_push_sorted (LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
| Add a pointer sorted in the list , starting by the end of the list. More...
int | list_unshift (LIST *list, void *ptr, void(*destructor)(void *ptr))
| Add a pointer at the start of the list. More...
int | list_unshift_sorted (LIST *list, void *ptr, int(*comparator)(void *a, void *b), void(*destructor)(void *ptr))
| Add a pointer sorted in the list , starting by the start of the list. More...
void * | list_pop_f (LIST *list)
| Get a pointer from the end of the list. More...
void * | list_shift_f (LIST *list)
| Get a pointer from the start of the list. More...
int | list_empty (LIST *list)
| Empty a LIST list of pointers. More...
int | list_empty_with_f (LIST *list, void(*free_fnct)(void *ptr))
| Empty a LIST list of pointers. More...
int | list_destroy (LIST **list)
| Empty and Free a list container. Call the destructor each time. More...

## Detailed Description

## Macro Definition Documentation

#define link_node | ( |  | __NODE_1,
|  |  | __NODE_2
| ) |  |

Value:
do \
{ \
__NODE_2 -> prev = __NODE_1 ; \
__NODE_1 -> next = __NODE_2 ; \
} \
while( 0 )

Macro helper for linking two nodes

Definition at line 62 of file n_list.h.

#define list_foreach | ( |  | __ITEM_,
|  |  | __LIST_
| ) |  |

Value:
if( !__LIST_ ) \
{ \
n_log( LOG_ERR , "Error in list_foreach, %s is NULL" , #__LIST_ ); \
} \
else \
for( LIST_NODE *__ITEM_ = __LIST_ -> start ; __ITEM_ != NULL; __ITEM_ = __ITEM_ -> next ) \

ForEach macro helper

Definition at line 71 of file n_list.h.

#define list_pop | ( |  | __LIST_,
|  |  | __TYPE_
| ) |  | ( __TYPE_ *)list_pop_f( __LIST_ )

Pop macro helper for void pointer casting

Definition at line 80 of file n_list.h.

#define list_shift | ( |  | __LIST_,
|  |  | __TYPE_
| ) |  | (__TYPE_ *)list_shift_f( __LIST_ )

Shift macro helper for void pointer casting

Definition at line 82 of file n_list.h.

#define remove_list_node | ( |  | __LIST_,
|  |  | __NODE_,
|  |  | __TYPE_
| ) |  | (__TYPE_ *)remove_list_node_f( __LIST_ , __NODE_ )

Remove macro helper for void pointer casting

Definition at line 84 of file n_list.h.

## Typedef Documentation

typedef struct LIST LIST

Structure of a generic LIST container

typedef struct LIST_NODE LIST_NODE

Structure of a generic list node

## Function Documentation

int list_destroy | ( | LIST ** | list | ) |

Empty and Free a list container. Call the destructor each time.

Parameters

  list | The list to destroy. An already empty or null list will cause an error and a _log message.

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 442 of file n_list.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int list_empty | ( | LIST * | list | ) |

Empty a LIST list of pointers.

Parameters

  list | The list to empty. An already empty or null list will cause an error and a _log message.

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 382 of file n_list.c.

Here is the caller graph for this function:

int list_empty_with_f | ( | LIST * | list,
|  | void(*)(void *ptr) | free_fnct
| ) |  |

Empty a LIST list of pointers.

Parameters

  list | The list to empty. An already empty or null list will cause an error and a _log message.
  free_fnct | a function ptr to a void func( void *ptr )

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 416 of file n_list.c.

void * list_pop_f | ( | LIST * | list | ) |

Get a pointer from the end of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.

Returns
  A void *ptr or NULL. Check error messages in DEBUG mode.

Definition at line 311 of file n_list.c.

int list_push | ( | LIST * | list,
|  | void * | ptr,
|  | void(*)(void *ptr) | destructor
| ) |  |

Add a pointer to the end of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.
  ptr | The pointer you wan to put in the list. A null value will cause an error and a _log message.
  destructor | Pointer to the ptr type destructor function. Leave to NULL if there isn't.

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 118 of file n_list.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int list_push_sorted | ( | LIST * | list,
|  | void * | ptr,
|  | int(*)(const void *a, const void *b) | comparator,
|  | void(*)(void *ptr) | destructor
| ) |  |

Add a pointer sorted in the list , starting by the end of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.
  ptr | The pointer you wan to put in the list. A null value will cause an error and a _log message.
  comparator | A pointer to a function which take two void * pointers and return an int.
  destructor | Pointer to the ptr type destructor function. Leave to NULL if there isn't.

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 159 of file n_list.c.

Here is the call graph for this function:

void * list_shift_f | ( | LIST * | list | ) |

Get a pointer from the start of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.

Returns
  A void *ptr or NULL. Check error messages in DEBUG mode.

Definition at line 346 of file n_list.c.

int list_unshift | ( | LIST * | list,
|  | void * | ptr,
|  | void(*)(void *ptr) | destructor
| ) |  |

Add a pointer at the start of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.
  ptr | The pointer you wan to put in the list. A null value will cause an error and a _log message.
  destructor | Pointer to the ptr type destructor function. Leave to NULL if there isn't.

Returns
  A void *ptr or NULL. Check error messages in DEBUG mode.

Definition at line 216 of file n_list.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int list_unshift_sorted | ( | LIST * | list,
|  | void * | ptr,
|  | int(*)(void *a, void *b) | comparator,
|  | void(*)(void *ptr) | destructor
| ) |  |

Add a pointer sorted in the list , starting by the start of the list.

Parameters

  list | An initilized list container. A null value will cause an error and a _log message.
  ptr | The pointer you wan to put in the list. A null value will cause an error and a _log message.
  comparator | A pointer to a function which take two void * pointers and return an int.
  destructor | Pointer to the ptr type destructor function. Leave to NULL if there isn't.

Returns
  TRUE or FALSE. Check error messages in DEBUG mode.

Definition at line 256 of file n_list.c.

Here is the call graph for this function:

LIST * new_generic_list | ( | int | max_items | ) |

Initialiaze a generic list container to max_items pointers.

Parameters

  max_items | Specify a max size for the list container, 0 or negative for unlimited lists.

Returns
  a new LIST or NULL

Definition at line 17 of file n_list.c.

Here is the caller graph for this function:

LIST_NODE * new_list_node | ( | void * | ptr,
|  | void(*)(void *ptr) | destructor
| ) |  |

Allocate a new node to link in a list.

Parameters

  ptr | The pointer you want to put in the node.
  destructor | Pointer to the ptr type destructor function. Leave to NULL if there isn't.

Returns
  A new node or NULL on error. Check error messages in DEBUG mode.

Definition at line 43 of file n_list.c.

Here is the caller graph for this function:

void * remove_list_node_f | ( | LIST * | list,
|  | LIST_NODE * | node
| ) |  |

Internal function called each time we need to get a node out of a list.

Parameters

  list | The list to pick in
  node | The node to remove in the list

Returns
  The node or NULL

Definition at line 65 of file n_list.c.