![]() |
ooc
1.3c
Object Oriented tollkit fo ANSI C
|
List class - doubly linked list, a standard ooc container. More...
#include "ooc.h"
Macros | |
#define | list_new_type(pClass, manage) _list_new_type( & pClass ## Class, manage ) |
Convenient macro for creating typed List. More... | |
#define | list_new_of_nodes(pNode, manage) _list_new_of_nodes( & pNode ## Class, manage ) |
Convenient macro for creating a List of a given type of ListNodes. More... | |
#define | list_use_of_nodes(location, pNode, manage) _list_use_of_nodes( location, & pNode ## Class, manage ) |
Convenient macro for creating a List of a given type of ListNodes at a preallocated location. More... | |
Typedefs | |
typedef struct ListObject * | List |
List class declaration. | |
typedef ListNode | ListIterator |
List iterator. More... | |
typedef void(* | list_item_destroyer )(void *item) |
Destroy function prototype for the list items. More... | |
typedef void(* | list_item_executor )(void *item, void *param) |
Execution function prototype for the list items. More... | |
typedef int(* | list_item_checker )(void *item, void *param) |
Boolean function prototype for the list items. More... | |
Functions | |
List | list_new (list_item_destroyer destroyer) |
Creates a new List. More... | |
List | _list_new_type (Class type, int manage) |
Creates a new List of a given type. More... | |
List | _list_new_of_nodes (Class node, int manage) |
Creates a new List of a given type of ListNodes. More... | |
void | _list_use_of_nodes (void *location, Class node, int manage) |
Creates a new List of a given type of ListNodes at location. More... | |
ListIterator | list_append (List list, void *item) |
Appends an item to the end of the list. More... | |
ListIterator | list_prepend (List list, void *item) |
Prepends an item at the beginning of the list. More... | |
ListIterator | list_insert_before (List list, ListIterator position, void *item) |
Inserts an item before the given position of the list. More... | |
ListIterator | list_insert_after (List list, ListIterator position, void *item) |
Inserts an item after the given position of the list. More... | |
void * | list_remove_item (List list, ListIterator position) |
Removes an item from the list. More... | |
void * | list_remove_first_item (List list) |
Removes the first item from the list. More... | |
void * | list_remove_last_item (List list) |
Removes the last item from the list. More... | |
void | list_delete_item (List list, ListIterator position) |
Deletes an item in the list. More... | |
ListIterator | list_first (List list) |
Gets the iterator for the first item in the list. More... | |
ListIterator | list_last (List list) |
Gets the iterator for the last item in the list. More... | |
void * | list_get_item (ListIterator listiterator) |
Gets an item in the list. More... | |
ListIterator | list_next (List list, ListIterator listiterator) |
Gets the iterator of the next item in the list. More... | |
ListIterator | list_previous (List list, ListIterator listiterator) |
Gets the iterator of the previous item in the list. More... | |
void | list_swap (List list, ListIterator listiterator1, ListIterator listiterator2) |
Changes two items' position in the list. More... | |
void | list_foreach (List list, list_item_executor method, void *param) |
Executes a method for each items in the list. More... | |
ListIterator | list_foreach_until_true (List list, ListIterator from, list_item_checker method, void *param) |
Executes a method for each items in the list until it returns TRUE . More... | |
void | list_foreach_delete_if (List list, list_item_checker criteria, void *param) |
Deletes each items in the list that match the criteria. More... | |
ListIterator | list_find_item (List list, ListIterator position, list_item_checker criteria, void *param) |
Finds the first matching item in the list. More... | |
ListIterator | list_find_item_reverse (List list, ListIterator position, list_item_checker criteria, void *param) |
Finds the first matching item in the list in reverse order. More... | |
Class | list_get_type (List list) |
Get the type of the list. More... | |
int | list_get_managed (List list) |
Check if the list is managed. More... | |
List class - doubly linked list, a standard ooc container.
List is a container class, that can hold pointers to any kind of data. Every item stored in the list must work perfectly with the supplied list item destroyer! In practice this means, that you can only store items in the list that has the same deletion method.
foreach
and find
methods may behave unexpectedly if an other thread is modifying the List! Make your own locking if needed! The same applies to the ooc_duplicate() method for List (uses list_foreach() internally)! #define list_new_of_nodes | ( | pNode, | |
manage | |||
) | _list_new_of_nodes( & pNode ## Class, manage ) |
Convenient macro for creating a List of a given type of ListNodes.
pNode | The type of the ListNodes. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. pNode must be a sublass of ListNode. |
manage | TRUE if the List must manage the Objects put in the List, FALSE if not. |
#define list_new_type | ( | pClass, | |
manage | |||
) | _list_new_type( & pClass ## Class, manage ) |
Convenient macro for creating typed List.
pClass | The type of the List. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. |
manage | TRUE if the List must manage the Objects put in the List, FALSE if not. |
#define list_use_of_nodes | ( | location, | |
pNode, | |||
manage | |||
) | _list_use_of_nodes( location, & pNode ## Class, manage ) |
Convenient macro for creating a List of a given type of ListNodes at a preallocated location.
location | The location where the preallocated List must be created. The location must be large enough to hold a ListObject. |
pNode | The type of the ListNodes. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. pNode must be a sublass of ListNode. |
manage | OOC_MANAGE if the List must manage the Objects put in the List, !OOC_MANAGE if not. |
typedef int(* list_item_checker)(void *item, void *param) |
Boolean function prototype for the list items.
This function is called by some of the list_for_each...() method.
item | The item. |
param | The parameter passed to the list_for_each() function. |
TRUE
or FALSE
. typedef void( * list_item_destroyer)(void *item) |
Destroy function prototype for the list items.
This function must clean up the item that was stored in the list and must free all resources (memory) that was allocated by this item.
item | The item that shuold be destroyed. |
typedef void(* list_item_executor)(void *item, void *param) |
Execution function prototype for the list items.
This function is called by the list_for_each() method.
item | The item. |
param | The parameter passed to the list_for_each() function. |
typedef ListNode ListIterator |
List iterator.
This iterator can be used as an identifier of a list node in the list.
Creates a new List of a given type of ListNodes.
Creates an empty List of listNodes.
node | The type of the ListNodes. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. node must be a sublass of ListNode. |
manage | TRUE if the List must manage the Objects put in the List, FALSE if not. |
Creates a new List of a given type.
Creates an empty typed List.
type | The type of the List. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. |
manage | TRUE if the List must manage the Objects put in the List, FALSE if not. |
void _list_use_of_nodes | ( | void * | location, |
Class | node, | ||
int | manage | ||
) |
Creates a new List of a given type of ListNodes at location.
Creates an empty List of listNodes at a preallocated location.
location | The location where the preallocated List must be created. The location must be large enough to hold a ListObject. |
node | The type of the ListNodes. It is guaranteed, that the list holds this type of Objects only. Trying to put different Object into the List will cause throwing an Exception with err_bad_cast error code. node must be a sublass of ListNode. |
manage | OOC_MANAGE if the List must manage the Objects put in the List, !OOC_MANAGE if not. |
ListIterator list_append | ( | List | list, |
void * | item | ||
) |
Appends an item to the end of the list.
list | The list |
item | The item to be appended. The list takes over the ownership of the item if you have created the list with a list item destroyer. |
void list_delete_item | ( | List | list, |
ListIterator | position | ||
) |
Deletes an item in the list.
This method removes and destroys the positioned item in the list.
list | The list |
position | The position of the item to be removed. |
NULL
as item destroyer for list_new(), then actually no deletion occurs. ListIterator list_find_item | ( | List | list, |
ListIterator | position, | ||
list_item_checker | criteria, | ||
void * | param | ||
) |
Finds the first matching item in the list.
This is a forward search (in the direction from the first item to the last item.)
list | The list. |
position | The position from where to start the search. It must be a valid list iterator, otherwise will throw err_wrong_position exception. Passing NULL will start from the beginning of the List. |
criteria | The method that is used to decide which items find. |
param | The parameter to be passed for the executed method. |
NULL
if there was no match. ListIterator list_find_item_reverse | ( | List | list, |
ListIterator | position, | ||
list_item_checker | criteria, | ||
void * | param | ||
) |
Finds the first matching item in the list in reverse order.
This is a backward search (in the direction from the last item to the first item.)
list | The list. |
position | The position from where to start the search. It must be a valid list iterator, otherwise will throw err_wrong_position exception. Passing NULL will start from the end of the List. |
criteria | The method that is used to decide which items find. |
param | The parameter to be passed for the executed method. |
NULL
if there was no match. ListIterator list_first | ( | List | list | ) |
Gets the iterator for the first item in the list.
list | The list |
NULL
if the list is empty. void list_foreach | ( | List | list, |
list_item_executor | method, | ||
void * | param | ||
) |
Executes a method for each items in the list.
list | The list. |
method | The method to be executed for each items. |
param | The parameter to be passed for the executed method. |
void list_foreach_delete_if | ( | List | list, |
list_item_checker | criteria, | ||
void * | param | ||
) |
Deletes each items in the list that match the criteria.
list | The list. |
criteria | The method that is used to decide which items to delete. The item is deleted if the method returns TRUE for it. |
param | The parameter to be passed for the executed method. |
ListIterator list_foreach_until_true | ( | List | list, |
ListIterator | from, | ||
list_item_checker | method, | ||
void * | param | ||
) |
Executes a method for each items in the list until it returns TRUE
.
list | The list. |
from | The position of the first item to be checked, or NULL if must start from the first item in the list. |
method | The method to be executed for each items. |
param | The parameter to be passed for the executed method. |
void* list_get_item | ( | ListIterator | listiterator | ) |
Gets an item in the list.
listiterator | The position of the item in the list. It must be a valid list iterator, passing NULL will throw err_wrong_position exception. |
int list_get_managed | ( | List | list | ) |
Check if the list is managed.
Check is the items in the list are managed by the list.
list | The list. |
Get the type of the list.
Returns the type of the list in case of a typed list.
list | The list. |
ListIterator list_insert_after | ( | List | list, |
ListIterator | position, | ||
void * | item | ||
) |
Inserts an item after the given position of the list.
list | The list |
position | The positon |
item | The item to be inserted. The list takes over the ownership of the item if you have created the list with a list item destroyer. |
ListIterator list_insert_before | ( | List | list, |
ListIterator | position, | ||
void * | item | ||
) |
Inserts an item before the given position of the list.
list | The list |
position | The positon |
item | The item to be inserted. The list takes over the ownership of the item if you have created the list with a list item destroyer. |
ListIterator list_last | ( | List | list | ) |
Gets the iterator for the last item in the list.
list | The list |
NULL
if the list is empty. List list_new | ( | list_item_destroyer | destroyer | ) |
Creates a new List.
Creates an empty List.
destroyer | The destroy function for the list items. It is usually ooc_free(), ooc_delete() or ooc_delete_and_null() depending on the type of the items stored in the List. For static List items (that do not need the release of the occupied memory) you can pass NULL as well. |
ListIterator list_next | ( | List | list, |
ListIterator | listiterator | ||
) |
Gets the iterator of the next item in the list.
list | The list |
listiterator | The position of the current item in the list. It must be a valid list iterator, passing NULL will throw err_wrong_position exception. |
NULL
if there are no more items. ListIterator list_prepend | ( | List | list, |
void * | item | ||
) |
Prepends an item at the beginning of the list.
list | The list |
item | The item to be prepended. The list takes over the ownership of the item if you have created the list with a list item destroyer. |
ListIterator list_previous | ( | List | list, |
ListIterator | listiterator | ||
) |
Gets the iterator of the previous item in the list.
list | The list |
listiterator | The position of the current item in the list. It must be a valid list iterator, passing NULL will throw err_wrong_position exception. |
NULL
if there are no more items. void* list_remove_first_item | ( | List | list | ) |
Removes the first item from the list.
list | The list |
void* list_remove_item | ( | List | list, |
ListIterator | position | ||
) |
Removes an item from the list.
list | The list |
position | The position of the item to be removed. |
void* list_remove_last_item | ( | List | list | ) |
Removes the last item from the list.
list | The list |
void list_swap | ( | List | list, |
ListIterator | listiterator1, | ||
ListIterator | listiterator2 | ||
) |
Changes two items' position in the list.
list | The list. |
listiterator1 | The list iterator of the first item |
listiterator2 | The list iterator of the second item |
NULL
will throw err_wrong_position
exception.