ADD: method to find all nodes of specific type

This commit is contained in:
Dominik Meyer 2019-04-10 13:11:43 +02:00
parent 243d8783ce
commit b7b350a9e1
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
1 changed files with 16 additions and 2 deletions

View File

@ -216,11 +216,25 @@ namespace Tree
/**
* @brief finds all nodes of a given type
*
* @param type - the type of the node as a string
* @param t - the type of the node as a string
* @param c - a container for holding all found nodes, has to be holding objects of type std::shared_ptr<Tree::BaseNode>
*/
template <typename Container>
void findAll(const std::string &type, Container &c);
void findAll(const std::string &t, Container &c)
{
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
if (type() == t)
{
c.push_back(shared_from_this());
}
for(it = children.begin(); it != children.end(); ++it)
{
(*it)->findAll(t,c);
}
}
/**
* @brief finds all nodes of a given base