- iterator insertion
This commit is contained in:
@@ -284,7 +284,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
|
||||
if (time_difference(&(event->time), &(current_event->time)) <= 0)
|
||||
{
|
||||
/* my event has to be fired before the current event in list */
|
||||
status = this->list->insert_before(this->list,iterator,event);
|
||||
status = iterator->insert_before(iterator,event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,6 +52,28 @@ struct linked_list_iterator_s {
|
||||
* @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 Resets a linked_list_iterator object
|
||||
@@ -112,30 +134,6 @@ struct linked_list_s {
|
||||
* @return SUCCESS if succeeded, FAILED otherwise
|
||||
*/
|
||||
status_t (*insert_first) (linked_list_t *linked_list, void *item);
|
||||
|
||||
/**
|
||||
* @brief inserts a new item before the given iterator position
|
||||
*
|
||||
* The iterator position is not changed after inserting
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param iterator new element is inserted before this iterator
|
||||
* @param[in] item value to insert in list
|
||||
* @return SUCCESS if succeeded, FAILED otherwise
|
||||
*/
|
||||
status_t (*insert_before) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
|
||||
|
||||
/**
|
||||
* @brief inserts a new item after the given iterator position
|
||||
*
|
||||
* The iterator position is not changed after inserting
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param iterator new element is inserted after this iterator
|
||||
* @param[in] item value to insert in list
|
||||
* @return SUCCESS if succeeded, FAILED otherwise
|
||||
*/
|
||||
status_t (*insert_after) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
|
||||
|
||||
/**
|
||||
* @brief removes an element from list at the given iterator position
|
||||
|
||||
Reference in New Issue
Block a user