src/cx/list.h

changeset 664
af5bf4603a5d
parent 655
7340c4255f1f
child 666
b5dd654deb3b
     1.1 --- a/src/cx/list.h	Sun Mar 05 10:55:32 2023 +0100
     1.2 +++ b/src/cx/list.h	Tue Mar 14 20:25:24 2023 +0100
     1.3 @@ -164,6 +164,11 @@
     1.4      );
     1.5  
     1.6      /**
     1.7 +     * Member function for removing all elements.
     1.8 +     */
     1.9 +    void (*clear)(struct cx_list_s *list);
    1.10 +
    1.11 +    /**
    1.12       * Member function for swapping two elements.
    1.13       */
    1.14      int (*swap)(
    1.15 @@ -222,6 +227,21 @@
    1.16  typedef struct cx_list_s CxList;
    1.17  
    1.18  /**
    1.19 + * Invokes the destructor function for a specific element.
    1.20 + *
    1.21 + * Usually only used by list implementations. There should be no need
    1.22 + * to invoke this function manually.
    1.23 + *
    1.24 + * @param list the list
    1.25 + * @param elem the element
    1.26 + */
    1.27 +__attribute__((__nonnull__))
    1.28 +void cx_list_invoke_destructor(
    1.29 +        struct cx_list_s const *list,
    1.30 +        void *elem
    1.31 +);
    1.32 +
    1.33 +/**
    1.34   * Advises the list to store copies of the objects (default mode of operation).
    1.35   *
    1.36   * Retrieving objects from this list will yield pointers to the copies stored
    1.37 @@ -398,6 +418,10 @@
    1.38  
    1.39  /**
    1.40   * Removes the element at the specified index.
    1.41 + *
    1.42 + * If an element destructor function is specified, it is called before
    1.43 + * removing the element.
    1.44 + *
    1.45   * @param list the list
    1.46   * @param index the index of the element
    1.47   * @return zero on success, non-zero if the index is out of bounds
    1.48 @@ -411,6 +435,19 @@
    1.49  }
    1.50  
    1.51  /**
    1.52 + * Removes all elements from this list.
    1.53 + *
    1.54 + * If an element destructor function is specified, it is called for each
    1.55 + * element before removing them.
    1.56 + *
    1.57 + * @param list the list
    1.58 + */
    1.59 +__attribute__((__nonnull__))
    1.60 +static inline void cxListClear(CxList *list) {
    1.61 +    list->cl->clear(list);
    1.62 +}
    1.63 +
    1.64 +/**
    1.65   * Swaps two items in the list.
    1.66   *
    1.67   * Implementations should only allocate temporary memory for the swap, if

mercurial