os: add 'Xml_node::for_each_sub_node'
The new function template simplifies the common case of iterating through the sub nodes of an XML node.
This commit is contained in:
parent
3a1ecdd5a7
commit
13bce287ad
|
@ -656,6 +656,35 @@ namespace Genode {
|
||||||
throw Nonexistent_sub_node();
|
throw Nonexistent_sub_node();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute functor 'fn' for each sub node of specified type
|
||||||
|
*/
|
||||||
|
template <typename FN>
|
||||||
|
void for_each_sub_node(char const *type, FN const &fn)
|
||||||
|
{
|
||||||
|
if (_num_sub_nodes == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Xml_node node = sub_node();
|
||||||
|
for (int i = 0; ; node = node.next()) {
|
||||||
|
|
||||||
|
if (!type || node.has_type(type))
|
||||||
|
fn(node);
|
||||||
|
|
||||||
|
if (++i == _num_sub_nodes)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute functor 'fn' for each sub node
|
||||||
|
*/
|
||||||
|
template <typename FN>
|
||||||
|
void for_each_sub_node(FN const &fn)
|
||||||
|
{
|
||||||
|
for_each_sub_node(nullptr, fn);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Nth attribute of XML node
|
* Return Nth attribute of XML node
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user