This commit is contained in:
Сергей Маринкевич
2025-07-22 19:18:03 +07:00
parent 3801a5dc0b
commit f5f78308bd
11 changed files with 136 additions and 143 deletions
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include "mixins/LazyLinkMixin.h"
#include "ifaces/INode.h"
#include <iostream>
class BaseNode : public INode,
public LazyLinkMixin<OneToManyLink>,
public std::enable_shared_from_this<BaseNode> {
public:
BaseNode(std::string name) : name_(std::move(name)) {}
const std::string& name() const override { return name_; }
~BaseNode() {
std::cout << "--- Destructor called for: " << name_ << "\n";
}
protected:
NodePtr getShared() override {
return shared_from_this();
}
std::string name_;
};
+7 -21
View File
@@ -1,26 +1,12 @@
#pragma once
#include "mixins/LazyLinkMixin.h"
#include "nodes/BaseNode.h"
#include <iostream>
class SimpleNode : public LazyLinkMixin<SimpleNode>,
public std::enable_shared_from_this<SimpleNode> {
class SimpleNode :
public BaseNode {
public:
static NodePtr create(std::string name) {
struct EnableMakeShared : public SimpleNode {
EnableMakeShared(std::string n) : SimpleNode(std::move(n)) {}
};
return std::make_shared<EnableMakeShared>(std::move(name));
}
const std::string& name() const override { return name_; }
~SimpleNode() {
std::cout << "--- Destructor called for: " << name_ << "\n";
}
protected:
std::shared_ptr<SimpleNode> getShared() override {
return shared_from_this();
}
private:
friend class LazyLinkMixin<SimpleNode>;
explicit SimpleNode(std::string name) : name_(std::move(name)) {}
std::string name_;
~SimpleNode() {
std::cout << "--- Destructor called for: " << name_ << "\n";
}
SimpleNode(std::string name) : BaseNode(std::move(name)) {}
};