From 6d55169a5f9708933cf4f31ff6f2e3fa522e1586 Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Wed, 10 Apr 2019 09:53:08 +0200 Subject: [PATCH] ADD: method to search for all nodes with a given base --- include/Tree/tree.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/Tree/tree.hpp b/include/Tree/tree.hpp index e373f44..9f8bfb5 100644 --- a/include/Tree/tree.hpp +++ b/include/Tree/tree.hpp @@ -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 */ - template - void findAllBase(const std::string &base, Container &c); + template + void findAllBase(const std::string &b, Container &c) + { + std::list>::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