--- psiconv/trunk/lib/psiconv/list.h 2000/12/24 16:34:19 74 +++ psiconv/trunk/lib/psiconv/list.h 2001/01/29 21:57:05 98 @@ -23,6 +23,7 @@ #ifndef PSICONV_LIST_H #define PSICONV_LIST_H +#include #include #include @@ -40,7 +41,7 @@ If there is not enough memory available, NULL is returned. You should always test for this explicitely, because the other functions do not like a psiconv_list argument that is equal to NULL */ -extern psiconv_list psiconv_list_new(int element_size); +extern psiconv_list psiconv_list_new(size_t element_size); /* This frees the list. If elements contain pointers that need to be freed separately, call list_free_el below. */ @@ -52,16 +53,19 @@ extern void psiconv_list_free_el(psiconv_list l, void free_el(void *el)); /* Return the number of allocated elements */ -extern int psiconv_list_length(const psiconv_list l); +extern psiconv_u32 psiconv_list_length(const psiconv_list l); /* Return 1 if the list is empty, 0 if not */ extern int psiconv_list_is_empty(const psiconv_list l); +/* Empty a list. Note this does not reclaim any memory space! */ +extern void psiconv_list_empty(psiconv_list l); + /* Get an element from the list, and return a pointer to it. Note: you can directly modify this element, but be careful not to write beyond the element memory space. If indx is out of range, NULL is returned. */ -extern void * psiconv_list_get(const psiconv_list l, unsigned int indx); +extern void * psiconv_list_get(const psiconv_list l, psiconv_u32 indx); /* Add an element at the end of the list. The element is copied from the supplied element. Of course, this does not help if the element contains @@ -71,6 +75,19 @@ succeeds, 0 is returned. */ extern int psiconv_list_add(psiconv_list l, const void *el); +/* Remove the last element from the list, and copy it to el. Note that + this will not reduce the amount of space reserved for the list. + An error code is returned, which will be 0 zero if everything + succeeded. It is your own responsibility to make sure enough + space is allocated to el. */ +extern int psiconv_list_pop(psiconv_list l, void *el); + +/* Replace an element within the list. The element is copied from the + supplied element. Fails if you try to write at or after the end of + the list. */ +extern int psiconv_list_replace(psiconv_list l, psiconv_u32 indx, + const void *el); + /* Do some action for each element. Note: you can directly modify the elements supplied to action, and they will be changed in the list, but never try a free(el)! */