Commit 7a639d1c authored by Abdó Roig-Maranges's avatar Abdó Roig-Maranges Committed by Sebastian Ramacher

Added some functions to manipulate girara_lists

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent db4b371c
......@@ -218,6 +218,16 @@ girara_list_iterator(girara_list_t* list)
return iter;
}
girara_list_iterator_t*
girara_list_iterator_copy(girara_list_iterator_t* iter) {
g_return_val_if_fail(iter, NULL);
girara_list_iterator_t* iter2 = g_malloc0(sizeof(girara_list_iterator_t));
iter2->list = iter->list;
iter2->element = iter->element;
return iter2;
}
girara_list_iterator_t*
girara_list_iterator_next(girara_list_iterator_t* iter)
{
......@@ -240,6 +250,41 @@ girara_list_iterator_has_next(girara_list_iterator_t* iter)
return iter && iter->element && g_list_next(iter->element);
}
girara_list_iterator_t*
girara_list_iterator_previous(girara_list_iterator_t* iter)
{
if (!iter || !iter->element) {
return NULL;
}
iter->element = g_list_previous(iter->element);
if (!iter->element) {
return NULL;
}
return iter;
}
bool
girara_list_iterator_has_previous(girara_list_iterator_t* iter)
{
return iter && iter->element && g_list_previous(iter->element);
}
void
girara_list_iterator_remove(girara_list_iterator_t* iter) {
if (iter && iter->element) {
GList *el = iter->element;
if (iter->list && iter->list->free) {
(iter->list->free)(iter->element->data);
}
iter->element = el->next;
iter->list->start = g_list_delete_link(iter->list->start, el);
}
}
bool
girara_list_iterator_is_valid(girara_list_iterator_t* iter)
{
......
......@@ -151,6 +151,14 @@ void* girara_list_find(girara_list_t* list, girara_compare_function_t compare,
*/
girara_list_iterator_t* girara_list_iterator(girara_list_t* list);
/**
* Create an iterator pointing to the same element as iter.
*
* @param list The girara list object
* @return The list iterator or NULL if an error occured
*/
girara_list_iterator_t* girara_list_iterator_copy(girara_list_iterator_t* iter);
/**
* Move iterator to next element.
*
......@@ -167,6 +175,31 @@ girara_list_iterator_t* girara_list_iterator_next(girara_list_iterator_t* iter);
*/
bool girara_list_iterator_has_next(girara_list_iterator_t* iter);
/**
* Move iterator to previous element.
*
* @param iter The list iterator
* @return The moved iterator or NULL if an error occured
*/
girara_list_iterator_t* girara_list_iterator_previous(girara_list_iterator_t* iter);
/**
* Check if iterator has previous element.
*
* @param iter The list iterator
* @return true if iterator has a previous element, false otherwise
*/
bool girara_list_iterator_has_previous(girara_list_iterator_t* iter);
/**
* Remove element pointed by the iterator, and updates the iterator
* to the next element
*
* @param iter The list iterator
*/
void girara_list_iterator_remove(girara_list_iterator_t* iter);
/**
* Check if iterator is valid
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment