Removed unneeded and confusing insert_after method from linked_list_t.
[strongswan.git] / src / libstrongswan / utils / iterator.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
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>.
10 *
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
14 * for more details.
15 */
16
17 /**
18 * @defgroup iterator iterator
19 * @{ @ingroup utils
20 */
21
22 #ifndef ITERATOR_H_
23 #define ITERATOR_H_
24
25 #include <library.h>
26
27
28 typedef struct iterator_t iterator_t;
29
30 /**
31 * Iterator interface, allows iteration over collections.
32 *
33 * iterator_t defines an interface for iterating over collections.
34 * It allows searching, deleting, updating and inserting.
35 *
36 * @deprecated Use enumerator instead.
37 */
38 struct iterator_t {
39
40 /**
41 * Return number of list items.
42 *
43 * @return number of list items
44 */
45 int (*get_count) (iterator_t *this);
46
47 /**
48 * Iterate over all items.
49 *
50 * The easy way to iterate over items.
51 *
52 * @param value item
53 * @return TRUE, if there was an element available, FALSE otherwise
54 */
55 bool (*iterate) (iterator_t *this, void** value);
56
57 /**
58 * Inserts a new item before the given iterator position.
59 *
60 * The iterator position is not changed after inserting
61 *
62 * @param item value to insert in list
63 */
64 void (*insert_before) (iterator_t *this, void *item);
65
66 /**
67 * Inserts a new item after the given iterator position.
68 *
69 * The iterator position is not changed after inserting.
70 *
71 * @param item value to insert in list
72 */
73 void (*insert_after) (iterator_t *this, void *item);
74
75 /**
76 * Replace the current item at current iterator position.
77 *
78 * The iterator position is not changed after replacing.
79 *
80 * @param old old value will be written here(can be NULL)
81 * @param new new value
82 * @return SUCCESS, FAILED if iterator is on an invalid position
83 */
84 status_t (*replace) (iterator_t *this, void **old, void *new);
85
86 /**
87 * Removes an element from list at the given iterator position.
88 *
89 * The iterator is set the the following position:
90 * - to the item before, if available
91 * - it gets reseted, otherwise
92 *
93 * @return SUCCESS, FAILED if iterator is on an invalid position
94 */
95 status_t (*remove) (iterator_t *this);
96
97 /**
98 * Resets the iterator position.
99 *
100 * After reset, the iterator_t objects doesn't point to an element.
101 * A call to iterator_t.has_next is necessary to do any other operations
102 * with the resetted iterator.
103 */
104 void (*reset) (iterator_t *this);
105
106 /**
107 * Destroys an iterator.
108 */
109 void (*destroy) (iterator_t *this);
110 };
111
112 #endif /** ITERATOR_H_ @}*/