1.1 --- a/src/cx/list.h Sat Jan 29 14:32:04 2022 +0100 1.2 +++ b/src/cx/list.h Sun Jan 30 14:19:00 2022 +0100 1.3 @@ -54,90 +54,9 @@ 1.4 ); 1.5 1.6 /** 1.7 - * Internal type for the list structure - use CxList instead. 1.8 + * List class type. 1.9 */ 1.10 -typedef struct cx_list_s cx_list_s; 1.11 - 1.12 -/** 1.13 - * The class definition for arbitrary lists. 1.14 - */ 1.15 -typedef struct { 1.16 - /** 1.17 - * Member function for adding an element. 1.18 - */ 1.19 - int (*add)( 1.20 - cx_list_s *list, 1.21 - void const *elem 1.22 - ); 1.23 - 1.24 - /** 1.25 - * Member function for inserting an element. 1.26 - */ 1.27 - int (*insert)( 1.28 - cx_list_s *list, 1.29 - size_t index, 1.30 - void const *elem 1.31 - ); 1.32 - 1.33 - /** 1.34 - * Member function for inserting an element relative to an iterator position. 1.35 - */ 1.36 - int (*insert_iter)( 1.37 - CxIterator *iter, 1.38 - void const *elem, 1.39 - int prepend 1.40 - ); 1.41 - 1.42 - /** 1.43 - * Member function for removing an element. 1.44 - */ 1.45 - int (*remove)( 1.46 - cx_list_s *list, 1.47 - size_t index 1.48 - ); 1.49 - 1.50 - /** 1.51 - * Member function for element lookup. 1.52 - */ 1.53 - void *(*at)( 1.54 - cx_list_s const *list, 1.55 - size_t index 1.56 - ); 1.57 - 1.58 - /** 1.59 - * Member function for finding an element. 1.60 - */ 1.61 - size_t (*find)( 1.62 - cx_list_s const *list, 1.63 - void const *elem 1.64 - ); 1.65 - 1.66 - /** 1.67 - * Member function for sorting the list in place. 1.68 - */ 1.69 - void (*sort)(cx_list_s *list); 1.70 - 1.71 - /** 1.72 - * Member function for comparing this list to another list of the same type. 1.73 - */ 1.74 - int (*compare)( 1.75 - cx_list_s const *list, 1.76 - cx_list_s const *other 1.77 - ); 1.78 - 1.79 - /** 1.80 - * Member function for reversing the order of the items. 1.81 - */ 1.82 - void (*reverse)(cx_list_s *list); 1.83 - 1.84 - /** 1.85 - * Returns an iterator pointing to the specified index. 1.86 - */ 1.87 - CxIterator (*iterator)( 1.88 - cx_list_s *list, 1.89 - size_t index 1.90 - ); 1.91 -} cx_list_class; 1.92 +typedef struct cx_list_class_s cx_list_class; 1.93 1.94 /** 1.95 * Structure for holding the base data of a list. 1.96 @@ -150,7 +69,7 @@ 1.97 /** 1.98 * The allocator to use. 1.99 */ 1.100 - CxAllocator allocator; 1.101 + CxAllocator *allocator; 1.102 /** 1.103 * The comparator function for the elements. 1.104 */ 1.105 @@ -170,9 +89,90 @@ 1.106 }; 1.107 1.108 /** 1.109 + * The class definition for arbitrary lists. 1.110 + */ 1.111 +struct cx_list_class_s { 1.112 + /** 1.113 + * Member function for adding an element. 1.114 + */ 1.115 + int (*add)( 1.116 + struct cx_list_s *list, 1.117 + void const *elem 1.118 + ); 1.119 + 1.120 + /** 1.121 + * Member function for inserting an element. 1.122 + */ 1.123 + int (*insert)( 1.124 + struct cx_list_s *list, 1.125 + size_t index, 1.126 + void const *elem 1.127 + ); 1.128 + 1.129 + /** 1.130 + * Member function for inserting an element relative to an iterator position. 1.131 + */ 1.132 + int (*insert_iter)( 1.133 + struct cx_iterator_s *iter, 1.134 + void const *elem, 1.135 + int prepend 1.136 + ); 1.137 + 1.138 + /** 1.139 + * Member function for removing an element. 1.140 + */ 1.141 + int (*remove)( 1.142 + struct cx_list_s *list, 1.143 + size_t index 1.144 + ); 1.145 + 1.146 + /** 1.147 + * Member function for element lookup. 1.148 + */ 1.149 + void *(*at)( 1.150 + struct cx_list_s const *list, 1.151 + size_t index 1.152 + ); 1.153 + 1.154 + /** 1.155 + * Member function for finding an element. 1.156 + */ 1.157 + size_t (*find)( 1.158 + struct cx_list_s const *list, 1.159 + void const *elem 1.160 + ); 1.161 + 1.162 + /** 1.163 + * Member function for sorting the list in place. 1.164 + */ 1.165 + void (*sort)(struct cx_list_s *list); 1.166 + 1.167 + /** 1.168 + * Member function for comparing this list to another list of the same type. 1.169 + */ 1.170 + int (*compare)( 1.171 + struct cx_list_s const *list, 1.172 + struct cx_list_s const *other 1.173 + ); 1.174 + 1.175 + /** 1.176 + * Member function for reversing the order of the items. 1.177 + */ 1.178 + void (*reverse)(struct cx_list_s *list); 1.179 + 1.180 + /** 1.181 + * Returns an iterator pointing to the specified index. 1.182 + */ 1.183 + struct cx_iterator_s (*iterator)( 1.184 + struct cx_list_s *list, 1.185 + size_t index 1.186 + ); 1.187 +}; 1.188 + 1.189 +/** 1.190 * Common type for all list implementations. 1.191 */ 1.192 -typedef cx_list_s *CxList; 1.193 +typedef struct cx_list_s CxList; 1.194 1.195 /** 1.196 * Adds an item to the end of the list. 1.197 @@ -182,7 +182,7 @@ 1.198 * @return zero on success, non-zero on memory allocation failure 1.199 */ 1.200 static inline int cxListAdd( 1.201 - CxList list, 1.202 + CxList *list, 1.203 void const *elem 1.204 ) { 1.205 return list->cl->add(list, elem); 1.206 @@ -202,7 +202,7 @@ 1.207 * @see cxListInsertBefore() 1.208 */ 1.209 static inline int cxListInsert( 1.210 - CxList list, 1.211 + CxList *list, 1.212 size_t index, 1.213 void const *elem 1.214 ) { 1.215 @@ -228,7 +228,7 @@ 1.216 CxIterator *iter, 1.217 void const *elem 1.218 ) { 1.219 - return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); 1.220 + return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); 1.221 } 1.222 1.223 /** 1.224 @@ -250,7 +250,7 @@ 1.225 CxIterator *iter, 1.226 void const *elem 1.227 ) { 1.228 - return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); 1.229 + return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); 1.230 } 1.231 1.232 /** 1.233 @@ -260,7 +260,7 @@ 1.234 * @return zero on success, non-zero if the index is out of bounds 1.235 */ 1.236 static inline int cxListRemove( 1.237 - CxList list, 1.238 + CxList *list, 1.239 size_t index 1.240 ) { 1.241 return list->cl->remove(list, index); 1.242 @@ -274,7 +274,7 @@ 1.243 * @return a pointer to the element or \c NULL if the index is out of bounds 1.244 */ 1.245 static inline void *cxListAt( 1.246 - CxList list, 1.247 + CxList *list, 1.248 size_t index 1.249 ) { 1.250 return list->cl->at(list, index); 1.251 @@ -292,7 +292,7 @@ 1.252 * @return a new iterator 1.253 */ 1.254 static inline CxIterator cxListIterator( 1.255 - CxList list, 1.256 + CxList *list, 1.257 size_t index 1.258 ) { 1.259 return list->cl->iterator(list, index); 1.260 @@ -308,7 +308,7 @@ 1.261 * @param list the list 1.262 * @return a new iterator 1.263 */ 1.264 -static inline CxIterator cxListBegin(CxList list) { 1.265 +static inline CxIterator cxListBegin(CxList *list) { 1.266 return list->cl->iterator(list, 0); 1.267 } 1.268 1.269 @@ -322,7 +322,7 @@ 1.270 * @return the index of the element or \c (size+1) if the element is not found 1.271 */ 1.272 static inline size_t cxListFind( 1.273 - CxList list, 1.274 + CxList *list, 1.275 void const *elem 1.276 ) { 1.277 return list->cl->find(list, elem); 1.278 @@ -335,7 +335,7 @@ 1.279 * 1.280 * @param list the list 1.281 */ 1.282 -static inline void cxListSort(CxList list) { 1.283 +static inline void cxListSort(CxList *list) { 1.284 list->cl->sort(list); 1.285 } 1.286 1.287 @@ -344,7 +344,7 @@ 1.288 * 1.289 * @param list the list 1.290 */ 1.291 -static inline void cxListReverse(CxList list) { 1.292 +static inline void cxListReverse(CxList *list) { 1.293 list->cl->reverse(list); 1.294 } 1.295 1.296 @@ -358,8 +358,8 @@ 1.297 * @return zero, if both lists are equal element wise, negative if the first list is smaller, zero if the first list is larger 1.298 */ 1.299 static inline int cxListCompare( 1.300 - CxList list, 1.301 - CxList other 1.302 + CxList *list, 1.303 + CxList *other 1.304 ) { 1.305 return list->cl->compare(list, other); 1.306 }