2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * @defgroup iterator iterator
30 typedef struct iterator_t iterator_t
;
33 * Iterator interface, allows iteration over collections.
35 * iterator_t defines an interface for iterating over collections.
36 * It allows searching, deleting, updating and inserting.
38 * @deprecated Use enumerator instead.
43 * Return number of list items.
45 * @return number of list items
47 int (*get_count
) (iterator_t
*this);
50 * Iterate over all items.
52 * The easy way to iterate over items.
55 * @return TRUE, if there was an element available, FALSE otherwise
57 bool (*iterate
) (iterator_t
*this, void** value
);
60 * Inserts a new item before the given iterator position.
62 * The iterator position is not changed after inserting
64 * @param item value to insert in list
66 void (*insert_before
) (iterator_t
*this, void *item
);
69 * Inserts a new item after the given iterator position.
71 * The iterator position is not changed after inserting.
73 * @param this calling iterator
74 * @param item value to insert in list
76 void (*insert_after
) (iterator_t
*this, void *item
);
79 * Replace the current item at current iterator position.
81 * The iterator position is not changed after replacing.
83 * @param this calling iterator
84 * @param old old value will be written here(can be NULL)
85 * @param new new value
86 * @return SUCCESS, FAILED if iterator is on an invalid position
88 status_t (*replace
) (iterator_t
*this, void **old
, void *new);
91 * Removes an element from list at the given iterator position.
93 * The iterator is set the the following position:
94 * - to the item before, if available
95 * - it gets reseted, otherwise
97 * @return SUCCESS, FAILED if iterator is on an invalid position
99 status_t (*remove
) (iterator_t
*this);
102 * Resets the iterator position.
104 * After reset, the iterator_t objects doesn't point to an element.
105 * A call to iterator_t.has_next is necessary to do any other operations
106 * with the resetted iterator.
108 void (*reset
) (iterator_t
*this);
111 * Destroys an iterator.
113 void (*destroy
) (iterator_t
*this);
116 #endif /*ITERATOR_H_ @} */