src/cx/list.h

changeset 503
a89857072ace
parent 500
eb9e7bd40a8e
child 504
aaf89ce0cbf6
     1.1 --- a/src/cx/list.h	Tue Feb 15 19:07:14 2022 +0100
     1.2 +++ b/src/cx/list.h	Tue Feb 15 19:41:48 2022 +0100
     1.3 @@ -71,6 +71,14 @@
     1.4       */
     1.5      CxAllocator *allocator;
     1.6      /**
     1.7 +     * A mandatory destructor for the list structure.
     1.8 +     */
     1.9 +    cx_destructor_func list_destructor;
    1.10 +    /**
    1.11 +     * An optional destructor for the list contents.
    1.12 +     */
    1.13 +    cx_destructor_func content_destructor;
    1.14 +    /**
    1.15       * The comparator function for the elements.
    1.16       */
    1.17      CxListComparator cmpfunc;
    1.18 @@ -86,6 +94,16 @@
    1.19       * The capacity of the list (maximum number of elements).
    1.20       */
    1.21      size_t capacity;
    1.22 +    /**
    1.23 +     * Flag indicating whether cxListDestroy() shall free the list structure,
    1.24 +     * even if cx_list_s.list_destructor did not do that.
    1.25 +     */
    1.26 +    bool autofree;
    1.27 +    /**
    1.28 +     * Flag indicating whether cxListDestroy() shall free each list element,
    1.29 +     * even if cx_list_s.content_destructor did not do that.
    1.30 +     */
    1.31 +    bool autofree_contents;
    1.32  };
    1.33  
    1.34  /**
    1.35 @@ -364,6 +382,21 @@
    1.36      return list->cl->compare(list, other);
    1.37  }
    1.38  
    1.39 +/**
    1.40 + * Calls the list's destructor function for every element.
    1.41 + * If CxList.autofree_content is \c true, the elements are automatically free'd
    1.42 + * unless the content destructor function did not already do that.
    1.43 + * Similarly, if CxList.autofree is \c true, the list structure is free'd, unless
    1.44 + * the list destructor function did not already do that.
    1.45 + *
    1.46 + * This function itself is a destructor function for the CxList.
    1.47 + *
    1.48 + * @param list the list which contents shall be destroyed
    1.49 + * @return \p list if the list structure has been free'd during the process
    1.50 + */
    1.51 +__attribute__((__nonnull__))
    1.52 +CxList *cxListDestroy(CxList *list);
    1.53 +
    1.54  #ifdef __cplusplus
    1.55  } /* extern "C" */
    1.56  #endif

mercurial