enforce ctx in constructor

Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2025-10-20 01:02:54 +03:00
1 parent 4a529c6ea9
commit 175f6cb5c1
1 file changed
+4 -31
+4 -31
View File
@@ -5,30 +5,7 @@
#include <memory>
#include <type_traits>
#include <typeinfo>
template<class T>
concept HasCtorWithContext =
requires(const vl::mod::Context& ctx) {
{ T(ctx) };
};
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>;
};
template<class T>
concept HasLifecycle =
requires(T obj) {
{ obj.onStart() } -> std::same_as<void>;
{ obj.onStop() } -> std::same_as<void>;
};namespace vl::mod {
namespace vl::mod {
#if defined(__ELF__)
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
@@ -39,13 +16,7 @@ concept HasLifecycle =
// ---- Contract Concepts ----
template <
class T
> requires
HasCtorWithContext<T> &&
HasStaticName<T> &&
HasStaticVersion<T> &&
HasLifecycle<T>
template <class T>
class Mod : public Base {
private:
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
@@ -61,9 +32,11 @@ private:
};
public:
Mod(const Context& ctx) : m_ctx(ctx){};
virtual void onStart() = 0;
virtual void onStop() = 0;
virtual ~Mod() = default;
Context m_ctx;
// T provides: T(const Context&), onStart(), onStop()
};