enforce ctx in constructor
Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
1 file changed
-36
@@ -13,39 +13,7 @@ namespace vl::mod {
|
||||
#define VL_MOD_SECTION __attribute__((used))
|
||||
#endif
|
||||
|
||||
// --- Contract concepts (NV2 + C2 + lifecycle) ---
|
||||
|
||||
// Must have T(const Context&)
|
||||
|
||||
template<class T>
|
||||
concept HasCtorWithContext =
|
||||
std::constructible_from<T, const Context&>;
|
||||
|
||||
// Must provide compile-time identity (SV1)
|
||||
template<class T>
|
||||
concept HasStaticName =
|
||||
requires { { T::Name() } -> std::same_as<std::string_view>; };
|
||||
|
||||
template<class T>
|
||||
concept HasStaticVersion =
|
||||
requires { { T::Version() } -> std::same_as<std::string_view>; };
|
||||
|
||||
// Must implement lifecycle
|
||||
template<class T>
|
||||
concept HasLifecycle =
|
||||
requires(T& o) {
|
||||
{ o.onStart() } -> std::same_as<void>;
|
||||
{ o.onStop() } -> std::same_as<void>;
|
||||
};
|
||||
|
||||
// --- CRTP base ---
|
||||
// NOTE: constraints placed on the template parameter itself (prevents
|
||||
// GCC from evaluating them before T is complete).
|
||||
template<class T>
|
||||
requires HasCtorWithContext<T> &&
|
||||
HasStaticName<T> &&
|
||||
HasStaticVersion<T> &&
|
||||
HasLifecycle<T>
|
||||
class Mod : public Base {
|
||||
private:
|
||||
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
|
||||
@@ -59,10 +27,6 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
// 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(); }
|
||||
|
||||
virtual ~Mod() = default;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user