| 78 */ |
78 */ |
| 79 void (*deallocate)(struct cx_list_s *list); |
79 void (*deallocate)(struct cx_list_s *list); |
| 80 |
80 |
| 81 /** |
81 /** |
| 82 * Member function for inserting a single element. |
82 * Member function for inserting a single element. |
| 83 */ |
83 * The data pointer may be @c NULL in which case the function shall only allocate memory. |
| 84 int (*insert_element)( |
84 * Returns a pointer to the data of the inserted element. |
| |
85 */ |
| |
86 void *(*insert_element)( |
| 85 struct cx_list_s *list, |
87 struct cx_list_s *list, |
| 86 size_t index, |
88 size_t index, |
| 87 const void *data |
89 const void *data |
| 88 ); |
90 ); |
| 89 |
91 |
| 368 * @param list the list |
370 * @param list the list |
| 369 * @param elem a pointer to the element to add |
371 * @param elem a pointer to the element to add |
| 370 * @retval zero success |
372 * @retval zero success |
| 371 * @retval non-zero memory allocation failure |
373 * @retval non-zero memory allocation failure |
| 372 * @see cxListAddArray() |
374 * @see cxListAddArray() |
| |
375 * @see cxListEmplace() |
| 373 */ |
376 */ |
| 374 cx_attr_nonnull |
377 cx_attr_nonnull |
| 375 static inline int cxListAdd( |
378 static inline int cxListAdd( |
| 376 CxList *list, |
379 CxList *list, |
| 377 const void *elem |
380 const void *elem |
| 378 ) { |
381 ) { |
| 379 list->collection.sorted = false; |
382 list->collection.sorted = false; |
| 380 return list->cl->insert_element(list, list->collection.size, elem); |
383 return list->cl->insert_element(list, list->collection.size, elem) == NULL; |
| 381 } |
384 } |
| 382 |
385 |
| 383 /** |
386 /** |
| 384 * Adds multiple items to the end of the list. |
387 * Adds multiple items to the end of the list. |
| 385 * |
388 * |
| 416 * @param elem a pointer to the element to add |
419 * @param elem a pointer to the element to add |
| 417 * @retval zero success |
420 * @retval zero success |
| 418 * @retval non-zero memory allocation failure or the index is out of bounds |
421 * @retval non-zero memory allocation failure or the index is out of bounds |
| 419 * @see cxListInsertAfter() |
422 * @see cxListInsertAfter() |
| 420 * @see cxListInsertBefore() |
423 * @see cxListInsertBefore() |
| |
424 * @see cxListEmplaceAt() |
| 421 */ |
425 */ |
| 422 cx_attr_nonnull |
426 cx_attr_nonnull |
| 423 static inline int cxListInsert( |
427 static inline int cxListInsert( |
| 424 CxList *list, |
428 CxList *list, |
| 425 size_t index, |
429 size_t index, |
| 426 const void *elem |
430 const void *elem |
| 427 ) { |
431 ) { |
| 428 list->collection.sorted = false; |
432 list->collection.sorted = false; |
| 429 return list->cl->insert_element(list, index, elem); |
433 return list->cl->insert_element(list, index, elem) == NULL; |
| |
434 } |
| |
435 |
| |
436 /** |
| |
437 * Allocates memory for an element at the specified index and returns a pointer to that memory. |
| |
438 * |
| |
439 * @remark When the list is storing pointers, this will return a @c void**. |
| |
440 * |
| |
441 * @param list the list |
| |
442 * @param index the index where to emplace the element |
| |
443 * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
| |
444 * @see cxListEmplace() |
| |
445 * @see cxListInsert() |
| |
446 */ |
| |
447 cx_attr_nonnull |
| |
448 static inline void *cxListEmplaceAt(CxList *list, size_t index) { |
| |
449 list->collection.sorted = false; |
| |
450 return list->cl->insert_element(list, index, NULL); |
| |
451 } |
| |
452 |
| |
453 |
| |
454 /** |
| |
455 * Allocates memory for an element at the end of the list and returns a pointer to that memory. |
| |
456 * |
| |
457 * @remark When the list is storing pointers, this will return a @c void**. |
| |
458 * |
| |
459 * @param list the list |
| |
460 * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
| |
461 * @see cxListEmplaceAt() |
| |
462 * @see cxListAdd() |
| |
463 */ |
| |
464 cx_attr_nonnull |
| |
465 static inline void *cxListEmplace(CxList *list) { |
| |
466 list->collection.sorted = false; |
| |
467 return list->cl->insert_element(list, list->collection.size, NULL); |
| 430 } |
468 } |
| 431 |
469 |
| 432 /** |
470 /** |
| 433 * Inserts an item into a sorted list. |
471 * Inserts an item into a sorted list. |
| 434 * |
472 * |