From 0b738d4e7ca50fa9c1abefd3bf9ccf96d9ea9812 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Thu, 27 Jun 2024 14:27:20 +0000 Subject: [PATCH] Add FindComponent using MetaFunction support --- include/cserver/engine/components.hpp | 79 ++++++++++++++++++++++++++- tests/all_meta.cpp | 57 +++++++++++++++++++ tests/meta.cpp | 58 ++++++++++++++++++++ 3 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 tests/all_meta.cpp create mode 100644 tests/meta.cpp diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 6a52f9b..0470451 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -13,7 +13,11 @@ template struct Options : utempl::TypeList {}; template -struct ComponentConfig {}; +struct ComponentConfig { + using Type = T; + static constexpr auto kOptions = Options; + static constexpr auto kName = name; +}; namespace impl { @@ -142,6 +146,15 @@ inline constexpr auto InitComponents(T& ccontext) -> void { } // namespace impl +#define COMPONENT_REQUIRES(name, impl) \ + template \ + concept name = impl ; \ + template \ + struct name##M { \ + static constexpr auto value = name;\ + } + + template struct ServiceContext { static constexpr auto kNames = names; @@ -163,6 +176,27 @@ struct ServiceContext { constexpr auto I = utempl::Find(names, name); return *Get(this->storage); }; + template