diff --git a/include/ifaces/ILinkMixin.h b/include/ifaces/ILinkMixin.h index 4fd59ef..e8fbec5 100644 --- a/include/ifaces/ILinkMixin.h +++ b/include/ifaces/ILinkMixin.h @@ -13,5 +13,5 @@ public: virtual void linkChild(const NodePtr& child) = 0; virtual void unlinkParent() = 0; virtual LinkPtr getLink() = 0; - virtual NodePtr getSelf() = 0; + virtual NodePtr getNode() = 0; }; diff --git a/include/mixins/LazyLinkMixin.h b/include/mixins/LazyLinkMixin.h index 1bfbfb0..1557d9f 100644 --- a/include/mixins/LazyLinkMixin.h +++ b/include/mixins/LazyLinkMixin.h @@ -11,7 +11,7 @@ class LazyLinkMixin : public virtual ILinkMixin { public: void linkChild(const NodePtr& childNode) override { LinkPtr childLink = childNode->getLink(); - childLink->setParent(getSelf()); + childLink->setParent(getNode()); getLink()->addChild(childNode); } @@ -27,7 +27,7 @@ public: LinkPtr parentLink = parent->getLink(); - parentLink->removeChild(getSelf()); + parentLink->removeChild(getNode()); getLink()->setParent(nullptr); } @@ -41,13 +41,12 @@ public: } protected: - virtual NodePtr getShared() = 0; - NodePtr getSelf() override { return getShared(); } + virtual NodePtr getNode() = 0; private: void lazyInit() { if (!link_) { - link_ = std::make_shared(getSelf()); + link_ = std::make_shared(getNode()); } } diff --git a/include/nodes/BaseNode.h b/include/nodes/BaseNode.h index 900855d..9526509 100644 --- a/include/nodes/BaseNode.h +++ b/include/nodes/BaseNode.h @@ -5,18 +5,15 @@ class BaseNode : public INode, public LazyLinkMixin, - public std::enable_shared_from_this { + public std::enable_shared_from_this { public: - //using LazyLinkMixin::linkChild; - //using LazyLinkMixin::unlinkParent; - //using LazyLinkMixin::getLink; BaseNode(std::string name) : name_(std::move(name)) {} const std::string& name() const override { return name_; } ~BaseNode() { - std::cout << "--- Destructor called for: " << name_ << "\n"; + std::cout << "--- Base destructor called for: " << name_ << "\n"; } protected: - NodePtr getShared() override { + NodePtr getNode() override { return shared_from_this(); } std::string name_; diff --git a/include/nodes/SimpleNode.h b/include/nodes/SimpleNode.h index 816d6fd..da5f97f 100644 --- a/include/nodes/SimpleNode.h +++ b/include/nodes/SimpleNode.h @@ -2,11 +2,10 @@ #include "nodes/BaseNode.h" #include -class SimpleNode : - public BaseNode { +class SimpleNode : public BaseNode { public: ~SimpleNode() { - std::cout << "--- Destructor called for: " << name_ << "\n"; + std::cout << "--- Simple destructor called for: " << name_ << "\n"; } SimpleNode(std::string name) : BaseNode(std::move(name)) {} }; diff --git a/src/main.cpp b/src/main.cpp index b7eded3..e04d099 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "nodes/SimpleNode.h" // Путь изменен +#include "nodes/SimpleNode.h" #include void printTree(const NodePtr& startNode, int indent = 0) { @@ -14,7 +14,6 @@ void printTree(const NodePtr& startNode, int indent = 0) { int main() { std::cout << "Entering main scope...\n\n"; - // Начало новой области видимости { auto root = std::make_shared("Root"); auto child2 = std::make_shared("Child2"); @@ -43,7 +42,7 @@ int main() { std::cout << "\nTree after scope out:\n"; printTree(root); - } // <--- КОНЕЦ ОБЛАСТИ ВИДИМОСТИ + } std::cout << "\nExited main scope. All smart pointers destroyed.\n";