]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
- moved remove-method to iterator
authorMartin Willi <martin@strongswan.org>
Thu, 24 Nov 2005 12:06:23 +0000 (12:06 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 24 Nov 2005 12:06:23 +0000 (12:06 -0000)
Source/charon/sa/ike_sa_manager.c
Source/charon/testcases/linked_list_test.c
Source/charon/utils/linked_list.c
Source/charon/utils/linked_list.h
Source/charon/utils/logger_manager.c

index 55fd0fcd633d3ad3b823a3c39f5e13a618e5456a..669bcec162ee856654f87572be74fca8d7896aa3 100644 (file)
@@ -335,7 +335,7 @@ static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *ent
                if (current == entry) 
                {
                        this->logger->log(this->logger,CONTROL | MOST,"Found entry by pointer. Going to delete it.");
-                       list->remove(list, iterator);
+                       iterator->remove(iterator);
                        entry->destroy(entry);
                        status = SUCCESS;
                        break;
index 46bc797b8807f35b681a3371efad6285a0241887..c13aedf93208c318365d4a9bd9be7b47db57c8ac 100644 (file)
@@ -190,7 +190,7 @@ void test_linked_list_insert_and_remove(tester_t *tester)
        tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
        
        
-       tester->assert_true(tester,(linked_list->remove(linked_list,iterator) == SUCCESS), "remove call check");
+       tester->assert_true(tester,(iterator->remove(iterator) == SUCCESS), "remove call check");
        iterator->current(iterator,&value);
        tester->assert_true(tester,(strcmp((char *) value,"before_three") == 0), "current value check");        
        
index 83e03705393dc8eb5efc593212a01e090d073ca9..2c6776c9625c27152bdf3843caae32126f048eba 100644 (file)
@@ -537,56 +537,31 @@ static status_t insert_after(private_linked_list_iterator_t * iterator, void *it
        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
+ * @brief implements function remove of linked_list_t.
  */
-static status_t linked_list_remove(private_linked_list_t *this, private_linked_list_iterator_t * iterator)
+static status_t remove(private_linked_list_iterator_t *this)
 {
        linked_list_element_t *new_current;
 
-       if ((this == NULL) || (iterator == NULL) || (iterator->current == NULL))
+       if (this->current == NULL)
        {
                return FAILED;
        }
 
-       if (this->count == 0)
+       if (this->list->count == 0)
        {
                return FAILED;
        }
        /* find out the new iterator position */
-       if (iterator->current->previous != NULL)
+       if (this ->current->previous != NULL)
        {
-               new_current = iterator->current->previous;
+               new_current = this->current->previous;
        }
-       else if (iterator->current->next != NULL)
+       else if (this->current->next != NULL)
        {
-               new_current = iterator->current->next;
+               new_current = this->current->next;
        }
        else
        {
@@ -594,35 +569,62 @@ static status_t linked_list_remove(private_linked_list_t *this, private_linked_l
        }
 
        /* now delete the entry :-) */
-       if (iterator->current->previous == NULL)
+       if (this->current->previous == NULL)
        {
-               if (iterator->current->next == NULL)
+               if (this->current->next == NULL)
                {
-                       this->first = NULL;
-                       this->last = NULL;
+                       this->list->first = NULL;
+                       this->list->last = NULL;
                }
                else
                {
-                       iterator->current->next->previous = NULL;
-                       this->first = iterator->current->next;
+                       this->current->next->previous = NULL;
+                       this->list->first = this->current->next;
                }
        }
-       else if (iterator->current->next == NULL)
+       else if (this->current->next == NULL)
        {
-               iterator->current->previous->next = NULL;
-               this->last = iterator->current->previous;
+               this->current->previous->next = NULL;
+               this->list->last = this->current->previous;
        }
        else
        {
-               iterator->current->previous->next = iterator->current->next;
-               iterator->current->next->previous = iterator->current->previous;
+               this->current->previous->next = this->current->next;
+               this->current->next->previous = this->current->previous;
        }
 
-       this->count--;
-       iterator->current->destroy(iterator->current);
-       /* set the new iterator position */
-       iterator->current = new_current;
-       return SUCCESS;
+       this->list->count--;
+       this->current->destroy(this->current);
+       /* set the new iterator position */
+       this->current = new_current;
+       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.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->forward = forward;
+       this->current = NULL;
+       this->list = linked_list;
+
+       *iterator = &(this->public);
+
+       return (SUCCESS);
 }
 
 /**
@@ -664,7 +666,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.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;
        this->public.destroy = (status_t (*) (linked_list_t *linked_list)) linked_list_destroy;
index f5a87cd14c5a3a9000aeb0722992b9382cf31c2c..71fdfd45e89cd46edac968137b76dc0bd54a4638 100644 (file)
@@ -75,6 +75,19 @@ struct linked_list_iterator_t {
         */
        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
         * 
@@ -135,20 +148,6 @@ struct linked_list_t {
         */
        status_t (*insert_first) (linked_list_t *linked_list, 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_t *linked_list, linked_list_iterator_t *iterator);
-
        /**
         * @brief removes the first item in the list and returns its value
         * 
index 0bd7e18d334c7454ef57672d5d8c950305636708..b145b279ec2e4141e2ec5a4628ee134132c6f3eb 100644 (file)
@@ -257,7 +257,7 @@ static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
                status = NOT_FOUND;
                if (entry->logger == logger)
                {
-                       this->loggers->remove(this->loggers,iterator);
+                       iterator->remove(iterator);
                        allocator_free(entry);
                        logger->destroy(logger);
                        status = SUCCESS;