|
|
|
@ -5,285 +5,176 @@
|
|
|
|
#include <algorithm>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class INode;
|
|
|
|
class INode;
|
|
|
|
class ILink;
|
|
|
|
class ILink;
|
|
|
|
class ILinkMixin;
|
|
|
|
class ILinkMixin;
|
|
|
|
|
|
|
|
|
|
|
|
using NodePtr = std::shared_ptr<INode>;
|
|
|
|
using NodePtr = std::shared_ptr<INode>;
|
|
|
|
using LinkPtr = std::shared_ptr<ILink>;
|
|
|
|
using LinkPtr = std::shared_ptr<ILink>;
|
|
|
|
using LinkMixinPtr = std::shared_ptr<ILinkMixin>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ILink {
|
|
|
|
// --- ИНТЕРФЕЙСЫ ---
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~ILink() = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual LinkPtr getParent() const = 0;
|
|
|
|
|
|
|
|
virtual void setParent(LinkPtr parent) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual const std::vector<LinkPtr>& getChildren() const = 0;
|
|
|
|
|
|
|
|
virtual void addChild(LinkPtr child) = 0;
|
|
|
|
|
|
|
|
virtual void removeChild(LinkPtr child) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual std::mutex& getLock() = 0;
|
|
|
|
|
|
|
|
virtual LinkMixinPtr getLinkMixin() const = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ILinkMixin {
|
|
|
|
class ILinkMixin {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~ILinkMixin() = default;
|
|
|
|
virtual ~ILinkMixin() = default;
|
|
|
|
virtual void linkChild(const NodePtr& child) = 0;
|
|
|
|
virtual void linkChild(const NodePtr& child) = 0;
|
|
|
|
virtual void unlinkParent() = 0;
|
|
|
|
virtual void unlinkParent() = 0;
|
|
|
|
virtual void unlinkChild(const NodePtr& child) = 0;
|
|
|
|
virtual LinkPtr getLink() = 0;
|
|
|
|
virtual LinkPtr getLink() const = 0;
|
|
|
|
|
|
|
|
virtual NodePtr getNode() const = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class INode {
|
|
|
|
class INode : public ILinkMixin {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~INode() = default;
|
|
|
|
~INode() override = default;
|
|
|
|
virtual LinkPtr getLink() const = 0;
|
|
|
|
virtual const std::string& name() const = 0;
|
|
|
|
virtual LinkMixinPtr getLinkMixin() const = 0;
|
|
|
|
// УБРАНО: const. Этот метод используется для получения указателя,
|
|
|
|
|
|
|
|
// который может участвовать в не-константных операциях.
|
|
|
|
|
|
|
|
virtual NodePtr getSelf() = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LeafLink : public ILink {
|
|
|
|
class ILink {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit LeafLink(NodePtr node) : node_(std::move(node)) {}
|
|
|
|
virtual ~ILink() = default;
|
|
|
|
|
|
|
|
virtual NodePtr getNode() const = 0;
|
|
|
|
LinkPtr getParent() const override { return parent_; }
|
|
|
|
virtual LinkPtr getParent() const = 0;
|
|
|
|
void setParent(LinkPtr parent) override { parent_ = std::move(parent); }
|
|
|
|
virtual void setParent(const LinkPtr& parent) = 0;
|
|
|
|
|
|
|
|
virtual const std::vector<LinkPtr>& getChildren() const = 0;
|
|
|
|
const std::vector<LinkPtr>& getChildren() const override {
|
|
|
|
virtual void addChild(const LinkPtr& child) = 0;
|
|
|
|
static std::vector<LinkPtr> empty;
|
|
|
|
virtual void removeChild(const LinkPtr& child) = 0;
|
|
|
|
return empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addChild(LinkPtr) override {
|
|
|
|
|
|
|
|
throw std::logic_error("LeafLink cannot have children");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void removeChild(LinkPtr) override {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::mutex& getLock() override { return lock_; }
|
|
|
|
|
|
|
|
LinkMixinPtr getLinkMixin() const override { return node_->getLinkMixin(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
NodePtr node_;
|
|
|
|
|
|
|
|
LinkPtr parent_;
|
|
|
|
|
|
|
|
mutable std::mutex lock_;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OneToManyLink : public ILink {
|
|
|
|
// --- РЕАЛИЗАЦИИ LINK ---
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit OneToManyLink(NodePtr node) : node_(std::move(node)) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LinkPtr getParent() const override { return parent_; }
|
|
|
|
|
|
|
|
void setParent(LinkPtr parent) override { parent_ = std::move(parent); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseLink : public ILink {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit BaseLink(NodePtr node) : owner_node_(node) {}
|
|
|
|
|
|
|
|
NodePtr getNode() const override { return owner_node_.lock(); }
|
|
|
|
|
|
|
|
LinkPtr getParent() const override { return parent_.lock(); }
|
|
|
|
|
|
|
|
void setParent(const LinkPtr& parent) override { parent_ = parent; }
|
|
|
|
const std::vector<LinkPtr>& getChildren() const override { return children_; }
|
|
|
|
const std::vector<LinkPtr>& getChildren() const override { return children_; }
|
|
|
|
|
|
|
|
void removeChild(const LinkPtr& child) override {
|
|
|
|
void addChild(LinkPtr child) override { children_.push_back(std::move(child)); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void removeChild(LinkPtr child) override {
|
|
|
|
|
|
|
|
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
|
|
|
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::mutex& getLock() override { return lock_; }
|
|
|
|
|
|
|
|
LinkMixinPtr getLinkMixin() const override { return node_->getLinkMixin(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
NodePtr node_;
|
|
|
|
|
|
|
|
LinkPtr parent_;
|
|
|
|
|
|
|
|
std::vector<LinkPtr> children_;
|
|
|
|
std::vector<LinkPtr> children_;
|
|
|
|
mutable std::mutex lock_;
|
|
|
|
std::weak_ptr<INode> owner_node_;
|
|
|
|
|
|
|
|
std::weak_ptr<ILink> parent_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OneToOneLink : public ILink {
|
|
|
|
class LeafLink : public BaseLink {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit OneToOneLink(NodePtr node) : node_(std::move(node)) {}
|
|
|
|
using BaseLink::BaseLink;
|
|
|
|
|
|
|
|
void addChild(const LinkPtr&) override { throw std::logic_error("LeafLink cannot have children"); }
|
|
|
|
LinkPtr getParent() const override { return parent_; }
|
|
|
|
|
|
|
|
void setParent(LinkPtr parent) override { parent_ = std::move(parent); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<LinkPtr>& getChildren() const override { return singleChildVec_; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addChild(LinkPtr child) override {
|
|
|
|
|
|
|
|
if (!singleChildVec_.empty()) {
|
|
|
|
|
|
|
|
throw std::logic_error("OneToOneLink already has a child");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
singleChildVec_.push_back(std::move(child));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void removeChild(LinkPtr child) override {
|
|
|
|
|
|
|
|
if (!singleChildVec_.empty() && singleChildVec_.front() == child) {
|
|
|
|
|
|
|
|
singleChildVec_.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::mutex& getLock() override { return lock_; }
|
|
|
|
|
|
|
|
LinkMixinPtr getLinkMixin() const override { return node_->getLinkMixin(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
NodePtr node_;
|
|
|
|
|
|
|
|
LinkPtr parent_;
|
|
|
|
|
|
|
|
std::vector<LinkPtr> singleChildVec_;
|
|
|
|
|
|
|
|
mutable std::mutex lock_;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Note: TypedOneToManyLink ensures type-safety on child linkage
|
|
|
|
class OneToManyLink : public BaseLink {
|
|
|
|
|
|
|
|
|
|
|
|
template <typename TChild>
|
|
|
|
|
|
|
|
class TypedOneToManyLink : public OneToManyLink {
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit TypedOneToManyLink(NodePtr node) : OneToManyLink(std::move(node)) {}
|
|
|
|
using BaseLink::BaseLink;
|
|
|
|
|
|
|
|
void addChild(const LinkPtr& child) override { children_.push_back(child); }
|
|
|
|
void addChild(LinkPtr child) override {
|
|
|
|
|
|
|
|
NodePtr n = child->getLinkMixin()->getNode();
|
|
|
|
|
|
|
|
if (!std::dynamic_pointer_cast<TChild>(n)) {
|
|
|
|
|
|
|
|
throw std::invalid_argument("TypedOneToManyLink: child is not of expected type");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OneToManyLink::addChild(std::move(child));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Note: BaseLinkMixin is used for direct eager link composition (non-lazy)
|
|
|
|
// --- CRTP МИКСИН-РЕАЛИЗАЦИЯ ---
|
|
|
|
|
|
|
|
|
|
|
|
class BaseLinkMixin : public ILinkMixin {
|
|
|
|
template <class TFinalNode>
|
|
|
|
|
|
|
|
class LazyLinkMixin : public INode {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit BaseLinkMixin(NodePtr self) {
|
|
|
|
void linkChild(const NodePtr& childNode) override {
|
|
|
|
link_ = std::make_shared<OneToManyLink>(self);
|
|
|
|
lazyInit();
|
|
|
|
}
|
|
|
|
upgradeLinkIfNeeded();
|
|
|
|
|
|
|
|
LinkPtr childLink = childNode->getLink();
|
|
|
|
void linkChild(const NodePtr& child) override {
|
|
|
|
|
|
|
|
LinkPtr childLink = child->getLink();
|
|
|
|
|
|
|
|
childLink->setParent(link_);
|
|
|
|
childLink->setParent(link_);
|
|
|
|
link_->addChild(childLink);
|
|
|
|
link_->addChild(childLink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unlinkParent() override {
|
|
|
|
void unlinkParent() override {
|
|
|
|
if (!link_ || !link_->getParent()) return;
|
|
|
|
lazyInit();
|
|
|
|
auto parent = link_->getParent();
|
|
|
|
LinkPtr parentLink = link_->getParent();
|
|
|
|
parent->getLinkMixin()->unlinkChild(getNode());
|
|
|
|
if (!parentLink) return;
|
|
|
|
|
|
|
|
parentLink->removeChild(this->getLink());
|
|
|
|
link_->setParent(nullptr);
|
|
|
|
link_->setParent(nullptr);
|
|
|
|
|
|
|
|
downgradeLinkIfPossible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unlinkChild(const NodePtr& child) override {
|
|
|
|
LinkPtr getLink() override {
|
|
|
|
LinkPtr childLink = child->getLink();
|
|
|
|
lazyInit();
|
|
|
|
link_->removeChild(childLink);
|
|
|
|
return link_;
|
|
|
|
childLink->setParent(nullptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkPtr getLink() const override { return link_; }
|
|
|
|
protected:
|
|
|
|
NodePtr getNode() const override { return self_; }
|
|
|
|
// УБРАНО: const. Возвращаем неконстантный указатель.
|
|
|
|
|
|
|
|
virtual std::shared_ptr<TFinalNode> getShared() = 0;
|
|
|
|
private:
|
|
|
|
|
|
|
|
LinkPtr link_;
|
|
|
|
|
|
|
|
NodePtr self_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note: LazyLinkMixin starts with LeafLink and upgrades dynamically
|
|
|
|
// УБРАНО: const. Соответствует базовому классу.
|
|
|
|
|
|
|
|
NodePtr getSelf() override {
|
|
|
|
template <typename TNode>
|
|
|
|
return getShared();
|
|
|
|
class LazyLinkMixin : public ILinkMixin {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit LazyLinkMixin(NodePtr self) : self_(self) {
|
|
|
|
|
|
|
|
link_ = std::make_shared<LeafLink>(self);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void linkChild(const NodePtr& child) override {
|
|
|
|
private:
|
|
|
|
ensureInitialized(child);
|
|
|
|
void lazyInit() {
|
|
|
|
|
|
|
|
if (!link_) {
|
|
|
|
LinkPtr childLink = child->getLink();
|
|
|
|
link_ = std::make_shared<LeafLink>(getSelf());
|
|
|
|
childLink->setParent(link_);
|
|
|
|
|
|
|
|
link_->addChild(childLink);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unlinkParent() override {
|
|
|
|
|
|
|
|
if (!link_ || !link_->getParent()) return;
|
|
|
|
|
|
|
|
auto parent = link_->getParent();
|
|
|
|
|
|
|
|
parent->getLinkMixin()->unlinkChild(getNode());
|
|
|
|
|
|
|
|
link_->setParent(nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (link_->getChildren().empty()) {
|
|
|
|
|
|
|
|
link_ = std::make_shared<LeafLink>(getNode());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void upgradeLinkIfNeeded() {
|
|
|
|
|
|
|
|
if (!std::dynamic_pointer_cast<LeafLink>(link_)) return;
|
|
|
|
|
|
|
|
auto oldParent = link_->getParent();
|
|
|
|
|
|
|
|
link_ = std::make_shared<OneToManyLink>(getSelf());
|
|
|
|
|
|
|
|
link_->setParent(oldParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void downgradeLinkIfPossible() {
|
|
|
|
void unlinkChild(const NodePtr& child) override {
|
|
|
|
|
|
|
|
if (!link_) return;
|
|
|
|
|
|
|
|
LinkPtr childLink = child->getLink();
|
|
|
|
|
|
|
|
link_->removeChild(childLink);
|
|
|
|
|
|
|
|
childLink->setParent(nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (link_->getChildren().empty()) {
|
|
|
|
if (link_->getChildren().empty()) {
|
|
|
|
link_ = std::make_shared<LeafLink>(getNode());
|
|
|
|
auto oldParent = link_->getParent();
|
|
|
|
}
|
|
|
|
link_ = std::make_shared<LeafLink>(getSelf());
|
|
|
|
}
|
|
|
|
link_->setParent(oldParent);
|
|
|
|
|
|
|
|
|
|
|
|
LinkPtr getLink() const override { return link_; }
|
|
|
|
|
|
|
|
NodePtr getNode() const override { return self_; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ensureInitialized(const NodePtr& child) {
|
|
|
|
|
|
|
|
if (link_ && !std::dynamic_pointer_cast<LeafLink>(link_)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LinkPtr oldLink = link_;
|
|
|
|
|
|
|
|
LinkPtr newLink;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (std::dynamic_pointer_cast<TNode>(child)) {
|
|
|
|
|
|
|
|
newLink = std::make_shared<TypedOneToManyLink<TNode>>(getNode());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
newLink = std::make_shared<OneToOneLink>(getNode());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newLink->setParent(oldLink->getParent());
|
|
|
|
|
|
|
|
link_ = newLink;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkPtr link_;
|
|
|
|
LinkPtr link_;
|
|
|
|
NodePtr self_;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleNode : public INode, public std::enable_shared_from_this<SimpleNode> {
|
|
|
|
// --- КОНКРЕТНЫЙ УЗЕЛ ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// УБРАНО: final. Теперь от класса можно наследоваться.
|
|
|
|
|
|
|
|
class SimpleNode : public LazyLinkMixin<SimpleNode>,
|
|
|
|
|
|
|
|
public std::enable_shared_from_this<SimpleNode>
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<SimpleNode> create(std::string name) {
|
|
|
|
static NodePtr create(std::string name) {
|
|
|
|
|
|
|
|
// Теперь эта структура может легально наследоваться от SimpleNode
|
|
|
|
struct EnableMakeShared : public SimpleNode {
|
|
|
|
struct EnableMakeShared : public SimpleNode {
|
|
|
|
EnableMakeShared(std::string n) : SimpleNode(std::move(n)) {}
|
|
|
|
EnableMakeShared(std::string n) : SimpleNode(std::move(n)) {}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
auto ptr = std::make_shared<EnableMakeShared>(std::move(name));
|
|
|
|
return std::make_shared<EnableMakeShared>(std::move(name));
|
|
|
|
ptr->initMixin();
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string& name() const { return name_; }
|
|
|
|
const std::string& name() const override { return name_; }
|
|
|
|
LinkPtr getLink() const override { return mixin_->getLink(); }
|
|
|
|
|
|
|
|
LinkMixinPtr getLinkMixin() const override { return mixin_; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void linkChild(const std::shared_ptr<SimpleNode>& child) { mixin_->linkChild(child); }
|
|
|
|
protected:
|
|
|
|
void unlinkParent() { mixin_->unlinkParent(); }
|
|
|
|
// УБРАНО: const. Теперь возвращается неконстантный shared_ptr, как и ожидается.
|
|
|
|
|
|
|
|
std::shared_ptr<SimpleNode> getShared() override {
|
|
|
|
|
|
|
|
return shared_from_this();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend struct std::enable_shared_from_this<SimpleNode>;
|
|
|
|
|
|
|
|
friend class LazyLinkMixin<SimpleNode>;
|
|
|
|
explicit SimpleNode(std::string name) : name_(std::move(name)) {}
|
|
|
|
explicit SimpleNode(std::string name) : name_(std::move(name)) {}
|
|
|
|
|
|
|
|
|
|
|
|
void initMixin() {
|
|
|
|
|
|
|
|
mixin_ = std::make_shared<LazyLinkMixin<SimpleNode>>(shared_from_this());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string name_;
|
|
|
|
std::string name_;
|
|
|
|
LinkMixinPtr mixin_;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void printTree(const LinkPtr& link, int indent = 0) {
|
|
|
|
// --- УТИЛИТА ДЛЯ ВЫВОДА ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void printTree(const NodePtr& startNode, int indent = 0) {
|
|
|
|
|
|
|
|
if (!startNode) return;
|
|
|
|
for (int i = 0; i < indent; ++i) std::cout << " ";
|
|
|
|
for (int i = 0; i < indent; ++i) std::cout << " ";
|
|
|
|
auto node = link->getLinkMixin()->getNode();
|
|
|
|
std::cout << startNode->name() << "\n";
|
|
|
|
auto simpleNode = std::dynamic_pointer_cast<SimpleNode>(node);
|
|
|
|
LinkPtr nodeLink = startNode->getLink();
|
|
|
|
if (simpleNode) {
|
|
|
|
for (const auto& childLink : nodeLink->getChildren()) {
|
|
|
|
std::cout << simpleNode->name() << "\n";
|
|
|
|
printTree(childLink->getNode(), indent + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& child : link->getChildren()) {
|
|
|
|
|
|
|
|
printTree(child, indent + 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- MAIN ---
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int main() {
|
|
|
|
auto root = SimpleNode::create("Root");
|
|
|
|
auto root = SimpleNode::create("Root");
|
|
|
|
auto child1 = SimpleNode::create("Child1");
|
|
|
|
auto child1 = SimpleNode::create("Child1");
|
|
|
|
@ -295,12 +186,12 @@ int main() {
|
|
|
|
auto subchild = SimpleNode::create("SubChild");
|
|
|
|
auto subchild = SimpleNode::create("SubChild");
|
|
|
|
child1->linkChild(subchild);
|
|
|
|
child1->linkChild(subchild);
|
|
|
|
|
|
|
|
|
|
|
|
printTree(root->getLink());
|
|
|
|
printTree(root);
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "\nUnlinking Child2...\n";
|
|
|
|
std::cout << "\nUnlinking Child1...\n";
|
|
|
|
child2->unlinkParent();
|
|
|
|
child1->unlinkParent();
|
|
|
|
|
|
|
|
|
|
|
|
printTree(root->getLink());
|
|
|
|
printTree(root);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|