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.
40 lines
832 B
C++
40 lines
832 B
C++
#pragma once
|
|
#include <iostream>
|
|
#include <memory>
|
|
|
|
#include "ifaces/ILinkMixin.h"
|
|
#include "Logger.h"
|
|
|
|
class BaseLinkMixin : public virtual ILinkMixin,
|
|
public std::enable_shared_from_this<ILinkMixin> {
|
|
public:
|
|
void linkChild(const MixinPtr& child) override {
|
|
getLink()->addChild(child);
|
|
|
|
LinkPtr childLink = child->getLink();
|
|
childLink->setParent(getNode());
|
|
}
|
|
|
|
void unlinkParent() override {
|
|
LinkPtr link = getLink();
|
|
|
|
MixinPtr parent = link->getParent();
|
|
if (!parent)
|
|
throw std::logic_error("Have no parent!");
|
|
|
|
LinkPtr parentLink = parent->getLink();
|
|
|
|
parentLink->removeChild(getNode());
|
|
getLink()->setParent(nullptr);
|
|
}
|
|
|
|
~BaseLinkMixin() override {
|
|
Logger::get("Mixin").dbg("--- Destructor called for: BaseLinkMixin");
|
|
}
|
|
|
|
protected:
|
|
MixinPtr getNode() {
|
|
return shared_from_this();
|
|
}
|
|
};
|