src/cx/list.h

changeset 630
ac5e7f789048
parent 629
6c81ee4f11ad
child 638
eafb45eefc51
equal deleted inserted replaced
629:6c81ee4f11ad 630:ac5e7f789048
149 149
150 /** 150 /**
151 * Member function for inserting an element relative to an iterator position. 151 * Member function for inserting an element relative to an iterator position.
152 */ 152 */
153 int (*insert_iter)( 153 int (*insert_iter)(
154 struct cx_iterator_s *iter, 154 struct cx_mut_iterator_s *iter,
155 void const *elem, 155 void const *elem,
156 int prepend 156 int prepend
157 ); 157 );
158 158
159 /** 159 /**
200 200
201 /** 201 /**
202 * Returns an iterator pointing to the specified index. 202 * Returns an iterator pointing to the specified index.
203 */ 203 */
204 struct cx_iterator_s (*iterator)( 204 struct cx_iterator_s (*iterator)(
205 struct cx_list_s const *list,
206 size_t index
207 );
208
209 /**
210 * Returns a mutating iterator pointing to the specified index.
211 */
212 struct cx_mut_iterator_s (*mut_iterator)(
205 struct cx_list_s *list, 213 struct cx_list_s *list,
206 size_t index 214 size_t index
207 ); 215 );
208 }; 216 };
209 217
287 * @see cxListInsert() 295 * @see cxListInsert()
288 * @see cxListInsertBefore() 296 * @see cxListInsertBefore()
289 */ 297 */
290 __attribute__((__nonnull__)) 298 __attribute__((__nonnull__))
291 static inline int cxListInsertAfter( 299 static inline int cxListInsertAfter(
292 CxIterator *iter, 300 CxMutIterator *iter,
293 void const *elem 301 void const *elem
294 ) { 302 ) {
295 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); 303 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
296 } 304 }
297 305
310 * @see cxListInsert() 318 * @see cxListInsert()
311 * @see cxListInsertAfter() 319 * @see cxListInsertAfter()
312 */ 320 */
313 __attribute__((__nonnull__)) 321 __attribute__((__nonnull__))
314 static inline int cxListInsertBefore( 322 static inline int cxListInsertBefore(
315 CxIterator *iter, 323 CxMutIterator *iter,
316 void const *elem 324 void const *elem
317 ) { 325 ) {
318 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); 326 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
319 } 327 }
320 328
358 * @param index the index where the iterator shall point at 366 * @param index the index where the iterator shall point at
359 * @return a new iterator 367 * @return a new iterator
360 */ 368 */
361 __attribute__((__nonnull__, __warn_unused_result__)) 369 __attribute__((__nonnull__, __warn_unused_result__))
362 static inline CxIterator cxListIterator( 370 static inline CxIterator cxListIterator(
363 CxList *list, 371 CxList const *list,
364 size_t index 372 size_t index
365 ) { 373 ) {
366 return list->cl->iterator(list, index); 374 return list->cl->iterator(list, index);
367 } 375 }
368 376
369 /** 377 /**
378 * Returns a mutating iterator pointing to the item at the specified index.
379 *
380 * The returned iterator is position-aware.
381 *
382 * If the index is out of range, a past-the-end iterator will be returned.
383 *
384 * @param list the list
385 * @param index the index where the iterator shall point at
386 * @return a new iterator
387 */
388 __attribute__((__nonnull__, __warn_unused_result__))
389 static inline CxMutIterator cxListMutIterator(
390 CxList *list,
391 size_t index
392 ) {
393 return list->cl->mut_iterator(list, index);
394 }
395
396 /**
370 * Returns an iterator pointing to the first item of the list. 397 * Returns an iterator pointing to the first item of the list.
371 * 398 *
372 * The returned iterator is position-aware. 399 * The returned iterator is position-aware.
373 * 400 *
374 * If the list is empty, a past-the-end iterator will be returned. 401 * If the list is empty, a past-the-end iterator will be returned.
375 * 402 *
376 * @param list the list 403 * @param list the list
377 * @return a new iterator 404 * @return a new iterator
378 */ 405 */
379 __attribute__((__nonnull__, __warn_unused_result__)) 406 __attribute__((__nonnull__, __warn_unused_result__))
380 static inline CxIterator cxListBegin(CxList *list) { 407 static inline CxIterator cxListBegin(CxList const *list) {
381 return list->cl->iterator(list, 0); 408 return list->cl->iterator(list, 0);
409 }
410
411 /**
412 * Returns a mutating iterator pointing to the first item of the list.
413 *
414 * The returned iterator is position-aware.
415 *
416 * If the list is empty, a past-the-end iterator will be returned.
417 *
418 * @param list the list
419 * @return a new iterator
420 */
421 __attribute__((__nonnull__, __warn_unused_result__))
422 static inline CxMutIterator cxListBeginMut(CxList *list) {
423 return list->cl->mut_iterator(list, 0);
382 } 424 }
383 425
384 /** 426 /**
385 * Returns the index of the first element that equals \p elem. 427 * Returns the index of the first element that equals \p elem.
386 * 428 *

mercurial