/* Copyright (C) 2019 Dominik Meyer This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include std::shared_ptr Tree::BaseNode::findNext(const std::string &t) { std::list>::iterator childIT; std::shared_ptr temp; if (type() == t ) { return shared_from_this(); } for(childIT=children.begin(); childIT != children.end(); ++childIT) { temp=(*childIT)->findNext(t); if (temp != nullptr) { return temp; } } return nullptr; } /* * return the number of children */ const unsigned int Tree::BaseNode::getNrChildren() const { std::list>::const_iterator childIT; unsigned int nr=children.size(); for(childIT=children.begin(); childIT != children.end(); ++childIT) { nr += (*childIT)->getNrChildren(); } return nr; } /* * print the tree and indent according to depth */ void Tree::BaseNode::printTree(const uint32_t depth) { for (uint32_t i=0; i< depth; i++) { std::cout << " "; } std::cout << toString() << std::endl; std::list>::iterator childIT; for(childIT=getChildrenBegin(); childIT != getChildrenEnd(); ++childIT) { (*childIT)->printTree(depth+1); } } void Tree::BaseNode::removeChild(const std::shared_ptr &c) { std::list>::iterator it; it=std::find(children.begin(), children.end(),c); children.erase(it); } void Tree::BaseNode::deleteChild(const std::shared_ptr &c) { std::list>::iterator it; it=std::find(children.begin(), children.end(),c); children.erase(it); c->setParent(nullptr); } /* * delete all children */ void Tree::BaseNode::deleteChildren() { std::list>::iterator it; for(it=children.begin(); it!=children.end(); ++it) { if ((*it) != nullptr ) { deleteChild((*it)); } } }