Thu, 23 May 2024 22:06:32 +0200
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 |
--- a/src/cx/collection.h Thu May 23 20:43:04 2024 +0200 +++ b/src/cx/collection.h Thu May 23 22:06:32 2024 +0200 @@ -100,6 +100,25 @@ #define CX_COLLECTION_BASE struct cx_collection_s collection /** + * Sets a simple destructor function for this collection. + * + * @param c the collection + * @param destr the destructor function + */ +#define cxDefineDestructor(c, destr) \ + (c)->collection.simple_destructor = (cx_destructor_func) destr + +/** + * Sets a simple destructor function for this collection. + * + * @param c the collection + * @param destr the destructor function + */ +#define cxDefineAdvancedDestructor(c, destr, data) \ + (c)->collection.advanced_destructor = (cx_destructor_func2) destr; \ + (c)->collection.destructor_data = data + +/** * Invokes the simple destructor function for a specific element. * * Usually only used by collection implementations. There should be no need
--- a/src/cx/map.h Thu May 23 20:43:04 2024 +0200 +++ b/src/cx/map.h Thu May 23 22:06:32 2024 +0200 @@ -187,6 +187,17 @@ map->collection.elem_size = sizeof(void *); } +/** + * Returns true, if this map is storing pointers instead of the actual data. + * + * @param map + * @return true, if this map is storing pointers + * @see cxMapStorePointers() + */ +__attribute__((__nonnull__)) +static inline bool cxMapIsStoringPointers(CxMap const *map) { + return map->collection.store_pointer; +} /** * Deallocates the memory of the specified map.
--- a/tests/test_list.c Thu May 23 20:43:04 2024 +0200 +++ b/tests/test_list.c Thu May 23 22:06:32 2024 +0200 @@ -1395,7 +1395,7 @@ roll_out_test_combos(simple_destr, { const size_t len = 60; int *testdata = int_test_data_added_to_list(list, isptrlist, len); - list->collection.simple_destructor = simple_destr_test_fun; + cxDefineDestructor(list, simple_destr_test_fun); CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len); free(testdata); }) @@ -1403,7 +1403,7 @@ roll_out_test_combos(advanced_destr, { const size_t len = 75; int *testdata = int_test_data_added_to_list(list, isptrlist, len); - list->collection.advanced_destructor = advanced_destr_test_fun; + cxDefineAdvancedDestructor(list, advanced_destr_test_fun, NULL); CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len); free(testdata); })