|
2 | 2 |
|
3 | 3 | #include <flow/common.hpp>
|
4 | 4 | #include <flow/log.hpp>
|
5 |
| -#include <flow/step.hpp> |
6 | 5 | #include <log/log.hpp>
|
7 | 6 |
|
8 | 7 | #include <stdx/ct_string.hpp>
|
9 |
| -#include <stdx/cx_vector.hpp> |
10 | 8 | #include <stdx/span.hpp>
|
11 | 9 |
|
12 | 10 | #include <algorithm>
|
| 11 | +#include <array> |
13 | 12 | #include <cstddef>
|
14 | 13 | #include <iterator>
|
15 |
| -#include <type_traits> |
16 | 14 |
|
17 | 15 | namespace flow {
|
18 | 16 | namespace detail {
|
19 |
| -template <typename CTNode> constexpr auto run_func() -> void { |
| 17 | +template <stdx::ct_string FlowName, typename CTNode> |
| 18 | +constexpr auto run_func() -> void { |
20 | 19 | if (CTNode::condition) {
|
| 20 | + if constexpr (not FlowName.empty()) { |
| 21 | + using log_spec_t = |
| 22 | + decltype(get_log_spec<CTNode, log_spec_id_t<FlowName>>()); |
| 23 | + CIB_LOG(typename log_spec_t::flavor, log_spec_t::level, |
| 24 | + "flow.{}({})", typename CTNode::type_t{}, |
| 25 | + typename CTNode::name_t{}); |
| 26 | + } |
21 | 27 | typename CTNode::func_t{}();
|
22 | 28 | }
|
23 | 29 | }
|
24 |
| - |
25 |
| -template <typename Flow, typename CTNode> constexpr auto log_func() -> void { |
26 |
| - if (CTNode::condition) { |
27 |
| - using log_spec_t = decltype(get_log_spec<CTNode, Flow>()); |
28 |
| - CIB_LOG(typename log_spec_t::flavor, log_spec_t::level, "flow.{}({})", |
29 |
| - typename CTNode::type_t{}, typename CTNode::name_t{}); |
30 |
| - } |
31 |
| -} |
32 | 30 | } // namespace detail
|
33 | 31 |
|
34 |
| -struct rt_node { |
35 |
| - FunctionPtr run{}; |
36 |
| - FunctionPtr log_name{}; |
37 |
| - |
38 |
| - private: |
39 |
| - friend constexpr auto operator==(rt_node const &, |
40 |
| - rt_node const &) -> bool = default; |
41 |
| -}; |
42 |
| - |
43 |
| -/** |
44 |
| - * flow::impl is a constant representation of a series of Milestones and actions |
45 |
| - * to be executed in a specific order. |
46 |
| - * |
47 |
| - * flow::builder allows multiple independent components to collaboratively |
48 |
| - * specify a flow::impl. Use flow::builder to create Flows. Independent |
49 |
| - * components can then add their own actions and milestones to a flow::impl |
50 |
| - * relative to other actions and milestones. |
51 |
| - * |
52 |
| - * @tparam Name |
53 |
| - * Name of flow as a compile-time string. |
54 |
| - * |
55 |
| - * @tparam NumSteps |
56 |
| - * The number of Milestones this flow::impl represents. |
57 |
| - * |
58 |
| - * @see flow::builder |
59 |
| - */ |
60 |
| -template <stdx::ct_string Name, std::size_t NumSteps> class impl { |
61 |
| - private: |
62 |
| - constexpr static bool loggingEnabled = not Name.empty(); |
| 32 | +template <stdx::ct_string Name, std::size_t NumSteps> struct impl { |
| 33 | + using node_t = FunctionPtr; |
| 34 | + std::array<node_t, NumSteps> functionPtrs{}; |
63 | 35 |
|
64 |
| - constexpr static auto capacity = [] { |
65 |
| - if constexpr (loggingEnabled) { |
66 |
| - return NumSteps * 2; |
67 |
| - } else { |
68 |
| - return NumSteps; |
69 |
| - } |
70 |
| - }(); |
71 |
| - |
72 |
| - public: |
73 |
| - stdx::cx_vector<FunctionPtr, capacity> functionPtrs{}; |
74 |
| - |
75 |
| - constexpr static bool active = capacity > 0; |
76 | 36 | constexpr static auto name = Name;
|
77 | 37 |
|
78 |
| - using node_t = rt_node; |
79 |
| - |
80 | 38 | template <typename CTNode>
|
81 | 39 | constexpr static auto create_node(CTNode) -> node_t {
|
82 |
| - constexpr auto rf = detail::run_func<CTNode>; |
83 |
| - constexpr auto lf = detail::log_func<log_spec_id_t<Name>, CTNode>; |
84 |
| - return node_t{rf, lf}; |
| 40 | + return detail::run_func<Name, CTNode>; |
85 | 41 | }
|
86 | 42 |
|
87 |
| - /** |
88 |
| - * Create a new flow::impl of Milestones. |
89 |
| - * |
90 |
| - * Do not call this constructor directly, use flow::builder instead. |
91 |
| - * |
92 |
| - * @param newMilestones |
93 |
| - * Array of Milestones to execute in the flow. |
94 |
| - * |
95 |
| - * @see flow::builder |
96 |
| - */ |
97 | 43 | constexpr explicit(true) impl(stdx::span<node_t const, NumSteps> steps) {
|
98 |
| - if constexpr (loggingEnabled) { |
99 |
| - for (auto const &step : steps) { |
100 |
| - functionPtrs.push_back(step.log_name); |
101 |
| - functionPtrs.push_back(step.run); |
102 |
| - } |
103 |
| - } else { |
104 |
| - std::transform(std::cbegin(steps), std::cend(steps), |
105 |
| - std::back_inserter(functionPtrs), |
106 |
| - [](auto const &step) { return step.run; }); |
107 |
| - } |
| 44 | + std::copy(std::cbegin(steps), std::cend(steps), |
| 45 | + std::begin(functionPtrs)); |
108 | 46 | }
|
109 | 47 | };
|
110 | 48 |
|
@@ -135,5 +73,4 @@ template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
|
135 | 73 | }
|
136 | 74 | };
|
137 | 75 | } // namespace detail
|
138 |
| - |
139 | 76 | } // namespace flow
|
0 commit comments