diff --git a/include/Mod/Base.hpp b/include/Mod/Base.hpp index 622f36f..d592254 100644 --- a/include/Mod/Base.hpp +++ b/include/Mod/Base.hpp @@ -10,6 +10,9 @@ public: virtual void onStart() = 0; virtual void onStop() = 0; + + virtual std::string_view name() const noexcept = 0; + virtual std::string_view version() const noexcept = 0; }; } // namespace vl::log diff --git a/include/Mod/Mod.hpp b/include/Mod/Mod.hpp index 26044fc..5d4f892 100644 --- a/include/Mod/Mod.hpp +++ b/include/Mod/Mod.hpp @@ -13,38 +13,33 @@ namespace vl::mod { #define VL_MOD_SECTION __attribute__((used)) #endif -// ---- Contract concepts ---- +// --- Contract concepts (NV2 + C2 + lifecycle) --- -// must have T(const Context&) +// Must have T(const Context&) template concept HasCtorWithContext = - requires(const Context& ctx) { - { T(ctx) }; - }; + requires(const Context& ctx) { { T{ctx} }; }; -// must have static constexpr std::string_view Name() +// Must provide compile-time identity (SV1) template concept HasStaticName = - requires { - { T::Name() } -> std::same_as; - }; + requires { { T::Name() } -> std::same_as; }; -// must have static constexpr std::string_view Version() template concept HasStaticVersion = - requires { - { T::Version() } -> std::same_as; - }; + requires { { T::Version() } -> std::same_as; }; -// must have lifecycle methods +// Must implement lifecycle template concept HasLifecycle = - requires(T& obj) { - { obj.onStart() } -> std::same_as; - { obj.onStop() } -> std::same_as; + requires(T& o) { + { o.onStart() } -> std::same_as; + { o.onStop() } -> std::same_as; }; -// ---- CRTP base with delayed constraints ---- +// --- CRTP base --- +// NOTE: constraints placed on the template parameter itself (prevents +// GCC from evaluating them before T is complete). template requires HasCtorWithContext && HasStaticName && @@ -56,14 +51,17 @@ private: return std::make_unique(ctx); } - // NOTE: no typeid(T), no T::Name()/Version() here — T is incomplete now. + // Registration only stores a factory pointer — no early T usage. static inline const Registration _vl_reg VL_MOD_SECTION { kModRegMagic, &_vl_factory }; public: - // no extra virtuals; T provides onStart()/onStop() and ctor(Context) + // R2: runtime identity getters implemented here using NV2 statics + std::string_view name() const noexcept override { return T::Name(); } + std::string_view version() const noexcept override { return T::Version(); } + ~Mod() override = default; };