Add a linked list constructor taking items from a vararg list
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "linked_list.h"
|
||||
|
||||
@@ -591,3 +592,24 @@ linked_list_t *linked_list_create_from_enumerator(enumerator_t *enumerator)
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* See header.
|
||||
*/
|
||||
linked_list_t *linked_list_create_with_items(void *item, ...)
|
||||
{
|
||||
linked_list_t *list;
|
||||
va_list args;
|
||||
|
||||
list = linked_list_create();
|
||||
|
||||
va_start(args, item);
|
||||
while (item)
|
||||
{
|
||||
list->insert_last(list, item);
|
||||
item = va_arg(args, void*);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -302,9 +302,18 @@ 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
|
||||
* @param 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);
|
||||
|
||||
/**
|
||||
* Creates a linked list from a NULL terminated vararg list of items.
|
||||
*
|
||||
* @param first first item
|
||||
* @param ... subsequent items, terminated by NULL
|
||||
* @return linked_list_t object, containing passed items
|
||||
*/
|
||||
linked_list_t *linked_list_create_with_items(void *first, ...);
|
||||
|
||||
#endif /** LINKED_LIST_H_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user