template<typename Source,
detail::EventSource< Source > ev, typename
Target, auto Cond = DefaultStateCondition, auto Op = DefaultStateTransition>
struct zyppng::Transition< Source, ev, Target, Cond, Op >
Defines a transition between Source and Target states. The EventSource ev triggers the transition from Source to Target if the condition Cond evaluates to true. The operation Op is called between exiting the old and entering the new state. It can be used to transfer information from the old into the new state.
- Template Parameters
-
Source | defines the type of the Source state |
ev | takes a member function pointer returning the event trigger signal that is used to trigger the transition to Target |
Target | defines the type of the Target state |
Cond | Defines the transition condition, can be used if the same event could trigger different transitions based on a condition, this can also be set to a simple boolean true or false |
Op | defines the transition operation from Source to Target states, this is either a function with the signature: std::unique_ptr<Target> ( Statemachine &, Source & ) or it can be a member function pointer of Source with the signature: std::unique_ptr<Target> ( Source::* ) ( ) |
- Note
- While it would be possible to implement the statemachine to operate only on non pointer types for the states , I chose to use std::unique_ptr<State> instead to make the handling of States with signals less error prone. Because even move assigning a signal that has connected lambda slots which have captured the this pointer will break the code. While it could be worked around to connect and disconnect signals in the enter() and exit() functions not doing so would crash the code. Leaving that note here in case we want to change that behaviour in the future.
Definition at line 237 of file statemachine.h.