#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 // ---- Contract concepts ---- // must have T(const Context&) template concept HasCtorWithContext = requires(const Context& ctx) { { T(ctx) }; }; // must have static constexpr std::string_view Name() template concept HasStaticName = requires { { T::Name() } -> std::same_as; }; // must have static constexpr std::string_view Version() template concept HasStaticVersion = requires { { T::Version() } -> std::same_as; }; // must have lifecycle methods template concept HasLifecycle = requires(T& obj) { { obj.onStart() } -> std::same_as; { obj.onStop() } -> std::same_as; }; // ---- CRTP base with delayed constraints ---- template requires HasCtorWithContext && HasStaticName && HasStaticVersion && HasLifecycle class Mod : public Base { private: static std::unique_ptr _vl_factory(const Context& ctx) { return std::make_unique(ctx); } // NOTE: no typeid(T), no T::Name()/Version() here — T is incomplete now. static inline const Registration _vl_reg VL_MOD_SECTION { kModRegMagic, &_vl_factory }; public: // no extra virtuals; T provides onStart()/onStop() and ctor(Context) ~Mod() override = default; }; } // namespace vl::mod