1.1 --- a/src/cx/list.h Fri Apr 07 11:30:28 2023 +0200 1.2 +++ b/src/cx/list.h Sun Apr 09 19:03:58 2023 +0200 1.3 @@ -37,29 +37,12 @@ 1.4 #ifndef UCX_LIST_H 1.5 #define UCX_LIST_H 1.6 1.7 -#include "common.h" 1.8 -#include "allocator.h" 1.9 -#include "iterator.h" 1.10 +#include "collection.h" 1.11 1.12 #ifdef __cplusplus 1.13 extern "C" { 1.14 #endif 1.15 1.16 -#ifndef CX_STORE_POINTERS 1.17 -/** 1.18 - * Special constant used for creating collections that are storing pointers. 1.19 - */ 1.20 -#define CX_STORE_POINTERS 0 1.21 -#endif 1.22 - 1.23 -/** 1.24 - * A comparator function comparing two list elements. 1.25 - */ 1.26 -typedef int(*CxListComparator)( 1.27 - void const *left, 1.28 - void const *right 1.29 -); 1.30 - 1.31 /** 1.32 * List class type. 1.33 */ 1.34 @@ -69,6 +52,7 @@ 1.35 * Structure for holding the base data of a list. 1.36 */ 1.37 struct cx_list_s { 1.38 + CX_COLLECTION_MEMBERS 1.39 /** 1.40 * The list class definition. 1.41 */ 1.42 @@ -77,50 +61,6 @@ 1.43 * The actual implementation in case the list class is delegating. 1.44 */ 1.45 cx_list_class const *climpl; 1.46 - /** 1.47 - * The allocator to use. 1.48 - */ 1.49 - CxAllocator const *allocator; 1.50 - /** 1.51 - * The comparator function for the elements. 1.52 - */ 1.53 - CxListComparator cmpfunc; 1.54 - /** 1.55 - * The size of each element (payload only). 1.56 - */ 1.57 - size_t itemsize; 1.58 - /** 1.59 - * The size of the list (number of currently stored elements). 1.60 - */ 1.61 - size_t size; 1.62 - /** 1.63 - * The capacity of the list (maximum number of elements). 1.64 - */ 1.65 - size_t capacity; 1.66 - union { 1.67 - /** 1.68 - * An optional simple destructor for the list contents that admits the free() interface. 1.69 - * 1.70 - * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE. 1.71 - * 1.72 - * @attention Read the documentation of the particular list implementation 1.73 - * whether this destructor shall only destroy the contents or also free the memory. 1.74 - */ 1.75 - cx_destructor_func simple_destructor; 1.76 - /** 1.77 - * An optional advanced destructor for the list contents providing additional data. 1.78 - * 1.79 - * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED. 1.80 - * 1.81 - * @attention Read the documentation of the particular list implementation 1.82 - * whether this destructor shall only destroy the contents or also free the memory. 1.83 - */ 1.84 - cx_advanced_destructor advanced_destructor; 1.85 - }; 1.86 - /** 1.87 - * The type of destructor to use. 1.88 - */ 1.89 - enum cx_destructor_type content_destructor_type; 1.90 }; 1.91 1.92 /** 1.93 @@ -234,51 +174,6 @@ 1.94 typedef struct cx_list_s CxList; 1.95 1.96 /** 1.97 - * Invokes the configured destructor function for a specific element. 1.98 - * 1.99 - * Usually only used by list implementations. There should be no need 1.100 - * to invoke this function manually. 1.101 - * 1.102 - * @param list the list 1.103 - * @param elem the element 1.104 - */ 1.105 -__attribute__((__nonnull__)) 1.106 -void cx_list_invoke_destructor( 1.107 - struct cx_list_s const *list, 1.108 - void *elem 1.109 -); 1.110 - 1.111 -/** 1.112 - * Invokes the simple destructor function for a specific element. 1.113 - * 1.114 - * Usually only used by list implementations. There should be no need 1.115 - * to invoke this function manually. 1.116 - * 1.117 - * @param list the list 1.118 - * @param elem the element 1.119 - */ 1.120 -__attribute__((__nonnull__)) 1.121 -void cx_list_invoke_simple_destructor( 1.122 - struct cx_list_s const *list, 1.123 - void *elem 1.124 -); 1.125 - 1.126 -/** 1.127 - * Invokes the advanced destructor function for a specific element. 1.128 - * 1.129 - * Usually only used by list implementations. There should be no need 1.130 - * to invoke this function manually. 1.131 - * 1.132 - * @param list the list 1.133 - * @param elem the element 1.134 - */ 1.135 -__attribute__((__nonnull__)) 1.136 -void cx_list_invoke_advanced_destructor( 1.137 - struct cx_list_s const *list, 1.138 - void *elem 1.139 -); 1.140 - 1.141 -/** 1.142 * Advises the list to store copies of the objects (default mode of operation). 1.143 * 1.144 * Retrieving objects from this list will yield pointers to the copies stored 1.145 @@ -309,11 +204,24 @@ 1.146 * Returns true, if this list is storing pointers instead of the actual data. 1.147 * 1.148 * @param list 1.149 - * @return 1.150 + * @return true, if this list is storing pointers 1.151 * @see cxListStorePointers() 1.152 */ 1.153 __attribute__((__nonnull__)) 1.154 -bool cxListIsStoringPointers(CxList const *list); 1.155 +static inline bool cxListIsStoringPointers(CxList const *list) { 1.156 + return list->store_pointer; 1.157 +} 1.158 + 1.159 +/** 1.160 + * Returns the number of elements currently stored in the list. 1.161 + * 1.162 + * @param list the list 1.163 + * @return the number of currently stored elements 1.164 + */ 1.165 +__attribute__((__nonnull__)) 1.166 +static inline size_t cxListSize(CxList const *list) { 1.167 + return list->size; 1.168 +} 1.169 1.170 /** 1.171 * Adds an item to the end of the list.