116 const void *elem, |
116 const void *elem, |
117 int prepend |
117 int prepend |
118 ); |
118 ); |
119 |
119 |
120 /** |
120 /** |
121 * Member function for removing an element. |
121 * Member function for removing elements. |
122 */ |
122 * |
123 int (*remove)( |
123 * Implementations SHALL check if \p targetbuf is set and copy the elements |
|
124 * to the buffer without invoking any destructor. |
|
125 * When \p targetbuf is not set, the destructors SHALL be invoked. |
|
126 * |
|
127 * The function SHALL return the actual number of elements removed, which |
|
128 * might be lower than \p num when going out of bounds. |
|
129 */ |
|
130 size_t (*remove)( |
124 struct cx_list_s *list, |
131 struct cx_list_s *list, |
125 size_t index |
132 size_t index, |
|
133 size_t num, |
|
134 void *targetbuf |
126 ); |
135 ); |
127 |
136 |
128 /** |
137 /** |
129 * Member function for removing all elements. |
138 * Member function for removing all elements. |
130 */ |
139 */ |
510 __attribute__((__nonnull__)) |
519 __attribute__((__nonnull__)) |
511 static inline int cxListRemove( |
520 static inline int cxListRemove( |
512 CxList *list, |
521 CxList *list, |
513 size_t index |
522 size_t index |
514 ) { |
523 ) { |
515 return list->cl->remove(list, index); |
524 return list->cl->remove(list, index, 1, NULL) == 0; |
|
525 } |
|
526 |
|
527 /** |
|
528 * Removes and returns the element at the specified index. |
|
529 * |
|
530 * No destructor is called and instead the element is copied to the |
|
531 * \p targetbuf which MUST be large enough to hold the removed element. |
|
532 * |
|
533 * @param list the list |
|
534 * @param index the index of the element |
|
535 * @param targetbuf a buffer where to copy the element |
|
536 * @return zero on success, non-zero if the index is out of bounds |
|
537 */ |
|
538 __attribute__((__nonnull__)) |
|
539 static inline int cxListRemoveAndGet( |
|
540 CxList *list, |
|
541 size_t index, |
|
542 void *targetbuf |
|
543 ) { |
|
544 return list->cl->remove(list, index, 1, targetbuf) == 0; |
|
545 } |
|
546 |
|
547 /** |
|
548 * Removes multiple element starting at the specified index. |
|
549 * |
|
550 * If an element destructor function is specified, it is called for each |
|
551 * element. It is guaranteed that the destructor is called before removing |
|
552 * the element, however, due to possible optimizations it is neither guaranteed |
|
553 * that the destructors are invoked for all elements before starting to remove |
|
554 * them, nor that the element is removed immediately after the destructor call |
|
555 * before proceeding to the next element. |
|
556 * |
|
557 * @param list the list |
|
558 * @param index the index of the element |
|
559 * @param num the number of elements to remove |
|
560 * @return the actual number of removed elements |
|
561 */ |
|
562 __attribute__((__nonnull__)) |
|
563 static inline size_t cxListRemoveArray( |
|
564 CxList *list, |
|
565 size_t index, |
|
566 size_t num |
|
567 ) { |
|
568 return list->cl->remove(list, index, num, NULL); |
|
569 } |
|
570 |
|
571 /** |
|
572 * Removes and returns multiple element starting at the specified index. |
|
573 * |
|
574 * No destructor is called and instead the elements are copied to the |
|
575 * \p targetbuf which MUST be large enough to hold all removed elements. |
|
576 * |
|
577 * @param list the list |
|
578 * @param index the index of the element |
|
579 * @param num the number of elements to remove |
|
580 * @param targetbuf a buffer where to copy the elements |
|
581 * @return the actual number of removed elements |
|
582 */ |
|
583 __attribute__((__nonnull__)) |
|
584 static inline size_t cxListRemoveArrayAndGet( |
|
585 CxList *list, |
|
586 size_t index, |
|
587 size_t num, |
|
588 void *targetbuf |
|
589 ) { |
|
590 return list->cl->remove(list, index, num, targetbuf); |
516 } |
591 } |
517 |
592 |
518 /** |
593 /** |
519 * Removes all elements from this list. |
594 * Removes all elements from this list. |
520 * |
595 * |