FIX: some fixes
This commit is contained in:
parent
343e880558
commit
d178ccb9a3
@ -18,6 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <Tree/tree.hpp>
|
||||
#include <memory>
|
||||
|
||||
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator Tree::BaseNode::getChildIterator(const std::shared_ptr<const Tree::BaseNode> child) const
|
||||
{
|
||||
@ -100,14 +101,22 @@ void Tree::BaseNode::removeChild(const std::shared_ptr<const Tree::BaseNode> &c)
|
||||
{
|
||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
|
||||
it=std::find(children.begin(), children.end(),c);
|
||||
children.erase(it);
|
||||
if (it!=children.end())
|
||||
{
|
||||
it=children.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void Tree::BaseNode::deleteChild(const std::shared_ptr<Tree::BaseNode> &c)
|
||||
{
|
||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
|
||||
it=std::find(children.begin(), children.end(),c);
|
||||
|
||||
if (it!=children.end())
|
||||
{
|
||||
children.erase(it);
|
||||
}
|
||||
it = children.erase(it);
|
||||
|
||||
c->setParent(nullptr);
|
||||
}
|
||||
@ -129,3 +138,14 @@ void Tree::BaseNode::deleteChildren()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Tree::BaseNode::replace(std::shared_ptr<Tree::BaseNode> n)
|
||||
{
|
||||
|
||||
n->setParent(getParent());
|
||||
n->addChildren(getChildrenBegin(), getChildrenEnd());
|
||||
|
||||
auto it=getParent()->getChildIterator(shared_from_this());
|
||||
getParent()->insertChild(n, it);
|
||||
getParent()->removeChild(shared_from_this());
|
||||
}
|
Loading…
Reference in New Issue
Block a user