mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
base: add List_model::apply_first
The new 'apply_first' method enables users of the list model to manually traverse the list model via the 'Element::next' method instead of iterating via 'for_each'. This is needed in situations where the list-model elements are visited via recursion, not via a loop. Issue #3094
This commit is contained in:
parent
554a100407
commit
cd29ca3c40
@ -22,6 +22,7 @@
|
||||
/* Genode includes */
|
||||
#include <util/xml_node.h>
|
||||
#include <util/list.h>
|
||||
#include <base/log.h>
|
||||
|
||||
namespace Genode { template <typename> class List_model; }
|
||||
|
||||
@ -94,6 +95,21 @@ class Genode::List_model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply functor 'fn' to the first element of the list model
|
||||
*
|
||||
* Using this method combined with the 'Element::next' method, the list
|
||||
* model can be traversed manually. This is handy in situations where
|
||||
* the list-model elements are visited via recursive function calls
|
||||
* instead of a 'for_each' loop.
|
||||
*/
|
||||
template <typename FN>
|
||||
void apply_first(FN const &fn) const
|
||||
{
|
||||
if (Element const *e = _elements.first())
|
||||
fn(static_cast<ELEM const &>(*e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all elements from the data model
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user