Add a linked list constructor initializing from an enumerator
This commit is contained in:
@@ -572,3 +572,22 @@ linked_list_t *linked_list_create()
|
|||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* See header.
|
||||||
|
*/
|
||||||
|
linked_list_t *linked_list_create_from_enumerator(enumerator_t *enumerator)
|
||||||
|
{
|
||||||
|
linked_list_t *list;
|
||||||
|
void *item;
|
||||||
|
|
||||||
|
list = linked_list_create();
|
||||||
|
|
||||||
|
while (enumerator->enumerate(enumerator, &item))
|
||||||
|
{
|
||||||
|
list->insert_last(list, item);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|||||||
@@ -299,4 +299,12 @@ struct linked_list_t {
|
|||||||
*/
|
*/
|
||||||
linked_list_t *linked_list_create(void);
|
linked_list_t *linked_list_create(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a linked list from an enumerator.
|
||||||
|
*
|
||||||
|
* @enumerator enumerator over void*, gets destroyed
|
||||||
|
* @return linked_list_t object, containing enumerated values
|
||||||
|
*/
|
||||||
|
linked_list_t *linked_list_create_from_enumerator(enumerator_t *enumerator);
|
||||||
|
|
||||||
#endif /** LINKED_LIST_H_ @}*/
|
#endif /** LINKED_LIST_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user