diff options
author | Martin Willi <martin@strongswan.org> | 2005-11-24 14:22:29 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2005-11-24 14:22:29 +0000 |
commit | bdb141cb4b7bffcdd6358b0fd4606d146816261a (patch) | |
tree | f199e7afa93f1c146af5aa59a59b285609e68d39 /Source/charon/utils/iterator.h | |
parent | 49a72ce3943adcf87a080a734adcdecb8efca5ed (diff) | |
download | strongswan-bdb141cb4b7bffcdd6358b0fd4606d146816261a.tar.bz2 strongswan-bdb141cb4b7bffcdd6358b0fd4606d146816261a.tar.xz |
- moved linked_list_iterator_t to iterator_t, located in iterator.h
Diffstat (limited to 'Source/charon/utils/iterator.h')
-rw-r--r-- | Source/charon/utils/iterator.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Source/charon/utils/iterator.h b/Source/charon/utils/iterator.h new file mode 100644 index 000000000..17deb630c --- /dev/null +++ b/Source/charon/utils/iterator.h @@ -0,0 +1,124 @@ +/** + * @file iterator.h + * + * @brief Interface iterator_t. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef ITERATOR_H_ +#define ITERATOR_H_ + +typedef struct iterator_t iterator_t; + +/** + * @brief Iterator interface, allows iteration over collections. + * + * iterator_t defines an interface for iterating over collections. + * It allows searching, deleting, updating and inserting. + * + */ +struct iterator_t { + + /** + * @brief Moves to the next element, if available. + * + * @param this calling object + * @return + * - TRUE, if more elements are avaiable, + * - FALSE otherwise + */ + bool (*has_next) (iterator_t *this); + + /** + * @brief Returns the current value at the iterator position. + * + * @param this calling object + * @param [out]value value is set to the current value at iterator position + * @return + * - SUCCESS, or + * - FAILED if iterator is on an invalid state + */ + status_t (*current) (iterator_t *this, void **value); + + /** + * @brief Inserts a new item before the given iterator position. + * + * The iterator position is not changed after inserting + * + * @param this calling iterator + * @param [in]item value to insert in list + * @return + * - SUCCESS if succeeded, + * - FAILED otherwise + */ + status_t (*insert_before) (iterator_t *this, void *item); + + /** + * @brief Inserts a new item after the given iterator position. + * + * The iterator position is not changed after inserting. + * + * @param this calling iterator + * @param [in]item value to insert in list + * @return + * - SUCCESS if succeeded, + * - FAILED otherwise + */ + status_t (*insert_after) (iterator_t *this, void *item); + + /** + * @brief removes an element from list at the given iterator position. + * + * The position of the iterator is set in the following order: + * - to the item before, if available + * - otherwise to the item after, if available + * - otherwise it gets reseted + * + * @param linked_list calling object + * @return + * - SUCCESS if succeeded, + * - FAILED otherwise + */ + status_t (*remove) (iterator_t *iterator); + + /** + * @brief Resets the iterator position. + * + * After reset, the iterator stands NOT on an element. + * A call to has_next is necessary to do any other operations + * with the resetted iterator. + * + * @param this calling object + * @return + * - SUCCESS if succeeded, + * - FAILED otherwise + */ + status_t (*reset) (iterator_t *this); + + /** + * @brief Destroys an iterator. + * + * @param this iterator to destroy + * @return + * - SUCCESS if succeeded, + * - FAILED otherwise + */ + status_t (*destroy) (iterator_t *this); +}; + +#endif /*ITERATOR_H_*/ |