aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/utils/linked_list.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-17 13:34:10 +0000
committerMartin Willi <martin@strongswan.org>2005-11-17 13:34:10 +0000
commitf0c83c23a3a4bee1d5703274904a956c1eb755bb (patch)
treedd67b4247f0307e94b295340b622e84f1cd81d2f /Source/charon/utils/linked_list.c
parent1a2e706beebcc9a84cb32401ef0fa51ae48b8ff0 (diff)
downloadstrongswan-f0c83c23a3a4bee1d5703274904a956c1eb755bb.tar.bz2
strongswan-f0c83c23a3a4bee1d5703274904a956c1eb755bb.tar.xz
- iterator insertion
Diffstat (limited to 'Source/charon/utils/linked_list.c')
-rw-r--r--Source/charon/utils/linked_list.c93
1 files changed, 36 insertions, 57 deletions
diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c
index 785377ee9..910b275ca 100644
--- a/Source/charon/utils/linked_list.c
+++ b/Source/charon/utils/linked_list.c
@@ -244,31 +244,6 @@ static int get_count(private_linked_list_t *this)
}
-static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
-{
- private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_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.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
- this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
-
-
- this->forward = forward;
- this->current = NULL;
- this->list = linked_list;
-
- *iterator = &(this->public);
-
- return (SUCCESS);
-}
-
-
/**
* @brief implements function insert_first of linked_list_t
*/
@@ -483,21 +458,11 @@ 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_t *this, private_linked_list_iterator_t * iterator, void *item)
+static status_t insert_before(private_linked_list_iterator_t * iterator, void *item)
{
- if ((this == NULL) || (iterator == NULL))
- {
- return FAILED;
- }
-
- if (this->count == 0)
- {
- return FAILED;
- }
-
if (iterator->current == NULL)
{
- return (this->public.insert_first(&this->public,item));
+ return (iterator->list->public.insert_first(&(iterator->list->public), item));
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
@@ -509,7 +474,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
if (iterator->current->previous == NULL)
{
- if (this->first != iterator->current)
+ if (iterator->list->first != iterator->current)
{
element->destroy(element);
return FAILED;
@@ -517,7 +482,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
iterator->current->previous = element;
element->next = iterator->current;
- this->first = element;
+ iterator->list->first = element;
}
else
{
@@ -527,7 +492,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
element->next = iterator->current;
}
- this->count++;
+ iterator->list->count++;
return SUCCESS;
}
@@ -535,21 +500,11 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
/**
* @brief implements function insert_after of linked_list_t
*/
-static status_t insert_after(private_linked_list_t *this, private_linked_list_iterator_t * iterator, void *item)
+static status_t insert_after(private_linked_list_iterator_t * iterator, void *item)
{
- if ((this == NULL) || (iterator == NULL))
- {
- return FAILED;
- }
-
- if (this->count == 0)
- {
- return FAILED;
- }
-
if (iterator->current == NULL)
{
- return (this->public.insert_first(&this->public,item));
+ return (iterator->list->public.insert_first(&(iterator->list->public),item));
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
@@ -561,7 +516,7 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
if (iterator->current->next == NULL)
{
- if (this->last != iterator->current)
+ if (iterator->list->last != iterator->current)
{
element->destroy(element);
return FAILED;
@@ -569,7 +524,7 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
iterator->current->next = element;
element->previous = iterator->current;
- this->last = element;
+ iterator->list->last = element;
}
else
{
@@ -579,10 +534,36 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
element->previous = iterator->current;
}
- this->count++;
+ iterator->list->count++;
return SUCCESS;
}
+static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
+{
+ private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_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.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
+ this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
+
+
+ this->forward = forward;
+ this->current = NULL;
+ this->list = linked_list;
+
+ *iterator = &(this->public);
+
+ return (SUCCESS);
+}
+
/**
* @brief implements function remove of linked_list_t
*/
@@ -684,8 +665,6 @@ linked_list_t *linked_list_create()
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;
this->public.insert_last = (status_t (*) (linked_list_t *linked_list, void *item)) insert_last;
- this->public.insert_before = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_before;
- this->public.insert_after = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_after;
this->public.remove = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element)) linked_list_remove;
this->public.remove_first = (status_t (*) (linked_list_t *linked_list, void **item)) remove_first;
this->public.remove_last = (status_t (*) (linked_list_t *linked_list, void **item)) remove_last;