-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathimpl.hpp
76 lines (63 loc) · 2.24 KB
/
impl.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
#pragma once
#include <flow/common.hpp>
#include <flow/log.hpp>
#include <log/log.hpp>
#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/span.hpp>
#include <stdx/type_traits.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator>
namespace flow {
namespace detail {
template <stdx::ct_string FlowName, typename CTNode>
constexpr auto run_func() -> void {
if (CTNode::condition) {
if constexpr (not FlowName.empty()) {
logging::log<
decltype(get_log_env<CTNode, log_env_id_t<FlowName>>())>(
__FILE__, __LINE__,
stdx::ct_format<"flow.{}({})">(stdx::cts_t<CTNode::ct_type>{},
stdx::cts_t<CTNode::ct_name>{}));
}
typename CTNode::func_t{}();
}
}
} // namespace detail
template <stdx::ct_string Name, std::size_t NumSteps> struct impl {
using node_t = FunctionPtr;
std::array<FunctionPtr, NumSteps> functionPtrs{};
constexpr static auto name = Name;
template <typename CTNode>
constexpr static auto create_node(CTNode) -> node_t {
constexpr auto fp = detail::run_func<Name, CTNode>;
return fp;
}
constexpr explicit(true) impl(stdx::span<node_t const, NumSteps> steps) {
std::copy(std::cbegin(steps), std::cend(steps),
std::begin(functionPtrs));
}
};
namespace detail {
template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
constexpr static auto active = sizeof...(FuncPtrs) > 0;
constexpr static auto ct_name = Name;
__attribute__((flatten, always_inline)) auto operator()() const -> void {
constexpr static bool loggingEnabled = not Name.empty();
if constexpr (loggingEnabled) {
logging::log<decltype(get_log_env<inlined_func_list>())>(
__FILE__, __LINE__,
stdx::ct_format<"flow.start({})">(stdx::cts_t<Name>{}));
}
(FuncPtrs(), ...);
if constexpr (loggingEnabled) {
logging::log<decltype(get_log_env<inlined_func_list>())>(
__FILE__, __LINE__,
stdx::ct_format<"flow.end({})">(stdx::cts_t<Name>{}));
}
}
};
} // namespace detail
} // namespace flow