4 * @brief Interface iterator_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 typedef struct iterator_t iterator_t
;
29 * @brief Iterator interface, allows iteration over collections.
31 * iterator_t defines an interface for iterating over collections.
32 * It allows searching, deleting, updating and inserting.
39 * Moves to the next element, if available.
41 * @param this calling object
43 * - TRUE, if more elements are avaiable,
46 bool (*has_next
) (iterator_t
*this);
49 * Returns the current value at the iterator position.
51 * @param this calling object
52 * @param [out]value value is set to the current value at iterator position
55 * - FAILED if list is empty
57 status_t (*current
) (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 this calling iterator
65 * @param [in]item value to insert in list
70 status_t (*insert_before
) (iterator_t
*this, void *item
);
73 * Inserts a new item after the given iterator position.
75 * The iterator position is not changed after inserting.
77 * @param this calling iterator
78 * @param [in]item value to insert in list
83 status_t (*insert_after
) (iterator_t
*this, void *item
);
86 * @brief removes an element from list at the given iterator position.
88 * The position of the iterator is set in the following order:
89 * - to the item before, if available
90 * - otherwise to the item after, if available
91 * - otherwise it gets reseted
93 * @param linked_list calling object
98 status_t (*remove
) (iterator_t
*iterator
);
101 * @brief Resets the iterator position.
103 * After reset, the iterator stands NOT on an element.
104 * A call to has_next is necessary to do any other operations
105 * with the resetted iterator.
107 * @param this calling object
108 * @return SUCCESS in any case
110 status_t (*reset
) (iterator_t
*this);
113 * @brief Destroys an iterator.
115 * @param this iterator to destroy
116 * @return SUCCESS in any case
119 status_t (*destroy
) (iterator_t
*this);
122 #endif /*ITERATOR_H_*/