This commit is contained in:
Сергей Маринкевич
2025-08-05 19:30:21 +07:00
parent f46e1a6d0b
commit d00bb90a38
11 changed files with 96 additions and 43 deletions
+18 -2
View File
@@ -14,7 +14,15 @@ class BaseLinkMixin : public virtual ILinkMixin<INode>,
public:
~BaseLinkMixin() override {
Logger::get("Mixin").dbg("--- Destructor called for: BaseLinkMixin");
Logger::get("ConDes").dbg("--- Destructor called for: BaseLinkMixin");
}
operator std::shared_ptr<INode>() override {
return this->getNode();
}
operator INode&() override {
return static_cast<INode&>(*this);
}
void linkChild(const ElemPtr& child) override {
@@ -33,7 +41,15 @@ public:
auto parentLink = parent->getLink();
parentLink->removeChild(getNode());
/* NOTE:
*
* Keep a reference to the node we gonna to unlink.
* Otherwise, we'll disappear between `removeChild` and
* `setParent`. Do not rearrange these calls, because
* we want to modify the tree top down.
*/
auto node = getNode();
parentLink->removeChild(node);
getLink()->setParent(nullptr);
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <memory>
template <typename T>
class FabricMixin {
public:
template <typename... Args>
static std::shared_ptr<T> create(Args&&... args) {
return std::shared_ptr<T>(new T(std::forward<Args>(args)...));
}
};
+3 -3
View File
@@ -16,7 +16,7 @@ class HierarchicalLinkMixin : public LazyLinkMixin<OneToOneLink<TElem>> {
public:
~HierarchicalLinkMixin() override {
Logger::get("Mixin").dbg("--- Destructor called for: HierarchicalLinkMixin");
Logger::get("ConDes").dbg("--- Destructor called for: HierarchicalLinkMixin");
}
void linkChild(const ElemPtr& child) override {
@@ -34,10 +34,10 @@ protected:
if (typeid(*child) == typeid(*this)) {
Logger::get("Mixin").dbg("--- Mutate to OneToMany");
newLink = std::make_shared<OneToManyLink<TElem>>(this->getNode());
newLink = std::make_shared<OneToManyLink<TElem>>(*this);
} else {
Logger::get("Mixin").dbg("--- Mutate to OneToOne");
newLink = std::make_shared<OneToOneLink<TElem>>(this->getNode());
newLink = std::make_shared<OneToOneLink<TElem>>(*this);
}
if (newLink && this->link_)
+2 -3
View File
@@ -25,14 +25,13 @@ public:
LazyLinkMixin() {}
~LazyLinkMixin() override {
Logger::get("Mixin").dbg("--- Destructor called for: LazyLinkMixin");
Logger::get("ConDes").info("--- Destructor called for: LazyLinkMixin");
}
protected:
void lazyInit() {
if (!link_) {
link_ = std::make_shared<TLink>(
BaseLinkMixin::getNode());
link_ = std::make_shared<TLink>(*this);
}
}
LinkPtr link_;