You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
935 B
C++
27 lines
935 B
C++
#pragma once
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
#include "ifaces/ILink.h"
|
|
|
|
template <class TElem>
|
|
class BaseLink : public ILink<TElem> {
|
|
public:
|
|
BaseLink(std::shared_ptr<TElem> node) : owner_node_(node) {}
|
|
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 removeChild(const std::shared_ptr<TElem>& child) override {
|
|
children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
|
|
}
|
|
|
|
~BaseLink() override {
|
|
std::cout << "--- Destructor called for: " << "BaseLink" << "\n";
|
|
}
|
|
protected:
|
|
std::vector<std::shared_ptr<TElem>> children_;
|
|
std::weak_ptr<TElem> owner_node_;
|
|
std::weak_ptr<TElem> parent_;
|
|
};
|