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.
37 lines
685 B
C++
37 lines
685 B
C++
#pragma once
|
|
#include <iostream>
|
|
#include "mixins/BaseLinkMixin.h"
|
|
#include <memory>
|
|
|
|
template <class TLink>
|
|
class LazyLinkMixin : public BaseLinkMixin {
|
|
public:
|
|
void unlinkParent() override {
|
|
/* No link -- no parent, who'll unlinked? */
|
|
if (!this->link_)
|
|
throw std::logic_error("Link isn't inited!");
|
|
|
|
BaseLinkMixin::unlinkParent();
|
|
}
|
|
|
|
LinkPtr getLink() override {
|
|
lazyInit();
|
|
return this->link_;
|
|
}
|
|
|
|
LazyLinkMixin() {}
|
|
|
|
~LazyLinkMixin() override {
|
|
std::cout << "--- Destructor called for: " << "LazyLinkMixin" << "\n";
|
|
}
|
|
|
|
protected:
|
|
void lazyInit() {
|
|
if (!link_) {
|
|
link_ = std::make_shared<TLink>(
|
|
BaseLinkMixin::getNode());
|
|
}
|
|
}
|
|
LinkPtr link_;
|
|
};
|