add missing convenience functions

Thu, 23 May 2024 22:06:32 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 23 May 2024 22:06:32 +0200
changeset 857
4d12e34bb130
parent 856
6bbbf219251d
child 858
d9ad7904c4c2

add missing convenience functions

src/cx/collection.h file | annotate | diff | comparison | revisions
src/cx/map.h file | annotate | diff | comparison | revisions
tests/test_list.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/cx/collection.h	Thu May 23 20:43:04 2024 +0200
     1.2 +++ b/src/cx/collection.h	Thu May 23 22:06:32 2024 +0200
     1.3 @@ -100,6 +100,25 @@
     1.4  #define CX_COLLECTION_BASE struct cx_collection_s collection
     1.5  
     1.6  /**
     1.7 + * Sets a simple destructor function for this collection.
     1.8 + *
     1.9 + * @param c the collection
    1.10 + * @param destr the destructor function
    1.11 + */
    1.12 +#define cxDefineDestructor(c, destr) \
    1.13 +    (c)->collection.simple_destructor = (cx_destructor_func) destr
    1.14 +
    1.15 +/**
    1.16 + * Sets a simple destructor function for this collection.
    1.17 + *
    1.18 + * @param c the collection
    1.19 + * @param destr the destructor function
    1.20 + */
    1.21 +#define cxDefineAdvancedDestructor(c, destr, data) \
    1.22 +    (c)->collection.advanced_destructor = (cx_destructor_func2) destr; \
    1.23 +    (c)->collection.destructor_data = data
    1.24 +
    1.25 +/**
    1.26   * Invokes the simple destructor function for a specific element.
    1.27   *
    1.28   * Usually only used by collection implementations. There should be no need
     2.1 --- a/src/cx/map.h	Thu May 23 20:43:04 2024 +0200
     2.2 +++ b/src/cx/map.h	Thu May 23 22:06:32 2024 +0200
     2.3 @@ -187,6 +187,17 @@
     2.4      map->collection.elem_size = sizeof(void *);
     2.5  }
     2.6  
     2.7 +/**
     2.8 + * Returns true, if this map is storing pointers instead of the actual data.
     2.9 + *
    2.10 + * @param map
    2.11 + * @return true, if this map is storing pointers
    2.12 + * @see cxMapStorePointers()
    2.13 + */
    2.14 +__attribute__((__nonnull__))
    2.15 +static inline bool cxMapIsStoringPointers(CxMap const *map) {
    2.16 +    return map->collection.store_pointer;
    2.17 +}
    2.18  
    2.19  /**
    2.20   * Deallocates the memory of the specified map.
     3.1 --- a/tests/test_list.c	Thu May 23 20:43:04 2024 +0200
     3.2 +++ b/tests/test_list.c	Thu May 23 22:06:32 2024 +0200
     3.3 @@ -1395,7 +1395,7 @@
     3.4  roll_out_test_combos(simple_destr, {
     3.5      const size_t len = 60;
     3.6      int *testdata = int_test_data_added_to_list(list, isptrlist, len);
     3.7 -    list->collection.simple_destructor = simple_destr_test_fun;
     3.8 +    cxDefineDestructor(list, simple_destr_test_fun);
     3.9      CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
    3.10      free(testdata);
    3.11  })
    3.12 @@ -1403,7 +1403,7 @@
    3.13  roll_out_test_combos(advanced_destr, {
    3.14      const size_t len = 75;
    3.15      int *testdata = int_test_data_added_to_list(list, isptrlist, len);
    3.16 -    list->collection.advanced_destructor = advanced_destr_test_fun;
    3.17 +    cxDefineAdvancedDestructor(list, advanced_destr_test_fun, NULL);
    3.18      CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
    3.19      free(testdata);
    3.20  })

mercurial