-
Notifications
You must be signed in to change notification settings - Fork 47
/
step.hpp
95 lines (78 loc) · 2.83 KB
/
step.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
#include <cib/detail/runtime_conditional.hpp>
#include <cib/func_decl.hpp>
#include <flow/common.hpp>
#include <flow/log.hpp>
#include <flow/subgraph_identity.hpp>
#include <sc/string_constant.hpp>
#include <stdx/compiler.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/type_traits.hpp>
#include <type_traits>
namespace flow {
template <stdx::ct_string Type, stdx::ct_string Name,
subgraph_identity Identity, typename Cond, typename F>
struct ct_node {
using is_subgraph = void;
using type_t =
decltype(stdx::ct_string_to_type<Type, sc::string_constant>());
using name_t =
decltype(stdx::ct_string_to_type<Name, sc::string_constant>());
using func_t = F;
constexpr static auto ct_name = Name;
constexpr static auto identity = Identity;
constexpr static auto condition = Cond{};
constexpr auto operator*() const {
if constexpr (Identity == subgraph_identity::REFERENCE) {
return ct_node<Type, Name, subgraph_identity::VALUE, Cond, F>{};
} else {
return ct_node{};
}
}
};
namespace detail {
template <stdx::ct_string Type, stdx::ct_string Name, typename F>
[[nodiscard]] constexpr auto make_node() {
return ct_node<Type, Name, subgraph_identity::REFERENCE,
cib::detail::always_condition_t, F>{};
}
constexpr auto empty_func = []() {};
} // namespace detail
template <stdx::ct_string Name, typename F>
requires(stdx::is_function_object_v<F> and std::is_empty_v<F>)
[[nodiscard]] constexpr auto action(F const &) {
return detail::make_node<"action", Name, F>();
}
template <stdx::ct_string Name> [[nodiscard]] constexpr auto action() {
return action<Name>(cib::func_decl<Name>);
}
template <stdx::ct_string Name> [[nodiscard]] constexpr auto step() {
return action<Name>(cib::func_decl<Name>);
}
template <stdx::ct_string Name> [[nodiscard]] constexpr auto milestone() {
return detail::make_node<"milestone", Name, decltype(detail::empty_func)>();
}
inline namespace literals {
template <stdx::ct_string S> [[nodiscard]] constexpr auto operator""_action() {
return action<S>();
}
template <stdx::ct_string S> [[nodiscard]] constexpr auto operator""_step() {
return action<S>();
}
template <stdx::ct_string S>
[[nodiscard]] constexpr auto operator""_milestone() {
return milestone<S>();
}
} // namespace literals
template <typename Cond, stdx::ct_string Type, stdx::ct_string Name,
subgraph_identity Identity, typename NodeCond, typename F>
constexpr auto
make_runtime_conditional(Cond, ct_node<Type, Name, Identity, NodeCond, F>) {
if constexpr (Identity == subgraph_identity::VALUE) {
return ct_node<Type, Name, Identity, decltype(NodeCond{} and Cond{}),
F>{};
} else {
return ct_node<Type, Name, Identity, NodeCond, F>{};
}
}
} // namespace flow