44#include < flow/step.hpp>
55#include < log/log.hpp>
66
7+ #include < stdx/ct_string.hpp>
78#include < stdx/cx_vector.hpp>
89#include < stdx/span.hpp>
910
1314#include < type_traits>
1415
1516namespace 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+
1642/* *
1743 * flow::impl is a constant representation of a series of Milestones and actions
1844 * to be executed in a specific order.
@@ -45,11 +71,18 @@ template <stdx::ct_string Name, std::size_t NumSteps> class impl {
4571 public:
4672 stdx::cx_vector<FunctionPtr, capacity> functionPtrs{};
4773
48- using node_t = rt_node;
4974 constexpr static bool active = capacity > 0 ;
50-
5175 constexpr static auto name = Name;
5276
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+
5386 /* *
5487 * Create a new flow::impl of Milestones.
5588 *
@@ -60,24 +93,24 @@ template <stdx::ct_string Name, std::size_t NumSteps> class impl {
6093 *
6194 * @see flow::builder
6295 */
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) {
6597 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 );
69101 }
70102 } else {
71- std::transform (std::cbegin (newMilestones ), std::cend (newMilestones ),
103+ std::transform (std::cbegin (steps ), std::cend (steps ),
72104 std::back_inserter (functionPtrs),
73- [](auto const &milestone ) { return milestone .run ; });
105+ [](auto const &step ) { return step .run ; });
74106 }
75107 }
76108};
77109
78110namespace detail {
79111template <stdx::ct_string Name, auto ... FuncPtrs> struct inlined_func_list {
80112 constexpr static auto active = sizeof ...(FuncPtrs) > 0 ;
113+ constexpr static auto ct_name = Name;
81114
82115 __attribute__ ((flatten, always_inline)) auto operator ()() const -> void {
83116 constexpr static bool loggingEnabled = not Name.empty ();
@@ -86,13 +119,17 @@ template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
86119 stdx::ct_string_to_type<Name, sc::string_constant>();
87120
88121 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);
90125 }
91126
92127 (FuncPtrs (), ...);
93128
94129 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);
96133 }
97134 }
98135};
0 commit comments