ADD: method to search for all nodes with a given base

This commit is contained in:
Dominik Meyer 2019-04-10 09:53:08 +02:00
parent cf58516daf
commit 6d55169a5f
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
1 changed files with 16 additions and 3 deletions

View File

@ -225,12 +225,25 @@ namespace Tree
/**
* @brief finds all nodes of a given base
*
* @param base - the base type of the node as a string
* @param b - the base 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 findAllBase(const std::string &base, Container &c);
template <class Container>
void findAllBase(const std::string &b, Container &c)
{
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
if (base() == b)
{
c.push_back(shared_from_this());
}
for(it = children.begin(); it != children.end(); ++it)
{
(*it)->findAllBase(b,c);
}
}
/**
* @brief checks if the given node is a direct child of this node