Commit 47e78250 authored by Sebastian Ramacher's avatar Sebastian Ramacher

add girara_list_iterator_has_next

parent 03937ccd
......@@ -155,6 +155,11 @@ girara_list_iterator_t* girara_list_iterator_next(girara_list_iterator_t* iter)
return iter;
}
gboolean girara_list_iterator_has_next(girara_list_iterator_t* iter)
{
return iter && iter->element && g_list_next(iter->element);
}
void* girara_list_iterator_data(girara_list_iterator_t* iter)
{
g_return_val_if_fail(iter && iter->element, NULL);
......
......@@ -104,6 +104,15 @@ girara_list_iterator_t* girara_list_iterator(girara_list_t* list);
*/
girara_list_iterator_t* girara_list_iterator_next(girara_list_iterator_t* iter);
/**
* Check if iterator has next element.
*
* @param list The list iterator
* @return true if iterator has a next element, false otherwise
*/
gboolean girara_list_iterator_has_next(girara_list_iterator_t* iter);
/**
* Get data from the element pointed to by the iterator.
*
......
......@@ -39,8 +39,10 @@ test_datastructures_list()
for (intptr_t i = 0; i != 10; ++i) {
g_assert_cmpuint((intptr_t)girara_list_iterator_data(iter), ==, i);
if (i < 9) {
g_assert(girara_list_iterator_has_next(iter));
g_assert(girara_list_iterator_next(iter));
} else {
g_assert(!girara_list_iterator_has_next(iter));
g_assert(!girara_list_iterator_next(iter));
}
}
......@@ -77,8 +79,10 @@ test_datastructures_list()
for (intptr_t i = 9; i >= 0; --i) {
g_assert_cmpuint((intptr_t)girara_list_iterator_data(iter), ==, i);
if (i > 0) {
g_assert(girara_list_iterator_has_next(iter));
g_assert(girara_list_iterator_next(iter));
} else {
g_assert(!girara_list_iterator_has_next(iter));
g_assert(!girara_list_iterator_next(iter));
}
}
......
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