#pragma once #include #include #include #include #include #include namespace vl::mod { #if defined(__ELF__) #define VL_MOD_SECTION __attribute__((section("vlmods"), used)) #else #define VL_MOD_SECTION __attribute__((used)) #endif // detection helpers template concept HasCtorWithContext = std::is_constructible_v; template concept HasStaticName = requires { { T::Name() } -> std::same_as; }; template concept HasStaticVersion = requires { { T::Version() } -> std::same_as; }; template class Mod : public Base { static_assert(HasCtorWithContext, "Any class derived from Mod must have a constructor: T(const vl::log::Context&)"); static_assert(HasStaticName, "Any class derived from Mod must declare: static constexpr std::string_view Name()"); static_assert(HasStaticVersion, "Any class derived from Mod must declare: static constexpr std::string_view Version()"); private: static std::unique_ptr _vl_factory(const Context& ctx) { return std::make_unique(ctx); } static inline const Registration _vl_reg VL_MOD_SECTION { kModRegMagic, &_vl_factory, typeid(T).name(), T::Name().data(), T::Version().data() }; public: // T provides: T(const Context&), onStart(), onStop() }; } // namespace vl::log