4
4
#include < flow/step.hpp>
5
5
#include < log/log.hpp>
6
6
7
+ #include < stdx/ct_string.hpp>
7
8
#include < stdx/cx_vector.hpp>
8
9
#include < stdx/span.hpp>
9
10
13
14
#include < type_traits>
14
15
15
16
namespace flow {
17
+ namespace detail {
18
+ template <typename CTNode> constexpr auto run_func () -> void {
19
+ if (CTNode::condition) {
20
+ typename CTNode::func_t {}();
21
+ }
22
+ }
23
+
24
+ template <typename Flow, typename CTNode> constexpr auto log_func () -> void {
25
+ if (CTNode::condition) {
26
+ using log_spec_t = decltype (get_log_spec<CTNode, Flow>());
27
+ CIB_LOG (typename log_spec_t ::flavor, log_spec_t ::level, " flow.{}({})" ,
28
+ typename CTNode::type_t {}, typename CTNode::name_t {});
29
+ }
30
+ }
31
+ } // namespace detail
32
+
33
+ struct rt_node {
34
+ FunctionPtr run{};
35
+ FunctionPtr log_name{};
36
+
37
+ private:
38
+ friend constexpr auto operator ==(rt_node const &,
39
+ rt_node const &) -> bool = default ;
40
+ };
41
+
16
42
/* *
17
43
* flow::impl is a constant representation of a series of Milestones and actions
18
44
* to be executed in a specific order.
@@ -45,11 +71,18 @@ template <stdx::ct_string Name, std::size_t NumSteps> class impl {
45
71
public:
46
72
stdx::cx_vector<FunctionPtr, capacity> functionPtrs{};
47
73
48
- using node_t = rt_node;
49
74
constexpr static bool active = capacity > 0 ;
50
-
51
75
constexpr static auto name = Name;
52
76
77
+ using node_t = rt_node;
78
+
79
+ template <typename CTNode>
80
+ constexpr static auto create_node (CTNode) -> node_t {
81
+ constexpr auto rf = detail::run_func<CTNode>;
82
+ constexpr auto lf = detail::log_func<log_spec_id_t <Name>, CTNode>;
83
+ return node_t {rf, lf};
84
+ }
85
+
53
86
/* *
54
87
* Create a new flow::impl of Milestones.
55
88
*
@@ -60,24 +93,24 @@ template <stdx::ct_string Name, std::size_t NumSteps> class impl {
60
93
*
61
94
* @see flow::builder
62
95
*/
63
- constexpr explicit (true )
64
- impl(stdx::span<node_t const , NumSteps> newMilestones) {
96
+ constexpr explicit (true ) impl(stdx::span<node_t const , NumSteps> steps) {
65
97
if constexpr (loggingEnabled) {
66
- for (auto const &milestone : newMilestones ) {
67
- functionPtrs.push_back (milestone .log_name );
68
- functionPtrs.push_back (milestone .run );
98
+ for (auto const &step : steps ) {
99
+ functionPtrs.push_back (step .log_name );
100
+ functionPtrs.push_back (step .run );
69
101
}
70
102
} else {
71
- std::transform (std::cbegin (newMilestones ), std::cend (newMilestones ),
103
+ std::transform (std::cbegin (steps ), std::cend (steps ),
72
104
std::back_inserter (functionPtrs),
73
- [](auto const &milestone ) { return milestone .run ; });
105
+ [](auto const &step ) { return step .run ; });
74
106
}
75
107
}
76
108
};
77
109
78
110
namespace detail {
79
111
template <stdx::ct_string Name, auto ... FuncPtrs> struct inlined_func_list {
80
112
constexpr static auto active = sizeof ...(FuncPtrs) > 0 ;
113
+ constexpr static auto ct_name = Name;
81
114
82
115
__attribute__ ((flatten, always_inline)) auto operator ()() const -> void {
83
116
constexpr static bool loggingEnabled = not Name.empty ();
@@ -86,13 +119,17 @@ template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
86
119
stdx::ct_string_to_type<Name, sc::string_constant>();
87
120
88
121
if constexpr (loggingEnabled) {
89
- CIB_TRACE (" flow.start({})" , name);
122
+ using log_spec_t = decltype (get_log_spec<inlined_func_list>());
123
+ CIB_LOG (typename log_spec_t ::flavor, log_spec_t ::level,
124
+ " flow.start({})" , name);
90
125
}
91
126
92
127
(FuncPtrs (), ...);
93
128
94
129
if constexpr (loggingEnabled) {
95
- CIB_TRACE (" flow.end({})" , name);
130
+ using log_spec_t = decltype (get_log_spec<inlined_func_list>());
131
+ CIB_LOG (typename log_spec_t ::flavor, log_spec_t ::level,
132
+ " flow.end({})" , name);
96
133
}
97
134
}
98
135
};
0 commit comments