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.
38 * @brief Moves to the next element, if available.
40 * @param this calling object
42 * - TRUE, if more elements are avaiable,
45 bool (*has_next
) (iterator_t
*this);
48 * @brief Returns the current value at the iterator position.
50 * @param this calling object
51 * @param [out]value value is set to the current value at iterator position
54 * - FAILED if iterator is on an invalid state
56 status_t (*current
) (iterator_t
*this, void **value
);
59 * @brief Inserts a new item before the given iterator position.
61 * The iterator position is not changed after inserting
63 * @param this calling iterator
64 * @param [in]item value to insert in list
66 * - SUCCESS if succeeded,
69 status_t (*insert_before
) (iterator_t
*this, void *item
);
72 * @brief Inserts a new item after the given iterator position.
74 * The iterator position is not changed after inserting.
76 * @param this calling iterator
77 * @param [in]item value to insert in list
79 * - SUCCESS if succeeded,
82 status_t (*insert_after
) (iterator_t
*this, void *item
);
85 * @brief removes an element from list at the given iterator position.
87 * The position of the iterator is set in the following order:
88 * - to the item before, if available
89 * - otherwise to the item after, if available
90 * - otherwise it gets reseted
92 * @param linked_list calling object
94 * - SUCCESS if succeeded,
97 status_t (*remove
) (iterator_t
*iterator
);
100 * @brief Resets the iterator position.
102 * After reset, the iterator stands NOT on an element.
103 * A call to has_next is necessary to do any other operations
104 * with the resetted iterator.
106 * @param this calling object
108 * - SUCCESS if succeeded,
111 status_t (*reset
) (iterator_t
*this);
114 * @brief Destroys an iterator.
116 * @param this iterator to destroy
118 * - SUCCESS if succeeded,
121 status_t (*destroy
) (iterator_t
*this);
124 #endif /*ITERATOR_H_*/