|
|
|
@ -8,21 +8,23 @@
|
|
|
|
template <class TElem>
|
|
|
|
template <class TElem>
|
|
|
|
class BaseLink : public ILink<TElem> {
|
|
|
|
class BaseLink : public ILink<TElem> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
BaseLink(std::shared_ptr<TElem> node) : owner_node_(node) {}
|
|
|
|
using ElemPtr = std::shared_ptr<TElem>;
|
|
|
|
std::shared_ptr<TElem> getNode() const override { return owner_node_.lock(); }
|
|
|
|
|
|
|
|
std::shared_ptr<TElem> getParent() const override { return parent_.lock(); }
|
|
|
|
|
|
|
|
void setParent(const std::shared_ptr<TElem>& parent) override { parent_ = parent; }
|
|
|
|
|
|
|
|
const std::vector<std::shared_ptr<TElem>>& getChildren() const override { return children_; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addChild(const std::shared_ptr<TElem>& child) override {
|
|
|
|
BaseLink(ElemPtr node) : owner_node_(node) {}
|
|
|
|
|
|
|
|
ElemPtr getNode() const override { return owner_node_.lock(); }
|
|
|
|
|
|
|
|
ElemPtr getParent() const override { return parent_.lock(); }
|
|
|
|
|
|
|
|
void setParent(const ElemPtr& parent) override { parent_ = parent; }
|
|
|
|
|
|
|
|
const std::vector<ElemPtr>& getChildren() const override { return children_; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addChild(const ElemPtr& child) override {
|
|
|
|
this->children_.push_back(child);
|
|
|
|
this->children_.push_back(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void removeChild(const std::shared_ptr<TElem>& child) override {
|
|
|
|
void removeChild(const ElemPtr& child) override {
|
|
|
|
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
|
|
|
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void replaceChild(const std::shared_ptr<TElem>& oldChild, const std::shared_ptr<TElem>& newChild) override {
|
|
|
|
void replaceChild(const ElemPtr& oldChild, const ElemPtr& newChild) override {
|
|
|
|
auto it = std::find(children_.begin(), children_.end(), oldChild);
|
|
|
|
auto it = std::find(children_.begin(), children_.end(), oldChild);
|
|
|
|
if (it != children_.end()) {
|
|
|
|
if (it != children_.end()) {
|
|
|
|
*it = newChild;
|
|
|
|
*it = newChild;
|
|
|
|
@ -33,7 +35,7 @@ public:
|
|
|
|
Logger::get("Link").dbg("--- Destructor called for: BaseLink");
|
|
|
|
Logger::get("Link").dbg("--- Destructor called for: BaseLink");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
std::vector<std::shared_ptr<TElem>> children_;
|
|
|
|
std::vector<ElemPtr> children_;
|
|
|
|
std::weak_ptr<TElem> owner_node_;
|
|
|
|
std::weak_ptr<TElem> owner_node_;
|
|
|
|
std::weak_ptr<TElem> parent_;
|
|
|
|
std::weak_ptr<TElem> parent_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|