qosd: сдавленные наброски по абстрактному дереву
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "ifaces/ILink.h"
|
||||
#include "Logger.h"
|
||||
|
||||
/// \brief Базовая реализация интерфейса ILink для хранения связей между элементами.
|
||||
/// \tparam TElem Тип элемента, между которыми устанавливается связь.
|
||||
template <class TElem>
|
||||
class BaseLink : public ILink<TElem> {
|
||||
public:
|
||||
using ElemPtr = std::shared_ptr<TElem>;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void removeChild(const ElemPtr& child) override {
|
||||
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
||||
}
|
||||
|
||||
void replaceChild(const ElemPtr& oldChild, const ElemPtr& newChild) override {
|
||||
auto it = std::find(children_.begin(), children_.end(), oldChild);
|
||||
if (it != children_.end()) {
|
||||
*it = newChild;
|
||||
}
|
||||
}
|
||||
|
||||
~BaseLink() override {
|
||||
Logger::get("Link").dbg("--- Destructor called for: BaseLink");
|
||||
}
|
||||
protected:
|
||||
std::vector<ElemPtr> children_;
|
||||
std::weak_ptr<TElem> owner_node_;
|
||||
std::weak_ptr<TElem> parent_;
|
||||
};
|
||||
Reference in New Issue
Block a user