43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
#pragma once
|
|
#include <Mod/Base.hpp>
|
|
#include <Mod/Registration.hpp>
|
|
#include <Mod/Context.hpp>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <typeinfo>
|
|
|
|
namespace vl::mod {
|
|
|
|
#if defined(__ELF__)
|
|
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
|
|
#else
|
|
#define VL_MOD_SECTION __attribute__((used))
|
|
#endif
|
|
|
|
template <class T>
|
|
class Mod : public Base {
|
|
private:
|
|
// ---- ENFORCE REQUIRED CONSTRUCTOR: T(const Context&) ----
|
|
static_assert(
|
|
std::is_constructible_v<T, const Context&>,
|
|
"Any class derived from Mod<T> must have a constructor: T(const Context&)"
|
|
);
|
|
|
|
// factory used by the registry
|
|
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
|
|
return std::make_unique<T>(ctx);
|
|
}
|
|
|
|
// auto-registration record (ELF)
|
|
static inline const Registration _vl_reg VL_MOD_SECTION {
|
|
kModRegMagic,
|
|
&_vl_factory,
|
|
typeid(T).name()
|
|
};
|
|
|
|
public:
|
|
// ModBase behavior implemented by T through overrides
|
|
};
|
|
|
|
} // namespace vl::log
|