From 1fa4a48ddc2afd30108439460f8ca9853e04b4e7 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Fri, 28 Jun 2024 05:04:14 +0000 Subject: [PATCH] Move operations for working with dependencies into a separate class --- include/cserver/engine/components.hpp | 136 +++++++++++++------------- tests/dependencies.cpp | 1 + 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 0470451..b89453b 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -134,7 +134,7 @@ inline constexpr auto InitComponents(T& ccontext) -> void { for(auto* flag : dependencies) { co_await flag->AsyncWait(); }; - Get(context.storage).emplace(utempl::Wrapper(T::kNames)>{}, context); + Get(context.storage).emplace(utempl::Wrapper(T::kUtils.kNames)>{}, context); auto& componentInitFlag = GetInitFlagFor(ioContext); componentInitFlag.NotifyAll(); if constexpr(requires{Get(context.storage)->Run();}) { @@ -144,6 +144,49 @@ inline constexpr auto InitComponents(T& ccontext) -> void { }(std::make_index_sequence>()); }; +template +struct DependenciesUtils { + static constexpr utempl::TypeList kTypeList; + static constexpr auto kOptions = utempl::Tuple{Ts::kOptions...}; + static constexpr auto kNames = utempl::Tuple{Ts::kName...}; + static constexpr utempl::TypeList kComponentConfigs; + template + static consteval auto GetIndexByType() -> std::size_t { + return utempl::Find>(kTypeList); + }; + + template + static consteval auto GetIndexByName(const utempl::ConstexprString& name) -> std::size_t { + return utempl::Find(kNames, name); + }; + + template