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.

35 lines
676 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() override {
std::cout << "--- Destructor called for: " << "LazyLinkMixin" << "\n";
}
protected:
void lazyInit() {
if (!this->link_) {
this->link_ = std::make_shared<TLink>(
BaseLinkMixin::getNode());
}
}
LinkPtr link_;
};