1.1 --- a/src/cx/list.h Sat Jan 29 12:46:07 2022 +0100 1.2 +++ b/src/cx/list.h Sat Jan 29 14:32:04 2022 +0100 1.3 @@ -80,6 +80,15 @@ 1.4 ); 1.5 1.6 /** 1.7 + * Member function for inserting an element relative to an iterator position. 1.8 + */ 1.9 + int (*insert_iter)( 1.10 + CxIterator *iter, 1.11 + void const *elem, 1.12 + int prepend 1.13 + ); 1.14 + 1.15 + /** 1.16 * Member function for removing an element. 1.17 */ 1.18 int (*remove)( 1.19 @@ -168,11 +177,6 @@ 1.20 /** 1.21 * Adds an item to the end of the list. 1.22 * 1.23 - * \remark It is implementation defined whether 1.24 - * the contents of the element are copied or the 1.25 - * pointer is added to the list. In the latter case 1.26 - * the \c itemsize of the list SHALL be \c sizeof(void*). 1.27 - * 1.28 * @param list the list 1.29 * @param elem a pointer to the element to add 1.30 * @return zero on success, non-zero on memory allocation failure 1.31 @@ -189,16 +193,13 @@ 1.32 * 1.33 * If \p index equals the list \c size, this is effectively cxListAdd(). 1.34 * 1.35 - * \remark It is implementation defined whether 1.36 - * the contents of the element are copied or the 1.37 - * pointer is added to the list. In the latter case 1.38 - * the \c itemsize of the list SHALL be \c sizeof(void*). 1.39 - * 1.40 * @param list the list 1.41 * @param index the index the element shall have 1.42 * @param elem a pointer to the element to add 1.43 * @return zero on success, non-zero on memory allocation failure 1.44 * or when the index is out of bounds 1.45 + * @see cxListInsertAfter() 1.46 + * @see cxListInsertBefore() 1.47 */ 1.48 static inline int cxListInsert( 1.49 CxList list, 1.50 @@ -209,6 +210,50 @@ 1.51 } 1.52 1.53 /** 1.54 + * Inserts an element after the current location of the specified iterator. 1.55 + * 1.56 + * The used iterator remains operational, but all other active iterators should 1.57 + * be considered invalidated. 1.58 + * 1.59 + * If \p iter is not a list iterator, the behavior is undefined. 1.60 + * If \p iter is a past-the-end iterator, the new element gets appended to the list. 1.61 + * 1.62 + * @param iter an iterator 1.63 + * @param elem the element to insert 1.64 + * @return zero on success, non-zero on memory allocation failure 1.65 + * @see cxListInsert() 1.66 + * @see cxListInsertBefore() 1.67 + */ 1.68 +static inline int cxListInsertAfter( 1.69 + CxIterator *iter, 1.70 + void const *elem 1.71 +) { 1.72 + return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); 1.73 +} 1.74 + 1.75 +/** 1.76 + * Inserts an element before the current location of the specified iterator. 1.77 + * 1.78 + * The used iterator remains operational, but all other active iterators should 1.79 + * be considered invalidated. 1.80 + * 1.81 + * If \p iter is not a list iterator, the behavior is undefined. 1.82 + * If \p iter is a past-the-end iterator, the new element gets appended to the list. 1.83 + * 1.84 + * @param iter an iterator 1.85 + * @param elem the element to insert 1.86 + * @return zero on success, non-zero on memory allocation failure 1.87 + * @see cxListInsert() 1.88 + * @see cxListInsertAfter() 1.89 + */ 1.90 +static inline int cxListInsertBefore( 1.91 + CxIterator *iter, 1.92 + void const *elem 1.93 +) { 1.94 + return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); 1.95 +} 1.96 + 1.97 +/** 1.98 * Removes the element at the specified index. 1.99 * @param list the list 1.100 * @param index the index of the element