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.
42 lines
933 B
C++
42 lines
933 B
C++
#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();
|
|
}
|
|
};
|