]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - programs/charon/lib/utils/iterator.h
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.
34 * Thanks to JMP for iterator lessons :-)
37 * - via linked_list_t.create_iterator, or
38 * - any other class which supports the iterator_t interface
47 * @brief Iterate over all items.
49 * The easy way to iterate over items.
51 * @param this calling object
52 * @param[out] value item
54 * - TRUE, if more elements are avaiable,
57 bool (*iterate
) (iterator_t
*this, void** value
);
60 * @brief Moves to the next element, if available.
62 * A newly created iterator_t object doesn't point to any item.
63 * Call iterator_t.has_next first to point it to the first item.
65 * @param this calling object
67 * - TRUE, if more elements are avaiable,
70 bool (*has_next
) (iterator_t
*this);
73 * @brief Returns the current value at the iterator position.
75 * @param this calling object
76 * @param[out] value value is set to the current value at iterator position
79 * - FAILED if iterator on an invalid position
81 status_t (*current
) (iterator_t
*this, void **value
);
84 * @brief Inserts a new item before the given iterator position.
86 * The iterator position is not changed after inserting
88 * @param this calling iterator
89 * @param[in] item value to insert in list
91 void (*insert_before
) (iterator_t
*this, void *item
);
94 * @brief Inserts a new item after the given iterator position.
96 * The iterator position is not changed after inserting.
98 * @param this calling iterator
99 * @param[in] item value to insert in list
101 void (*insert_after
) (iterator_t
*this, void *item
);
104 * @brief Replace the current item at current iterator position.
106 * The iterator position is not changed after replacing.
108 * @param this calling iterator
109 * @param[out] old_item old value will be written here(can be NULL)
110 * @param[in] new_item new value
114 * - FAILED if iterator is on an invalid position
116 status_t (*replace
) (iterator_t
*this, void **old_item
, void *new_item
);
119 * @brief Removes an element from list at the given iterator position.
121 * The position of the iterator is set in the following order:
122 * - to the item before, if available
123 * - otherwise to the item after, if available
124 * - otherwise it gets reseted
126 * @param linked_list calling object
129 * - FAILED if iterator is on an invalid position
131 status_t (*remove
) (iterator_t
*iterator
);
134 * @brief Resets the iterator position.
136 * After reset, the iterator_t objects doesn't point to an element.
137 * A call to iterator_t.has_next is necessary to do any other operations
138 * with the resetted iterator.
140 * @param this calling object
142 void (*reset
) (iterator_t
*this);
145 * @brief Destroys an iterator.
147 * @param this iterator to destroy
150 void (*destroy
) (iterator_t
*this);
153 #endif /*ITERATOR_H_*/