src/cx/list.h

changeset 499
3dc9075df822
parent 495
2856c74e18ba
child 500
eb9e7bd40a8e
equal deleted inserted replaced
498:435c9965b2dd 499:3dc9075df822
78 size_t index, 78 size_t index,
79 void const *elem 79 void const *elem
80 ); 80 );
81 81
82 /** 82 /**
83 * Member function for inserting an element relative to an iterator position.
84 */
85 int (*insert_iter)(
86 CxIterator *iter,
87 void const *elem,
88 int prepend
89 );
90
91 /**
83 * Member function for removing an element. 92 * Member function for removing an element.
84 */ 93 */
85 int (*remove)( 94 int (*remove)(
86 cx_list_s *list, 95 cx_list_s *list,
87 size_t index 96 size_t index
166 typedef cx_list_s *CxList; 175 typedef cx_list_s *CxList;
167 176
168 /** 177 /**
169 * Adds an item to the end of the list. 178 * Adds an item to the end of the list.
170 * 179 *
171 * \remark It is implementation defined whether
172 * the contents of the element are copied or the
173 * pointer is added to the list. In the latter case
174 * the \c itemsize of the list SHALL be \c sizeof(void*).
175 *
176 * @param list the list 180 * @param list the list
177 * @param elem a pointer to the element to add 181 * @param elem a pointer to the element to add
178 * @return zero on success, non-zero on memory allocation failure 182 * @return zero on success, non-zero on memory allocation failure
179 */ 183 */
180 static inline int cxListAdd( 184 static inline int cxListAdd(
186 190
187 /** 191 /**
188 * Inserts an item at the specified index. 192 * Inserts an item at the specified index.
189 * 193 *
190 * If \p index equals the list \c size, this is effectively cxListAdd(). 194 * If \p index equals the list \c size, this is effectively cxListAdd().
191 *
192 * \remark It is implementation defined whether
193 * the contents of the element are copied or the
194 * pointer is added to the list. In the latter case
195 * the \c itemsize of the list SHALL be \c sizeof(void*).
196 * 195 *
197 * @param list the list 196 * @param list the list
198 * @param index the index the element shall have 197 * @param index the index the element shall have
199 * @param elem a pointer to the element to add 198 * @param elem a pointer to the element to add
200 * @return zero on success, non-zero on memory allocation failure 199 * @return zero on success, non-zero on memory allocation failure
201 * or when the index is out of bounds 200 * or when the index is out of bounds
201 * @see cxListInsertAfter()
202 * @see cxListInsertBefore()
202 */ 203 */
203 static inline int cxListInsert( 204 static inline int cxListInsert(
204 CxList list, 205 CxList list,
205 size_t index, 206 size_t index,
206 void const *elem 207 void const *elem
207 ) { 208 ) {
208 return list->cl->insert(list, index, elem); 209 return list->cl->insert(list, index, elem);
210 }
211
212 /**
213 * Inserts an element after the current location of the specified iterator.
214 *
215 * The used iterator remains operational, but all other active iterators should
216 * be considered invalidated.
217 *
218 * If \p iter is not a list iterator, the behavior is undefined.
219 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
220 *
221 * @param iter an iterator
222 * @param elem the element to insert
223 * @return zero on success, non-zero on memory allocation failure
224 * @see cxListInsert()
225 * @see cxListInsertBefore()
226 */
227 static inline int cxListInsertAfter(
228 CxIterator *iter,
229 void const *elem
230 ) {
231 return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
232 }
233
234 /**
235 * Inserts an element before the current location of the specified iterator.
236 *
237 * The used iterator remains operational, but all other active iterators should
238 * be considered invalidated.
239 *
240 * If \p iter is not a list iterator, the behavior is undefined.
241 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
242 *
243 * @param iter an iterator
244 * @param elem the element to insert
245 * @return zero on success, non-zero on memory allocation failure
246 * @see cxListInsert()
247 * @see cxListInsertAfter()
248 */
249 static inline int cxListInsertBefore(
250 CxIterator *iter,
251 void const *elem
252 ) {
253 return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
209 } 254 }
210 255
211 /** 256 /**
212 * Removes the element at the specified index. 257 * Removes the element at the specified index.
213 * @param list the list 258 * @param list the list

mercurial