unlink the links

This commit is contained in:
Сергей Маринкевич
2025-07-23 17:44:25 +07:00
parent d17c80a195
commit 55ef99c848
10 changed files with 58 additions and 44 deletions
+8 -11
View File
@@ -1,26 +1,23 @@
#pragma once
#include <iostream>
#include "ifaces/INode.h"
#include "ifaces/ILinkMixin.h"
#include "links/LeafLink.h"
#include "links/OneToManyLink.h"
#include <memory>
#include "ifaces/ILinkMixin.h"
class BaseLinkMixin : public virtual ILinkMixin,
public virtual INode,
public std::enable_shared_from_this<INode> {
public std::enable_shared_from_this<ILinkMixin> {
public:
void linkChild(const NodePtr& childNode) override {
LinkPtr childLink = childNode->getLink();
void linkChild(const MixinPtr& child) override {
LinkPtr childLink = child->getLink();
childLink->setParent(getNode());
getLink()->addChild(childNode);
getLink()->addChild(child);
}
void unlinkParent() override {
LinkPtr link = getLink();
NodePtr parent = link->getParent();
MixinPtr parent = link->getParent();
if (!parent)
throw std::logic_error("Have no parent!");
@@ -35,7 +32,7 @@ public:
}
protected:
NodePtr getNode() {
MixinPtr getNode() {
return shared_from_this();
}
};
+4 -2
View File
@@ -19,14 +19,16 @@ public:
return this->link_;
}
LazyLinkMixin() {}
~LazyLinkMixin() override {
std::cout << "--- Destructor called for: " << "LazyLinkMixin" << "\n";
}
protected:
void lazyInit() {
if (!this->link_) {
this->link_ = std::make_shared<TLink>(
if (!link_) {
link_ = std::make_shared<TLink>(
BaseLinkMixin::getNode());
}
}