make nodes to provide nodes instead of mixins
This commit is contained in:
@@ -3,37 +3,46 @@
|
||||
#include <memory>
|
||||
|
||||
#include "ifaces/ILinkMixin.h"
|
||||
#include "ifaces/INode.h"
|
||||
#include "Logger.h"
|
||||
|
||||
class BaseLinkMixin : public virtual ILinkMixin,
|
||||
public std::enable_shared_from_this<ILinkMixin> {
|
||||
class BaseLinkMixin : public virtual ILinkMixin<INode>,
|
||||
public std::enable_shared_from_this<ILinkMixin<INode>> {
|
||||
using ElemPtr = std::shared_ptr<INode>;
|
||||
|
||||
public:
|
||||
void linkChild(const MixinPtr& child) override {
|
||||
~BaseLinkMixin() override {
|
||||
Logger::get("Mixin").dbg("--- Destructor called for: BaseLinkMixin");
|
||||
}
|
||||
|
||||
void linkChild(const ElemPtr& child) override {
|
||||
getLink()->addChild(child);
|
||||
|
||||
LinkPtr childLink = child->getLink();
|
||||
auto childLink = child->getLink();
|
||||
childLink->setParent(getNode());
|
||||
}
|
||||
|
||||
void unlinkParent() override {
|
||||
LinkPtr link = getLink();
|
||||
auto link = getLink();
|
||||
|
||||
MixinPtr parent = link->getParent();
|
||||
ElemPtr parent = link->getParent();
|
||||
if (!parent)
|
||||
throw std::logic_error("Have no parent!");
|
||||
|
||||
LinkPtr parentLink = parent->getLink();
|
||||
auto parentLink = parent->getLink();
|
||||
|
||||
parentLink->removeChild(getNode());
|
||||
getLink()->setParent(nullptr);
|
||||
}
|
||||
|
||||
~BaseLinkMixin() override {
|
||||
Logger::get("Mixin").dbg("--- Destructor called for: BaseLinkMixin");
|
||||
|
||||
const std::vector<ElemPtr>& children() override {
|
||||
auto link = getLink();
|
||||
return link->getChildren();
|
||||
}
|
||||
|
||||
protected:
|
||||
MixinPtr getNode() {
|
||||
return shared_from_this();
|
||||
ElemPtr getNode() {
|
||||
return std::dynamic_pointer_cast<INode>(shared_from_this());
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user