fup
parent
f994303cb5
commit
d17c80a195
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
class INode;
|
||||||
|
class ILink;
|
||||||
|
using NodePtr = std::shared_ptr<INode>;
|
||||||
|
using LinkPtr = std::shared_ptr<ILink>;
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include "ifaces/INode.h"
|
||||||
|
#include "ifaces/ILinkMixin.h"
|
||||||
|
#include "links/LeafLink.h"
|
||||||
|
#include "links/OneToManyLink.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class BaseLinkMixin : public virtual ILinkMixin,
|
||||||
|
public virtual INode,
|
||||||
|
public std::enable_shared_from_this<INode> {
|
||||||
|
public:
|
||||||
|
void linkChild(const NodePtr& childNode) override {
|
||||||
|
LinkPtr childLink = childNode->getLink();
|
||||||
|
childLink->setParent(getNode());
|
||||||
|
|
||||||
|
getLink()->addChild(childNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlinkParent() override {
|
||||||
|
LinkPtr link = getLink();
|
||||||
|
|
||||||
|
NodePtr parent = link->getParent();
|
||||||
|
if (!parent)
|
||||||
|
throw std::logic_error("Have no parent!");
|
||||||
|
|
||||||
|
LinkPtr parentLink = parent->getLink();
|
||||||
|
|
||||||
|
parentLink->removeChild(getNode());
|
||||||
|
getLink()->setParent(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
~BaseLinkMixin() override {
|
||||||
|
std::cout << "--- Destructor called for: " << "BaseLinkMixin" << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NodePtr getNode() {
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue