Maki
Loading...
Searching...
No Matches
action.hpp
1//Copyright Florian Goujeon 2021 - 2025.
2//Distributed under the Boost Software License, Version 1.0.
3//(See accompanying file LICENSE or copy at
4//https://www.boost.org/LICENSE_1_0.txt)
5//Official repository: https://github.com/fgoujeon/maki
6
11
12#ifndef MAKI_ACTION_HPP
13#define MAKI_ACTION_HPP
14
15#include "detail/signature_macros.hpp"
16#include "detail/call.hpp"
17#include "null.hpp"
18
19namespace maki
20{
21
25enum class action_signature: char
26{
29
32
35
38
41
44
47
50};
51
58template<action_signature Sig, class Callable>
59struct action
60{
61 static constexpr action_signature signature = Sig;
62 Callable callable;
63};
64
65#define MAKI_DETAIL_X(name) /*NOLINT(cppcoreguidelines-macro-usage)*/ \
66 \
71 template<class Callable> \
72 constexpr action<action_signature::name, Callable> action_##name(const Callable& callable) \
73 { \
74 return {callable}; \
75 }
76MAKI_DETAIL_ACTION_SIGNATURES
77#undef MAKI_DETAIL_X
78
79namespace detail
80{
81 inline constexpr auto null_action = action_v([]{});
82
83 template<action_signature Sig, class Callable>
84 constexpr const auto& to_action(const action<Sig, Callable>& act)
85 {
86 return act;
87 }
88
89 constexpr const auto& to_action(null_t /*ignored*/)
90 {
91 return null_action;
92 }
93
94 template<class T>
95 struct is_action
96 {
97 static constexpr auto value = false;
98 };
99
100 template<action_signature Sig, class Callable>
101 struct is_action<action<Sig, Callable>>
102 {
103 static constexpr auto value = true;
104 };
105
106 template<class T>
107 constexpr bool is_action_v = is_action<T>::value;
108
109 template
110 <
111 class Action,
112 class Context,
113 class Machine,
114 class Event
115 >
116 void call_action
117 (
118 const Action& act,
119 Context& ctx,
120 Machine& mach,
121 const Event& event
122 )
123 {
124 call_callable<action_signature, Action::signature>
125 (
126 act.callable,
127 ctx,
128 mach,
129 event
130 );
131 }
132}
133
134} //namespace
135
136#endif
The Maki library.
IMPLEMENTATION_DETAIL null_t
The type of maki::null
Definition null.hpp:26
action_signature
The set of arguments taken by an action callable.
Definition action.hpp:26
@ c
void action(context&)
Definition action.hpp:31
@ m
void action(machine&)
Definition action.hpp:43
@ cm
void action(context&, machine&)
Definition action.hpp:34
@ cme
void action(context&, machine&, const event&)
Definition action.hpp:37
@ ce
void action(context&, const event&)
Definition action.hpp:40
@ v
void action()
Definition action.hpp:28
@ me
void action(machine&, const event&)
Definition action.hpp:46
@ e
void action(const event&)
Definition action.hpp:49
Represents an action to be given to maki::transition_table.
Definition action.hpp:60
constexpr action< action_signature::v, Callable > action_v(const Callable &callable)
Makes a maki::action with the indicated signature and given callable.
Definition action.hpp:72