enforce ctx in constructor
Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
1 file changed
+4
-31
+4
-31
@@ -5,30 +5,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
template<class T>
|
namespace vl::mod {
|
||||||
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 {
|
|
||||||
|
|
||||||
#if defined(__ELF__)
|
#if defined(__ELF__)
|
||||||
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
|
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
|
||||||
@@ -39,13 +16,7 @@ concept HasLifecycle =
|
|||||||
// ---- Contract Concepts ----
|
// ---- Contract Concepts ----
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <class T>
|
||||||
class T
|
|
||||||
> requires
|
|
||||||
HasCtorWithContext<T> &&
|
|
||||||
HasStaticName<T> &&
|
|
||||||
HasStaticVersion<T> &&
|
|
||||||
HasLifecycle<T>
|
|
||||||
class Mod : public Base {
|
class Mod : public Base {
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
|
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
|
||||||
@@ -61,9 +32,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Mod(const Context& ctx) : m_ctx(ctx){};
|
||||||
virtual void onStart() = 0;
|
virtual void onStart() = 0;
|
||||||
virtual void onStop() = 0;
|
virtual void onStop() = 0;
|
||||||
virtual ~Mod() = default;
|
virtual ~Mod() = default;
|
||||||
|
Context m_ctx;
|
||||||
// T provides: T(const Context&), onStart(), onStop()
|
// T provides: T(const Context&), onStart(), onStop()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user