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 iterator on an invalid position
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
67 void (*insert_before
) (iterator_t
*this, void *item
);
70 * @brief Inserts a new item after the given iterator position.
72 * The iterator position is not changed after inserting.
74 * @param this calling iterator
75 * @param[in] item value to insert in list
77 void (*insert_after
) (iterator_t
*this, void *item
);
80 * @brief removes an element from list at the given iterator position.
82 * The position of the iterator is set in the following order:
83 * - to the item before, if available
84 * - otherwise to the item after, if available
85 * - otherwise it gets reseted
87 * @param linked_list calling object
90 * - FAILED if iterator is on an invalid position
92 status_t (*remove
) (iterator_t
*iterator
);
95 * @brief Resets the iterator position.
97 * After reset, the iterator stands NOT on an element.
98 * A call to has_next is necessary to do any other operations
99 * with the resetted iterator.
101 * @param this calling object
102 * @return SUCCESS in any case
104 void (*reset
) (iterator_t
*this);
107 * @brief Destroys an iterator.
109 * @param this iterator to destroy
110 * @return SUCCESS in any case
113 void (*destroy
) (iterator_t
*this);
116 #endif /*ITERATOR_H_*/