Files
tws-zombies-scripts/t5/plugins/tws-t5-gsc-utils/src/loader/component_loader.hpp
T
josh 1121b44857 Organize scripts and add TWS plugins with HTTP timeouts
Vendor pinned T5 and T6 plugin sources under the new plugins layout. Add native HTTP deadlines, status and timing diagnostics, telemetry integration, and build/test tooling.
2026-10-09 11:02:20 -04:00

60 lines
1.4 KiB
C++

#pragma once
#include "component_interface.hpp"
class component_loader final
{
public:
class premature_shutdown_trigger final : public std::exception
{
[[nodiscard]] const char* what() const noexcept override
{
return "Premature shutdown requested";
}
};
template <typename T>
class installer final
{
static_assert(std::is_base_of<component_interface, T>::value, "component has invalid base class");
public:
installer(const std::string& name)
{
register_component(name, std::make_unique<T>());
}
};
template <typename T>
static T* get()
{
for (const auto& component_ : get_components())
{
if (typeid(*component_.get()) == typeid(T))
{
return reinterpret_cast<T*>(component_.get());
}
}
return nullptr;
}
static void register_component(const std::string& name, std::unique_ptr<component_interface>&& component);
static void on_startup();
static void on_dvar_init();
static void on_after_dvar_init();
static void on_shutdown();
static void clean();
static void trigger_premature_shutdown();
private:
static std::vector<std::pair<std::string, std::unique_ptr<component_interface>>>& get_components();
};
#define REGISTER_COMPONENT(name) \
namespace \
{ \
static component_loader::installer<name> __component(#name); \
}