src/cx/list.h

changeset 504
aaf89ce0cbf6
parent 503
a89857072ace
child 505
03e9151bea32
     1.1 --- a/src/cx/list.h	Tue Feb 15 19:41:48 2022 +0100
     1.2 +++ b/src/cx/list.h	Tue Feb 15 19:48:25 2022 +0100
     1.3 @@ -193,6 +193,28 @@
     1.4  typedef struct cx_list_s CxList;
     1.5  
     1.6  /**
     1.7 + * Convenience function to configure the memory management for this a list.
     1.8 + * @param list the list to configure
     1.9 + * @param list_destructor an alternative list destructor to use (if \c NULL, the current destructor remains unchanged)
    1.10 + * @param content_destructor the content destructor to use (if \c NULL, no content destructor is used)
    1.11 + * @param list_autofree a flag indicating, if the list allocator shall free the list, if the destructor did not do that
    1.12 + * @param content_autofree a flag indicating, if the list allocator shall free an element,
    1.13 + * if the content destructor did not do that or no content destructor exists
    1.14 + */
    1.15 +static inline void cxListMemoryMgmt(
    1.16 +        CxList *list,
    1.17 +        cx_destructor_func list_destructor,
    1.18 +        cx_destructor_func content_destructor,
    1.19 +        bool list_autofree,
    1.20 +        bool content_autofree
    1.21 +) {
    1.22 +    if (list_destructor != NULL) list->list_destructor = list_destructor;
    1.23 +    list->content_destructor = content_destructor;
    1.24 +    list->autofree = list_autofree;
    1.25 +    list->autofree_contents = content_autofree;
    1.26 +}
    1.27 +
    1.28 +/**
    1.29   * Adds an item to the end of the list.
    1.30   *
    1.31   * @param list the list

mercurial