| 126 ) { |
126 ) { |
| 127 void **ptr = list->climpl->at(list, index); |
127 void **ptr = list->climpl->at(list, index); |
| 128 return ptr == NULL ? NULL : *ptr; |
128 return ptr == NULL ? NULL : *ptr; |
| 129 } |
129 } |
| 130 |
130 |
| 131 static ssize_t cx_pl_find_remove( |
131 static size_t cx_pl_find_remove( |
| 132 struct cx_list_s *list, |
132 struct cx_list_s *list, |
| 133 const void *elem, |
133 const void *elem, |
| 134 bool remove |
134 bool remove |
| 135 ) { |
135 ) { |
| 136 cx_pl_hack_cmpfunc(list); |
136 cx_pl_hack_cmpfunc(list); |
| 137 ssize_t ret = list->climpl->find_remove(list, &elem, remove); |
137 size_t ret = list->climpl->find_remove(list, &elem, remove); |
| 138 cx_pl_unhack_cmpfunc(list); |
138 cx_pl_unhack_cmpfunc(list); |
| 139 return ret; |
139 return ret; |
| 140 } |
140 } |
| 141 |
141 |
| 142 static void cx_pl_sort(struct cx_list_s *list) { |
142 static void cx_pl_sort(struct cx_list_s *list) { |
| 190 cx_pl_sort, |
190 cx_pl_sort, |
| 191 cx_pl_compare, |
191 cx_pl_compare, |
| 192 cx_pl_reverse, |
192 cx_pl_reverse, |
| 193 cx_pl_iterator, |
193 cx_pl_iterator, |
| 194 }; |
194 }; |
| 195 |
|
| 196 void cxListStoreObjects(CxList *list) { |
|
| 197 list->collection.store_pointer = false; |
|
| 198 if (list->climpl != NULL) { |
|
| 199 list->cl = list->climpl; |
|
| 200 list->climpl = NULL; |
|
| 201 } |
|
| 202 } |
|
| 203 |
|
| 204 void cxListStorePointers(CxList *list) { |
|
| 205 list->collection.elem_size = sizeof(void *); |
|
| 206 list->collection.store_pointer = true; |
|
| 207 list->climpl = list->cl; |
|
| 208 list->cl = &cx_pointer_list_class; |
|
| 209 } |
|
| 210 |
|
| 211 // </editor-fold> |
195 // </editor-fold> |
| 212 |
196 |
| 213 // <editor-fold desc="empty list implementation"> |
197 // <editor-fold desc="empty list implementation"> |
| 214 |
198 |
| 215 static void cx_emptyl_noop(cx_attr_unused CxList *list) { |
199 static void cx_emptyl_noop(cx_attr_unused CxList *list) { |
| 221 cx_attr_unused size_t index |
205 cx_attr_unused size_t index |
| 222 ) { |
206 ) { |
| 223 return NULL; |
207 return NULL; |
| 224 } |
208 } |
| 225 |
209 |
| 226 static ssize_t cx_emptyl_find_remove( |
210 static size_t cx_emptyl_find_remove( |
| 227 cx_attr_unused struct cx_list_s *list, |
211 cx_attr_unused struct cx_list_s *list, |
| 228 cx_attr_unused const void *elem, |
212 cx_attr_unused const void *elem, |
| 229 cx_attr_unused bool remove |
213 cx_attr_unused bool remove |
| 230 ) { |
214 ) { |
| 231 return -1; |
215 return 0; |
| 232 } |
216 } |
| 233 |
217 |
| 234 static bool cx_emptyl_iter_valid(cx_attr_unused const void *iter) { |
218 static bool cx_emptyl_iter_valid(cx_attr_unused const void *iter) { |
| 235 return false; |
219 return false; |
| 236 } |
220 } |
| 413 memcpy(jp, tmp, elem_size); |
398 memcpy(jp, tmp, elem_size); |
| 414 |
399 |
| 415 free(tmp); |
400 free(tmp); |
| 416 |
401 |
| 417 return 0; |
402 return 0; |
| |
403 } |
| |
404 |
| |
405 void cx_list_init( |
| |
406 struct cx_list_s *list, |
| |
407 struct cx_list_class_s *cl, |
| |
408 const struct cx_allocator_s *allocator, |
| |
409 cx_compare_func comparator, |
| |
410 size_t elem_size |
| |
411 ) { |
| |
412 list->cl = cl; |
| |
413 list->collection.allocator = allocator; |
| |
414 list->collection.cmpfunc = comparator; |
| |
415 if (elem_size > 0) { |
| |
416 list->collection.elem_size = elem_size; |
| |
417 } else { |
| |
418 list->collection.elem_size = sizeof(void *); |
| |
419 if (list->collection.cmpfunc == NULL) { |
| |
420 list->collection.cmpfunc = cx_cmp_ptr; |
| |
421 } |
| |
422 list->collection.store_pointer = true; |
| |
423 list->climpl = list->cl; |
| |
424 list->cl = &cx_pointer_list_class; |
| |
425 } |
| 418 } |
426 } |
| 419 |
427 |
| 420 int cxListCompare( |
428 int cxListCompare( |
| 421 const CxList *list, |
429 const CxList *list, |
| 422 const CxList *other |
430 const CxList *other |