|
- #pragma once
-
- #include <ecs/config.h>
-
- beg_namespace_ecs_system_execution_adapter
- {
-
- namespace __impl
- {
- template<typename T_predicate>
- struct predicate_holder
- {
- private:
- using predicate_type = T_predicate;
-
- template<typename T_instance>
- using predicate_result_type = decltype(
- std::declval<predicate_type>()(
- std::declval<core::mp::decay_t<T_instance>>().system()));
-
- template<typename T_predicate_result>
- using enabler = std::enable_if_t<T_predicate_result { }, void>;
-
- public:
- template<typename T_func>
- constexpr decltype(auto) detailed_instance(T_func&& func) noexcept
- {
- return [f = std::forward<T_func>(func)](auto& instance, auto& executor)
- -> enabler<predicate_result_type<decltype(instance)>>
- {
- f(instance, executor);
- };
- }
-
- template<typename T_func>
- constexpr decltype(auto) detailed(T_func&& func) noexcept
- {
- return detailed_instance([f = std::forward<T_func>(func)](auto& instance, auto& executor) {
- f(instance.system(), executor);
- });
- }
-
- template<typename T_func>
- constexpr decltype(auto) for_subtasks(T_func&& func) noexcept
- {
- return detailed([f = std::forward<T_func>(func)](auto& system, auto& executor){
- executor.for_subtasks([&system, &f](auto& data){
- f(system, data);
- });
- });
- }
- };
- }
-
- template<typename T_func>
- constexpr decltype(auto) matching(T_func) noexcept
- {
- return __impl::predicate_holder<T_func> { };
- }
-
- constexpr decltype(auto) all() noexcept
- {
- return matching(hana::always(hana::true_c));
- }
-
- template<typename... T_system_tags>
- constexpr decltype(auto) tags(T_system_tags... tags) noexcept
- {
- auto tag_set = hana::make_set(tags...);
- return matching([tag_set](auto& system) {
- auto tag = tag::system::make(system);
- return hana::contains(tag_set, tag);
- });
- }
-
- }
- end_namespace_ecs_system_execution_adapter
|