#pragma once #include "component_interface.hpp" class component_loader final { public: template class installer final { static_assert(std::is_base_of::value, "component has invalid base class"); public: installer() { register_component(std::make_unique()); } }; template static T* get() { for (const auto& component_ : get_components()) { if (typeid(*component_.get()) == typeid(T)) { return reinterpret_cast(component_.get()); } } return nullptr; } static void register_component(std::unique_ptr&& component); static bool post_start(); static bool post_load(); static void post_unpack(); static void pre_destroy(); static void clean(); static void* load_import(const std::string& library, const std::string& function); private: static std::vector>& get_components(); }; #define REGISTER_COMPONENT(name) \ namespace \ { \ static component_loader::installer __component; \ }