Files
VoidLoaderApi/include/Mod/Mod.hpp
T
faumaray e84b2691cf Mod Base
Signed-off-by: Faumaray <faumaray@gmail.com>
2025-10-20 00:32:43 +03:00

40 lines
1.1 KiB
C++

#pragma once
#include <Mod/Base.hpp>
#include <Mod/Registration.hpp>
#include <memory>
#include <typeinfo>
namespace vl::mod {
// ---- platform section helpers (ELF) ----
#if defined(__ELF__)
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
#else
// Fallback: keep the variable, but discovery code will need a different path on non-ELF.
#define VL_MOD_SECTION __attribute__((used))
#endif
// CRTP base: derive as `class MyMod : public Mod<MyMod> { ... };`
// Requires: `MyMod::MyMod(const Context&)` constructor.
template <class T>
class Mod : public Base {
private:
// Factory thunk that Core will call via the registration record.
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
return std::make_unique<T>(ctx);
}
// One registration record per T in a well-known section.
// This creates *no* runtime cost for mods beyond a single static object.
static inline const Registration _vl_reg VL_MOD_SECTION = {
kModRegMagic,
&_vl_factory,
typeid(T).name()
};
public:
// The rest (onStart/onStop/name/version/ctor) is implemented by T.
};
} // namespace vl::log