You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB
C++

#pragma once
#include <iostream>
#include <memory>
#include "ifaces/ILinkMixin.h"
#include "ifaces/INode.h"
#include "Logger.h"
class BaseLinkMixin : public virtual ILinkMixin<INode>,
public std::enable_shared_from_this<ILinkMixin<INode>> {
using ElemPtr = std::shared_ptr<INode>;
public:
~BaseLinkMixin() override {
Logger::get("Mixin").dbg("--- Destructor called for: BaseLinkMixin");
}
void linkChild(const ElemPtr& child) override {
getLink()->addChild(child);
auto childLink = child->getLink();
childLink->setParent(getNode());
}
void unlinkParent() override {
auto link = getLink();
ElemPtr parent = link->getParent();
if (!parent)
throw std::logic_error("Have no parent!");
auto parentLink = parent->getLink();
parentLink->removeChild(getNode());
getLink()->setParent(nullptr);
}
const std::vector<ElemPtr>& children() override {
auto link = getLink();
return link->getChildren();
}
protected:
ElemPtr getNode() {
return std::dynamic_pointer_cast<INode>(shared_from_this());
}
};