diff -r d0680a23d850 -r b09aae58bba4 src/cx/list.h --- a/src/cx/list.h Fri Apr 07 11:30:28 2023 +0200 +++ b/src/cx/list.h Sun Apr 09 19:03:58 2023 +0200 @@ -37,29 +37,12 @@ #ifndef UCX_LIST_H #define UCX_LIST_H -#include "common.h" -#include "allocator.h" -#include "iterator.h" +#include "collection.h" #ifdef __cplusplus extern "C" { #endif -#ifndef CX_STORE_POINTERS -/** - * Special constant used for creating collections that are storing pointers. - */ -#define CX_STORE_POINTERS 0 -#endif - -/** - * A comparator function comparing two list elements. - */ -typedef int(*CxListComparator)( - void const *left, - void const *right -); - /** * List class type. */ @@ -69,6 +52,7 @@ * Structure for holding the base data of a list. */ struct cx_list_s { + CX_COLLECTION_MEMBERS /** * The list class definition. */ @@ -77,50 +61,6 @@ * The actual implementation in case the list class is delegating. */ cx_list_class const *climpl; - /** - * The allocator to use. - */ - CxAllocator const *allocator; - /** - * The comparator function for the elements. - */ - CxListComparator cmpfunc; - /** - * The size of each element (payload only). - */ - size_t itemsize; - /** - * The size of the list (number of currently stored elements). - */ - size_t size; - /** - * The capacity of the list (maximum number of elements). - */ - size_t capacity; - union { - /** - * An optional simple destructor for the list contents that admits the free() interface. - * - * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE. - * - * @attention Read the documentation of the particular list implementation - * whether this destructor shall only destroy the contents or also free the memory. - */ - cx_destructor_func simple_destructor; - /** - * An optional advanced destructor for the list contents providing additional data. - * - * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED. - * - * @attention Read the documentation of the particular list implementation - * whether this destructor shall only destroy the contents or also free the memory. - */ - cx_advanced_destructor advanced_destructor; - }; - /** - * The type of destructor to use. - */ - enum cx_destructor_type content_destructor_type; }; /** @@ -234,51 +174,6 @@ typedef struct cx_list_s CxList; /** - * Invokes the configured destructor function for a specific element. - * - * Usually only used by list implementations. There should be no need - * to invoke this function manually. - * - * @param list the list - * @param elem the element - */ -__attribute__((__nonnull__)) -void cx_list_invoke_destructor( - struct cx_list_s const *list, - void *elem -); - -/** - * Invokes the simple destructor function for a specific element. - * - * Usually only used by list implementations. There should be no need - * to invoke this function manually. - * - * @param list the list - * @param elem the element - */ -__attribute__((__nonnull__)) -void cx_list_invoke_simple_destructor( - struct cx_list_s const *list, - void *elem -); - -/** - * Invokes the advanced destructor function for a specific element. - * - * Usually only used by list implementations. There should be no need - * to invoke this function manually. - * - * @param list the list - * @param elem the element - */ -__attribute__((__nonnull__)) -void cx_list_invoke_advanced_destructor( - struct cx_list_s const *list, - void *elem -); - -/** * Advises the list to store copies of the objects (default mode of operation). * * Retrieving objects from this list will yield pointers to the copies stored @@ -309,11 +204,24 @@ * Returns true, if this list is storing pointers instead of the actual data. * * @param list - * @return + * @return true, if this list is storing pointers * @see cxListStorePointers() */ __attribute__((__nonnull__)) -bool cxListIsStoringPointers(CxList const *list); +static inline bool cxListIsStoringPointers(CxList const *list) { + return list->store_pointer; +} + +/** + * Returns the number of elements currently stored in the list. + * + * @param list the list + * @return the number of currently stored elements + */ +__attribute__((__nonnull__)) +static inline size_t cxListSize(CxList const *list) { + return list->size; +} /** * Adds an item to the end of the list.