From b7b350a9e14df8ebc74a4e5ac1a175d91cd3eb8c Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Wed, 10 Apr 2019 13:11:43 +0200 Subject: [PATCH] ADD: method to find all nodes of specific type --- include/Tree/tree.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/Tree/tree.hpp b/include/Tree/tree.hpp index 9f8bfb5..a3f308a 100644 --- a/include/Tree/tree.hpp +++ b/include/Tree/tree.hpp @@ -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 */ template - void findAll(const std::string &type, Container &c); + void findAll(const std::string &t, Container &c) + { + std::list>::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