mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-01 15:10:56 +00:00
nic_router: destroy_each for list wrapper
List method to destruct and deallocate each item of a list. Ref #2670
This commit is contained in:
parent
8fff7df438
commit
d5f645ee69
@ -16,23 +16,33 @@
|
|||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <util/list.h>
|
#include <util/list.h>
|
||||||
|
#include <base/allocator.h>
|
||||||
|
|
||||||
|
namespace Net { template <typename> class List; }
|
||||||
|
|
||||||
namespace Net {
|
|
||||||
template <typename> class List;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LT>
|
template <typename LT>
|
||||||
struct Net::List : Genode::List<LT>
|
struct Net::List : Genode::List<LT>
|
||||||
{
|
{
|
||||||
|
using Base = Genode::List<LT>;
|
||||||
|
|
||||||
template <typename FUNC>
|
template <typename FUNC>
|
||||||
void for_each(FUNC && functor)
|
void for_each(FUNC && functor)
|
||||||
{
|
{
|
||||||
for (LT * elem = Genode::List<LT>::first(); elem;
|
for (LT * elem = Base::first(); elem;
|
||||||
elem = elem->Genode::List<LT>::Element::next())
|
elem = elem->Base::Element::next())
|
||||||
{
|
{
|
||||||
functor(*elem);
|
functor(*elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void destroy_each(Genode::Deallocator &dealloc)
|
||||||
|
{
|
||||||
|
while (LT *elem = Base::first()) {
|
||||||
|
Base::remove(elem);
|
||||||
|
destroy(dealloc, elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _LIST_H_ */
|
#endif /* _LIST_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user