SMACC2
smacc_transition.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
25namespace smacc2
26{
28template <
29 class Event, class Destination, typename Tag, class TransitionContext,
30 void (TransitionContext::*pTransitionAction)(const Event &)>
32{
33public:
34 typedef Tag TRANSITION_TAG;
35
36private:
38 template <class State>
39 struct reactions
40 {
41 static boost::statechart::result react_without_action(State & stt)
42 {
43 RCLCPP_DEBUG(stt.getLogger(), "[Smacc Transition] REACT WITHOUT ACTION");
45 Transtype;
46 TRANSITION_TAG mock;
47 specificNamedOnExit(stt, mock);
48
49 stt.template notifyTransition<Transtype>();
50 return stt.template transit<Destination>();
51 }
52
53 static boost::statechart::result react_with_action(State & stt, const Event & evt)
54 {
55 RCLCPP_DEBUG(stt.getLogger(), "[Smacc Transition] REACT WITH ACTION AND EVENT");
57 Transtype;
58 TRANSITION_TAG mock;
59 specificNamedOnExit(stt, mock);
60 stt.template notifyTransition<Transtype>();
61 return stt.template transit<Destination>(pTransitionAction, evt);
62 }
63 };
64
65public:
67 // The following declarations should be private.
68 // They are only public because many compilers lack template friends.
70 template <class State, class EventBase, class IdType>
71 static boost::statechart::detail::reaction_result react(
72 State & stt, const EventBase & evt, const IdType & eventType)
73 {
74 typedef boost::statechart::detail::reaction_dispatcher<
75 reactions<State>, State, EventBase, Event, TransitionContext, IdType>
76 dispatcher;
77 return dispatcher::react(stt, evt, eventType);
78 }
79};
80} // namespace smacc2
static boost::statechart::detail::reaction_result react(State &stt, const EventBase &evt, const IdType &eventType)
void specificNamedOnExit(TState &st, TTransitionTagName tn, std::true_type)
static boost::statechart::result react_with_action(State &stt, const Event &evt)
static boost::statechart::result react_without_action(State &stt)