enumerator: Add venumerate() method to enumerator_t that takes a va_list
This will allow us to implement e.g. enumerator_cleaner without having to use that unportable 5 pointer forwarding or having to define a callback for each instance. A generic implementation for enumerate() is provided so only venumerate() has to be implemented, which may be simplified by using the VA_ARGS_VGET() macro.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2013 Tobias Brunner
|
* Copyright (C) 2008-2017 Tobias Brunner
|
||||||
* Copyright (C) 2007 Martin Willi
|
* Copyright (C) 2007 Martin Willi
|
||||||
* Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
@@ -31,6 +31,25 @@
|
|||||||
|
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Described in header.
|
||||||
|
*/
|
||||||
|
bool enumerator_enumerate_default(enumerator_t *enumerator, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
if (!enumerator->venumerate)
|
||||||
|
{
|
||||||
|
DBG1(DBG_LIB, "!!! ENUMERATE DEFAULT: venumerate() missing !!!");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
va_start(args, enumerator);
|
||||||
|
result = enumerator->venumerate(enumerator, args);
|
||||||
|
va_end(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of enumerator_create_empty().enumerate
|
* Implementation of enumerator_create_empty().enumerate
|
||||||
*/
|
*/
|
||||||
@@ -646,4 +665,3 @@ enumerator_t *enumerator_create_single(void *item, void (*cleanup)(void *item))
|
|||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Tobias Brunner
|
* Copyright (C) 2013-2017 Tobias Brunner
|
||||||
* Copyright (C) 2007 Martin Willi
|
* Copyright (C) 2007 Martin Willi
|
||||||
* Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
@@ -34,8 +34,11 @@ struct enumerator_t {
|
|||||||
/**
|
/**
|
||||||
* Enumerate collection.
|
* Enumerate collection.
|
||||||
*
|
*
|
||||||
* The enumerate function takes a variable argument list containing
|
* The enumerate() method takes a variable number of pointer arguments
|
||||||
* pointers where the enumerated values get written.
|
* where the enumerated values get written to.
|
||||||
|
*
|
||||||
|
* @note Just assigning the generic enumerator_enumerate_default() function
|
||||||
|
* that calls the enumerator's venumerate() method is usually enough.
|
||||||
*
|
*
|
||||||
* @param ... variable list of enumerated items, implementation dependent
|
* @param ... variable list of enumerated items, implementation dependent
|
||||||
* @return TRUE if pointers returned
|
* @return TRUE if pointers returned
|
||||||
@@ -43,11 +46,33 @@ struct enumerator_t {
|
|||||||
bool (*enumerate)(enumerator_t *this, ...);
|
bool (*enumerate)(enumerator_t *this, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a enumerator instance.
|
* Enumerate collection.
|
||||||
|
*
|
||||||
|
* The venumerate() method takes a variable argument list containing
|
||||||
|
* pointers where the enumerated values get written to.
|
||||||
|
*
|
||||||
|
* To simplify the implementation the VA_ARGS_VGET() macro may be used.
|
||||||
|
*
|
||||||
|
* @param args variable list of enumerated items, implementation dependent
|
||||||
|
* @return TRUE if pointers returned
|
||||||
|
*/
|
||||||
|
bool (*venumerate)(enumerator_t *this, va_list args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy an enumerator_t instance.
|
||||||
*/
|
*/
|
||||||
void (*destroy)(enumerator_t *this);
|
void (*destroy)(enumerator_t *this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic implementation of enumerator_t::enumerate() that simply calls
|
||||||
|
* the enumerator's venumerate() method.
|
||||||
|
*
|
||||||
|
* @param enumerator the enumerator
|
||||||
|
* @param ... arguments passed to enumerate()
|
||||||
|
*/
|
||||||
|
bool enumerator_enumerate_default(enumerator_t *enumerator, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an enumerator which enumerates over nothing
|
* Create an enumerator which enumerates over nothing
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user