4 files changed
+101
No files matched your search
@@ -0,0 +1,39 @@
|
||||
#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
|
||||
Reference in new issue
Block a user