- moved linked_list_iterator_t to iterator_t, located in iterator.h

This commit is contained in:
Martin Willi
2005-11-24 14:22:29 +00:00
parent 49a72ce394
commit bdb141cb4b
23 changed files with 201 additions and 156 deletions
+124
View File
@@ -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_*/
+20 -20
View File
@@ -135,13 +135,13 @@ struct private_linked_list_t {
* Private variables and functions of linked list iterator
*
*/
typedef struct private_linked_list_iterator_t private_linked_list_iterator_t;
typedef struct private_iterator_t private_iterator_t;
struct private_linked_list_iterator_t {
struct private_iterator_t {
/**
* Public part of linked list iterator
*/
linked_list_iterator_t public;
iterator_t public;
/**
* associated linked list
@@ -162,7 +162,7 @@ struct private_linked_list_iterator_t {
/**
* Implements function has_next of linked_list_iteratr
*/
bool iterator_has_next(private_linked_list_iterator_t *this)
bool iterator_has_next(private_iterator_t *this)
{
if (this->list->count == 0)
{
@@ -194,7 +194,7 @@ bool iterator_has_next(private_linked_list_iterator_t *this)
/**
* Implements function current of linked_list_iteratr
*/
static status_t iterator_current(private_linked_list_iterator_t *this, void **value)
static status_t iterator_current(private_iterator_t *this, void **value)
{
if (this == NULL)
{
@@ -211,7 +211,7 @@ static status_t iterator_current(private_linked_list_iterator_t *this, void **va
/**
* Implements function current of linked_list_iteratr
*/
static status_t iterator_reset(private_linked_list_iterator_t *this)
static status_t iterator_reset(private_iterator_t *this)
{
if (this == NULL)
{
@@ -224,7 +224,7 @@ static status_t iterator_reset(private_linked_list_iterator_t *this)
/**
* Implements function destroy of linked_list_iteratr
*/
static status_t iterator_destroy(private_linked_list_iterator_t *this)
static status_t iterator_destroy(private_iterator_t *this)
{
if (this == NULL)
{
@@ -457,7 +457,7 @@ static status_t get_last(private_linked_list_t *this, void **item)
/**
* @brief implements function insert_before of linked_list_t
*/
static status_t insert_before(private_linked_list_iterator_t * iterator, void *item)
static status_t insert_before(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
@@ -499,7 +499,7 @@ static status_t insert_before(private_linked_list_iterator_t * iterator, void *i
/**
* @brief implements function insert_after of linked_list_t
*/
static status_t insert_after(private_linked_list_iterator_t * iterator, void *item)
static status_t insert_after(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
@@ -541,7 +541,7 @@ static status_t insert_after(private_linked_list_iterator_t * iterator, void *it
/**
* @brief implements function remove of linked_list_t.
*/
static status_t remove(private_linked_list_iterator_t *this)
static status_t remove(private_iterator_t *this)
{
linked_list_element_t *new_current;
@@ -600,22 +600,22 @@ static status_t remove(private_linked_list_iterator_t *this)
return SUCCESS;
}
static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
static status_t create_iterator (private_linked_list_t *linked_list, iterator_t **iterator,bool forward)
{
private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t);
private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
if (this == NULL)
{
return FAILED;
}
this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
this->public.insert_before = (status_t (*) (linked_list_iterator_t *this, void *item)) insert_before;
this->public.insert_after = (status_t (*) (linked_list_iterator_t *this, void *item)) insert_after;
this->public.remove = (status_t (*) (linked_list_iterator_t *this)) remove;
this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current;
this->public.insert_before = (status_t (*) (iterator_t *this, void *item)) insert_before;
this->public.insert_after = (status_t (*) (iterator_t *this, void *item)) insert_after;
this->public.remove = (status_t (*) (iterator_t *this)) remove;
this->public.reset = (status_t (*) (iterator_t *this)) iterator_reset;
this->public.destroy = (status_t (*) (iterator_t *this)) iterator_destroy;
this->forward = forward;
@@ -661,7 +661,7 @@ linked_list_t *linked_list_create()
private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
this->public.get_count = (int (*) (linked_list_t *linked_list)) get_count;
this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, iterator_t **iterator,bool forward)) create_iterator;
this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
this->public.get_last = (status_t (*) (linked_list_t *linked_list, void **item)) get_last;
this->public.insert_first = (status_t (*) (linked_list_t *linked_list, void *item)) insert_first;
+2 -81
View File
@@ -24,90 +24,11 @@
#define LINKED_LIST_H_
#include <types.h>
#include <utils/iterator.h>
typedef struct linked_list_iterator_t linked_list_iterator_t;
/**
* @brief Iterator for a linked list.
*
* This element holds a pointer to the current element in the linked list
*
* @warning the iterator is NOT thread-save
*/
struct linked_list_iterator_t {
/**
* @brief returns TRUE if more elements are available
*
* @param this calling object
* @return if more elements are avaiable TRUE, FALSE otherwise
*/
bool (*has_next) (linked_list_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 if succeeded, FAILED otherwise
*/
status_t (*current) (linked_list_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) (linked_list_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) (linked_list_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
* @param iterator iterator holding the position of the element to remove
* @return SUCCESS if succeeded, FAILED otherwise
*/
status_t (*remove) (linked_list_iterator_t *iterator);
/**
* @brief Resets a linked_list_iterator object
*
* @param this calling object
* @return SUCCESS if succeeded, FAILED otherwise
*/
status_t (*reset) (linked_list_iterator_t *this);
/**
* @brief Destroys a linked_list_iterator object
*
* @param this calling object
* @return SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (linked_list_iterator_t *this);
};
typedef struct linked_list_t linked_list_t;
/**
* @brief Double Linked List (named only as linked list).
*
@@ -137,7 +58,7 @@ struct linked_list_t {
* @param[in] forward iterator direction (TRUE: front to end)
* @return SUCCESS if succeeded, FAILED otherwise
*/
status_t (*create_iterator) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward);
status_t (*create_iterator) (linked_list_t *linked_list, iterator_t **iterator,bool forward);
/**
* @brief inserts a new item at the beginning of the list
+3 -3
View File
@@ -194,7 +194,7 @@ static logger_t *create_logger(private_logger_manager_t *this, logger_context_t
*/
static logger_level_t get_logger_level (private_logger_manager_t *this, logger_context_t context)
{
linked_list_iterator_t *iterator;
iterator_t *iterator;
/* set logger_level to default logger_level */
logger_level_t logger_level = this->default_log_level;
@@ -235,7 +235,7 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c
static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
{
linked_list_iterator_t *iterator;
iterator_t *iterator;
status_t status = NOT_FOUND;
pthread_mutex_lock(&(this->mutex));
@@ -275,7 +275,7 @@ static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
*/
static status_t set_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable)
{
linked_list_iterator_t *iterator;
iterator_t *iterator;
status_t status;
pthread_mutex_lock(&(this->mutex));