* NULL if last element in list.
*/
linked_list_element_t *next;
-
- /**
- * Destroys a linked_list_element object.
- *
- * @param linked_list_element_t calling object
- */
- void (*destroy) (linked_list_element_t *this);
};
/**
- * Implementation of linked_list_element_t.destroy.
+ * Creates an empty linked list object.
*/
-static void linked_list_element_destroy(linked_list_element_t *this)
-{
- free(this);
-}
-
-/**
- * @brief Creates an empty linked list object.
- *
- * @warning Only the pointer to the value is stored.
- *
- * @param[in] value value of item to be set
- * @return linked_list_element_t object
- */
-
linked_list_element_t *linked_list_element_create(void *value)
{
linked_list_element_t *this = malloc_thing(linked_list_element_t);
-
- this->destroy = linked_list_element_destroy;
-
- this->previous=NULL;
- this->next=NULL;
+
+ this->previous = NULL;
+ this->next = NULL;
this->value = value;
-
+
return (this);
}
this->current->previous->next = this->current->next;
this->current->next->previous = this->current->previous;
}
-
+
this->list->count--;
- this->current->destroy(this->current);
+ free(this->current);
/* set the new iterator position */
this->current = new_current;
return SUCCESS;
{
iterator->list->public.insert_first(&(iterator->list->public), item);
}
-
- linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
+
+ linked_list_element_t *element = linked_list_element_create(item);
if (iterator->current->previous == NULL)
{
iterator->current->previous = element;
iterator->current->previous = element;
element->next = iterator->current;
}
-
iterator->list->count++;
}
iterator->list->public.insert_first(&(iterator->list->public),item);
return;
}
-
- linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
+
+ linked_list_element_t *element = linked_list_element_create(item);
if (iterator->current->next == NULL)
{
iterator->current->next = element;
iterator_t *iterator;
void *item;
- iterator = this->public.create_iterator(&(this->public),TRUE);
+ iterator = this->public.create_iterator(&this->public,TRUE);
while (iterator->has_next(iterator))
{
static void insert_first(private_linked_list_t *this, void *item)
{
linked_list_element_t *element;
-
- element =(linked_list_element_t *) linked_list_element_create(item);
-
+
+ element = linked_list_element_create(item);
if (this->count == 0)
{
/* first entry in list */
old_first_element->previous = element;
this->first = element;
}
-
this->count++;
}
{
return NOT_FOUND;
}
-
+
linked_list_element_t *element = this->first;
-
if (element->next != NULL)
{
element->next->previous = NULL;
}
this->first = element->next;
-
+
if (item != NULL)
{
*item = element->value;
}
-
this->count--;
-
- element->destroy(element);
-
+ free(element);
return SUCCESS;
}
{
return NOT_FOUND;
}
-
*item = this->first->value;
-
return SUCCESS;
}
*/
static void insert_last(private_linked_list_t *this, void *item)
{
- linked_list_element_t *element = (linked_list_element_t *) linked_list_element_create(item);
-
+ linked_list_element_t *element = linked_list_element_create(item);
+
if (this->count == 0)
{
/* first entry in list */
}
else
{
-
linked_list_element_t *old_last_element = this->last;
element->previous = old_last_element;
element->next = NULL;
old_last_element->next = element;
this->last = element;
}
-
this->count++;
}
{
return NOT_FOUND;
}
-
+
linked_list_element_t *element = this->last;
-
+
if (element->previous != NULL)
{
element->previous->next = NULL;
{
*item = element->value;
}
-
- this->count--;
-
- element->destroy(element);
+ this->count--;
+ free(element);
return SUCCESS;
}
{
current_element = current_element->next;
}
-
+
if (current_element == NULL)
{
this->public.insert_last(&(this->public),item);
return SUCCESS;
}
-
- linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
-
+
+ linked_list_element_t *element = linked_list_element_create(item);
if (current_element->previous == NULL)
{
current_element->previous = element;
this->current = NULL;
this->list = linked_list;
- return &(this->public);
+ return &this->public;
}
/**
*/
static void linked_list_destroy(private_linked_list_t *this)
{
- void * value;
+ void *value;
/* Remove all list items before destroying list */
- while (this->public.remove_first(&(this->public),&value) != NOT_FOUND)
+ while (this->public.remove_first(&(this->public), &value) != NOT_FOUND)
{
/* values are not destroyed so memory leaks are possible
* if list is not empty when deleting */
private_linked_list_t *this = malloc_thing(private_linked_list_t);
this->public.get_count = (int (*) (linked_list_t *)) get_count;
- this->public.create_iterator = (iterator_t * (*) (linked_list_t *,bool )) create_iterator;
+ this->public.create_iterator = (iterator_t * (*) (linked_list_t *,bool))create_iterator;
this->public.call_on_items = (void (*) (linked_list_t *, void(*func)(void*)))call_on_items;
- this->public.get_first = (status_t (*) (linked_list_t *, void **item)) get_first;
- this->public.get_last = (status_t (*) (linked_list_t *, void **item)) get_last;
- this->public.insert_first = (void (*) (linked_list_t *, void *item)) insert_first;
- this->public.insert_last = (void (*) (linked_list_t *, void *item)) insert_last;
- this->public.remove_first = (status_t (*) (linked_list_t *, void **item)) remove_first;
- this->public.remove_last = (status_t (*) (linked_list_t *, void **item)) remove_last;
- this->public.insert_at_position =(status_t (*) (linked_list_t *,size_t, void *)) insert_at_position;
- this->public.remove_at_position =(status_t (*) (linked_list_t *,size_t, void **)) remove_at_position;
- this->public.get_at_position =(status_t (*) (linked_list_t *,size_t, void **)) get_at_position;
-
- this->public.destroy = (void (*) (linked_list_t *)) linked_list_destroy;
+ this->public.get_first = (status_t (*) (linked_list_t *, void **item))get_first;
+ this->public.get_last = (status_t (*) (linked_list_t *, void **item))get_last;
+ this->public.insert_first = (void (*) (linked_list_t *, void *item))insert_first;
+ this->public.insert_last = (void (*) (linked_list_t *, void *item))insert_last;
+ this->public.remove_first = (status_t (*) (linked_list_t *, void **item))remove_first;
+ this->public.remove_last = (status_t (*) (linked_list_t *, void **item))remove_last;
+ this->public.insert_at_position = (status_t (*) (linked_list_t *,size_t, void *))insert_at_position;
+ this->public.remove_at_position = (status_t (*) (linked_list_t *,size_t, void **))remove_at_position;
+ this->public.get_at_position = (status_t (*) (linked_list_t *,size_t, void **))get_at_position;
+ this->public.destroy = (void (*) (linked_list_t *))linked_list_destroy;
this->count = 0;
this->first = NULL;
this->last = NULL;
- return (&(this->public));
+ return &this->public;
}