From f2db8a222ae23a166e58397243b85550092265f6 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sun, 24 Mar 2024 17:21:17 +0000 Subject: [PATCH] Add GetDependencyGraph method to ServiceContextBuilder --- include/cserver/engine/components.hpp | 40 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index f2a97e8..3fda518 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -69,7 +69,7 @@ struct ServiceContext { storage{ [&](std::index_sequence) -> utempl::Tuple { return {[&](utempl::Wrapper) { - return [&]() -> std::remove_cvref_t(storage))> { + return [&] -> std::remove_cvref_t(storage))> { return {utempl::Wrapper(names)>{}, *this}; }; }(utempl::Wrapper{})...}; @@ -202,12 +202,16 @@ public: static constexpr auto FindComponent() -> T&; template - static consteval auto GetDependencies() requires - requires {Magic(loopholes::Getter{}>{});} { - if constexpr(requires{GetDependencies();}) { - return GetDependencies{}>{}))::Type>(); + static consteval auto GetDependencies() requires (I == 0 || + requires {Magic(loopholes::Getter{}>{});}) { + if constexpr(I == 0 && !requires {Magic(loopholes::Getter{}>{});}) { + return utempl::TypeList{}; } else { - return utempl::kTypeList{}>{}))::Type>; + if constexpr(requires{GetDependencies();}) { + return GetDependencies{}>{}))::Type>(); + } else { + return utempl::kTypeList{}>{}))::Type>; + }; }; }; @@ -219,6 +223,16 @@ public: } // namespace impl +template +struct DependencyGraphElement {}; + + +template +struct DependencyGraph { + static constexpr auto kValue = utempl::TypeList{}; +}; + + template struct ServiceContextBuilder { static constexpr auto kList = utempl::kTypeList; @@ -257,6 +271,20 @@ struct ServiceContextBuilder { return config; }; + static consteval auto GetDependencyGraph() { + return [&] + (ComponentConfig...){ + return DependencyGraph + (ComponentConfig) { + impl::DependencyInfoInjector injector; + injector.template Inject(); + return injector.GetDependencies(); + }(Ts{})>...>{}; + }(Ts{}...); + }; + + static constexpr auto Run() -> void { [] (utempl::TypeList...>) {