From 4d917d63758fe6c10e382afb1f52c06f7a6335d6 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Mon, 1 Jul 2024 18:48:32 +0000 Subject: [PATCH] Change API Component(Wrapper name, auto& context) -> Component(T& context) T::kName --- examples/src/http.cpp | 4 ++-- include/cserver/components/work_guard.hpp | 2 +- include/cserver/engine/components.hpp | 8 ++++---- include/cserver/server/handlers/http_handler_base.hpp | 6 +++--- include/cserver/server/server/server.hpp | 11 +++++------ tests/all_meta.cpp | 6 +++--- tests/dependencies.cpp | 4 ++-- tests/meta.cpp | 6 +++--- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/src/http.cpp b/examples/src/http.cpp index 6413975..1228d51 100644 --- a/examples/src/http.cpp +++ b/examples/src/http.cpp @@ -6,8 +6,8 @@ struct SomeComponent : public cserver::server::handlers::HttpHandlerBaseWithAdde static constexpr utempl::ConstexprString kPath = "/v1/some/"; static constexpr utempl::ConstexprString kName = "name"; static constexpr utempl::ConstexprString kHandlerManagerName = "server"; - inline constexpr SomeComponent(auto name, auto& context) : - HttpHandlerBaseWithAdder(name, context) {}; + inline constexpr SomeComponent(auto& context) : + HttpHandlerBaseWithAdder(context) {}; inline auto HandleRequestThrow(const cserver::server::http::HttpRequest& request) -> cserver::Task { co_return cserver::server::http::HttpResponse{.body = request.url.data()}; diff --git a/include/cserver/components/work_guard.hpp b/include/cserver/components/work_guard.hpp index 032e3d1..6325c7d 100644 --- a/include/cserver/components/work_guard.hpp +++ b/include/cserver/components/work_guard.hpp @@ -6,7 +6,7 @@ namespace cserver { struct StopBlocker { boost::asio::io_context::work guard; - inline constexpr StopBlocker(auto, auto& context) : + inline constexpr StopBlocker(auto& context) : guard(context.template FindComponent().ioContext) {}; }; diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 9f2d801..8a1e883 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -126,6 +126,7 @@ struct ServiceContextForComponent { T& context; static constexpr auto kConfig = T::kConfig; static constexpr auto kUtils = T::kUtils; + static constexpr auto kName = Component::kName; template constexpr auto FindComponent() -> decltype(this->context.template FindComponent()) { @@ -174,8 +175,7 @@ inline constexpr auto InitComponents(T& ccontext) -> void { co_await flag->AsyncWait(); }; ServiceContextForComponent(decltype(T::kUtils)::kComponentConfigs)), T> currentContext{context}; - Get(context.storage).emplace(utempl::Wrapper(T::kUtils.kNames)>{}, - currentContext); + Get(context.storage).emplace(currentContext); auto& componentInitFlag = GetInitFlagFor(ioContext); componentInitFlag.NotifyAll(); if constexpr(requires{Get(context.storage)->Run();}) { @@ -311,7 +311,7 @@ template struct DependencyInfoInjector { static constexpr ConstexprConfig kConfig = Config; static constexpr DependenciesUtils kUtils; - + static constexpr utempl::ConstexprString kName = Current::kName; template static consteval auto FindComponentType() { if constexpr(name == kBasicTaskProcessorName) { @@ -392,7 +392,7 @@ public: }; template static inline consteval auto Inject() { - Ignore{}, DependencyInfoInjector{}>())>(); + Ignore{}>())>(); }; }; diff --git a/include/cserver/server/handlers/http_handler_base.hpp b/include/cserver/server/handlers/http_handler_base.hpp index e849571..5fa1139 100644 --- a/include/cserver/server/handlers/http_handler_base.hpp +++ b/include/cserver/server/handlers/http_handler_base.hpp @@ -40,7 +40,7 @@ struct HttpHandlerBase { }; co_await stream.Close(); }; - inline constexpr HttpHandlerBase(auto, auto&) {}; + inline constexpr HttpHandlerBase(auto&) {}; }; template struct HttpHandlerAdderType { @@ -51,8 +51,8 @@ struct HttpHandlerAdderType { }; template struct HttpHandlerBaseWithAdder : HttpHandlerBase, HttpHandlerAdderType { - inline constexpr HttpHandlerBaseWithAdder(auto name, auto& context) : - HttpHandlerBase(name, context), + inline constexpr HttpHandlerBaseWithAdder(auto& context) : + HttpHandlerBase(context), HttpHandlerAdderType{} {}; }; diff --git a/include/cserver/server/server/server.hpp b/include/cserver/server/server/server.hpp index 483ffa0..a01c8f9 100644 --- a/include/cserver/server/server/server.hpp +++ b/include/cserver/server/server/server.hpp @@ -35,18 +35,17 @@ struct Server : StopBlocker { }); }; template < - utempl::ConstexprString Name, typename T, std::size_t... Is> - inline constexpr Server(std::index_sequence, utempl::Wrapper name, T& context) : - StopBlocker(name, context), + inline constexpr Server(std::index_sequence, T& context) : + StopBlocker(context), taskProcessor(context.template FindComponent()), handlers{context.template FindComponent(kNames)>()...}, - port(T::kConfig.template Get().template Get<"port">()) { + port(T::kConfig.template Get().template Get<"port">()) { }; - inline constexpr Server(auto name, auto& context) : - Server(std::index_sequence_for{}, name, context) { + inline constexpr Server(auto& context) : + Server(std::index_sequence_for{}, context) { }; template auto ProcessHandler(Socket&& socket, http::HttpRequest request) -> Task { diff --git a/tests/all_meta.cpp b/tests/all_meta.cpp index d2a0553..e239a21 100644 --- a/tests/all_meta.cpp +++ b/tests/all_meta.cpp @@ -6,7 +6,7 @@ COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as;}); struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto, auto& context) { + constexpr SomeComponent(auto& context) { context.template FindAllComponents(); }; }; @@ -14,13 +14,13 @@ struct SomeComponent { struct OtherComponent { static constexpr utempl::ConstexprString kName = "other"; auto f() -> void {}; - constexpr OtherComponent(auto, auto& context) {}; + constexpr OtherComponent(auto& context) {}; }; struct OtherComponent2 { static constexpr utempl::ConstexprString kName = "other2"; auto f() -> void {}; - constexpr OtherComponent2(auto, auto& context) {}; + constexpr OtherComponent2(auto& context) {}; }; diff --git a/tests/dependencies.cpp b/tests/dependencies.cpp index b934141..34cbf1f 100644 --- a/tests/dependencies.cpp +++ b/tests/dependencies.cpp @@ -4,14 +4,14 @@ struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto, auto&) {}; + constexpr SomeComponent(auto&) {}; }; struct SomeOtherComponent { SomeComponent& component; static constexpr utempl::ConstexprString kName = "other"; - constexpr SomeOtherComponent(auto, auto& context) : component(context.template FindComponent<"some">()) { + constexpr SomeOtherComponent(auto& context) : component(context.template FindComponent<"some">()) { }; }; diff --git a/tests/meta.cpp b/tests/meta.cpp index 89e16d7..7b6a2fb 100644 --- a/tests/meta.cpp +++ b/tests/meta.cpp @@ -6,7 +6,7 @@ COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as;}); struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto, auto& context) { + constexpr SomeComponent(auto& context) { context.template FindComponent(); }; }; @@ -14,13 +14,13 @@ struct SomeComponent { struct OtherComponent { static constexpr utempl::ConstexprString kName = "other"; auto f() -> void {}; - constexpr OtherComponent(auto, auto& context) {}; + constexpr OtherComponent(auto& context) {}; }; struct OtherComponent2 { static constexpr utempl::ConstexprString kName = "other2"; auto f() -> void {}; - constexpr OtherComponent2(auto, auto& context) {}; + constexpr OtherComponent2(auto& context) {}; };