functions invoked on all linked list items now support up to five additional arguments
This commit is contained in:
parent
b1f8fc0cdb
commit
ebb036feec
|
@ -118,7 +118,7 @@ static void unregister(iface_t *iface)
|
|||
*/
|
||||
static void destroy(private_bridge_t *this)
|
||||
{
|
||||
this->ifaces->invoke_function(this->ifaces, (void(*)(void*))unregister);
|
||||
this->ifaces->invoke_function(this->ifaces, (linked_list_invoke_t)unregister);
|
||||
this->ifaces->destroy(this->ifaces);
|
||||
if (br_del_bridge(this->name) != 0)
|
||||
{
|
||||
|
|
|
@ -671,14 +671,15 @@ static status_t find_last(private_linked_list_t *this, linked_list_match_t match
|
|||
/**
|
||||
* Implementation of linked_list_t.invoke_offset.
|
||||
*/
|
||||
static void invoke_offset(private_linked_list_t *this, size_t offset)
|
||||
static void invoke_offset(private_linked_list_t *this, size_t offset,
|
||||
void *d1, void *d2, void *d3, void *d4, void *d5)
|
||||
{
|
||||
element_t *current = this->first;
|
||||
|
||||
while (current)
|
||||
{
|
||||
void (**method)(void*) = current->value + offset;
|
||||
(*method)(current->value);
|
||||
linked_list_invoke_t *method = current->value + offset;
|
||||
(*method)(current->value, d1, d2, d3, d4, d5);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
@ -686,13 +687,14 @@ static void invoke_offset(private_linked_list_t *this, size_t offset)
|
|||
/**
|
||||
* Implementation of linked_list_t.invoke_function.
|
||||
*/
|
||||
static void invoke_function(private_linked_list_t *this, void(*fn)(void*))
|
||||
static void invoke_function(private_linked_list_t *this, linked_list_invoke_t fn,
|
||||
void *d1, void *d2, void *d3, void *d4, void *d5)
|
||||
{
|
||||
element_t *current = this->first;
|
||||
|
||||
while (current)
|
||||
{
|
||||
fn(current->value);
|
||||
fn(current->value, d1, d2, d3, d4, d5);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
@ -843,8 +845,8 @@ linked_list_t *linked_list_create()
|
|||
this->public.remove_last = (status_t (*) (linked_list_t *, void **item))remove_last;
|
||||
this->public.remove = (int(*)(linked_list_t*, void *item, bool (*compare)(void *,void*)))remove;
|
||||
this->public.remove_at = (void(*)(linked_list_t*, enumerator_t *enumerator))remove_at;
|
||||
this->public.invoke_offset = (void (*)(linked_list_t*,size_t))invoke_offset;
|
||||
this->public.invoke_function = (void (*)(linked_list_t*,void(*)(void*)))invoke_function;
|
||||
this->public.invoke_offset = (void (*)(linked_list_t*,size_t,...))invoke_offset;
|
||||
this->public.invoke_function = (void (*)(linked_list_t*,linked_list_invoke_t,...))invoke_function;
|
||||
this->public.clone_offset = (linked_list_t * (*)(linked_list_t*,size_t))clone_offset;
|
||||
this->public.clone_function = (linked_list_t * (*)(linked_list_t*,void*(*)(void*)))clone_function;
|
||||
this->public.destroy = (void (*) (linked_list_t *))destroy;
|
||||
|
|
|
@ -45,6 +45,14 @@ typedef struct linked_list_t linked_list_t;
|
|||
*/
|
||||
typedef bool (*linked_list_match_t)(void *item, ...);
|
||||
|
||||
/**
|
||||
* Method to be invoked on elements in a linked list (used in invoke_* functions)
|
||||
*
|
||||
* @param item current list item
|
||||
* @param ... user supplied data (only pointers, at most 5)
|
||||
*/
|
||||
typedef void (*linked_list_invoke_t)(void *item, ...);
|
||||
|
||||
/**
|
||||
* Class implementing a double linked list.
|
||||
*
|
||||
|
@ -210,15 +218,17 @@ struct linked_list_t {
|
|||
* macro, e.g.: list->invoke(list, offsetof(object_t, method));
|
||||
*
|
||||
* @param offset offset of the method to invoke on objects
|
||||
* @param ... user data to supply to called function (limited to 5 arguments)
|
||||
*/
|
||||
void (*invoke_offset) (linked_list_t *this, size_t offset);
|
||||
void (*invoke_offset) (linked_list_t *this, size_t offset, ...);
|
||||
|
||||
/**
|
||||
* Invoke a function on all of the contained objects.
|
||||
*
|
||||
* @param offset offset of the method to invoke on objects
|
||||
* @param function offset of the method to invoke on objects
|
||||
* @param ... user data to supply to called function (limited to 5 arguments)
|
||||
*/
|
||||
void (*invoke_function) (linked_list_t *this, void (*)(void*));
|
||||
void (*invoke_function) (linked_list_t *this, linked_list_invoke_t function, ...);
|
||||
|
||||
/**
|
||||
* Clones a list and its objects using the objects' clone method.
|
||||
|
|
Loading…
Reference in New Issue