diff -r d50b5dc1e058 -r af5bf4603a5d src/cx/list.h --- a/src/cx/list.h Sun Mar 05 10:55:32 2023 +0100 +++ b/src/cx/list.h Tue Mar 14 20:25:24 2023 +0100 @@ -164,6 +164,11 @@ ); /** + * Member function for removing all elements. + */ + void (*clear)(struct cx_list_s *list); + + /** * Member function for swapping two elements. */ int (*swap)( @@ -222,6 +227,21 @@ typedef struct cx_list_s CxList; /** + * Invokes the destructor function for a specific element. + * + * Usually only used by list implementations. There should be no need + * to invoke this function manually. + * + * @param list the list + * @param elem the element + */ +__attribute__((__nonnull__)) +void cx_list_invoke_destructor( + struct cx_list_s const *list, + void *elem +); + +/** * Advises the list to store copies of the objects (default mode of operation). * * Retrieving objects from this list will yield pointers to the copies stored @@ -398,6 +418,10 @@ /** * Removes the element at the specified index. + * + * If an element destructor function is specified, it is called before + * removing the element. + * * @param list the list * @param index the index of the element * @return zero on success, non-zero if the index is out of bounds @@ -411,6 +435,19 @@ } /** + * Removes all elements from this list. + * + * If an element destructor function is specified, it is called for each + * element before removing them. + * + * @param list the list + */ +__attribute__((__nonnull__)) +static inline void cxListClear(CxList *list) { + list->cl->clear(list); +} + +/** * Swaps two items in the list. * * Implementations should only allocate temporary memory for the swap, if