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.

39 lines
885 B
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include <iostream>
#include "mixins/BaseLinkMixin.h"
#include <memory>
#include "Logger.h"
/// \brief Миксин для ленивой инициализации связи (link) с дочерними элементами.
/// \tparam TLink Тип используемой связи (link).
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 {
Logger::get("ConDes").info("--- Destructor called for: LazyLinkMixin");
}
protected:
void lazyInit() {
if (!link_) {
link_ = std::make_shared<TLink>(*this);
}
}
LinkPtr link_;
};