ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
base_functors.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Static asserts
4 #include <type_traits>
5 // Internal Transition Event
7 
19 template <class EventT, class RobotSystemT, class LogicStateMachineT>
20 struct ActionFunctor {
28  virtual void run(EventT const &event, RobotSystemT &robot_system) = 0;
29 
36  template <class FSM, class SourceState, class TargetState>
37  void operator()(EventT const &event, FSM &logic_state_machine, SourceState &,
38  TargetState &) {
39  static_assert(
40  std::is_convertible<decltype(
41  logic_state_machine.robot_system_container_()),
42  RobotSystemT &>::value,
43  "Robot system in logic state machine is not the same as one used in "
44  "action functor");
45  static_assert(
46  std::is_base_of<FSM, LogicStateMachineT>::value,
47  "Template Logic state machine arg is not subclass of provided FSM");
48  run(event, logic_state_machine.robot_system_container_());
49  }
50 
54  virtual ~ActionFunctor() {}
55 };
56 
67 template <class EventT, class RobotSystemT, class LogicStateMachineT>
68 struct GuardFunctor {
76  virtual bool guard(EventT const &event, RobotSystemT &robot_system) = 0;
84  template <class FSM, class SourceState, class TargetState>
85  bool operator()(EventT const &event, FSM &logic_state_machine, SourceState &,
86  TargetState &) {
87  static_assert(
88  std::is_convertible<decltype(
89  logic_state_machine.robot_system_container_()),
90  RobotSystemT &>::value,
91  "Robot system in logic state machine is not the same as one used in "
92  "action functor");
93  static_assert(
94  std::is_base_of<FSM, LogicStateMachineT>::value,
95  "Template Logic state machine arg is not subclass of provided FSM");
96  return guard(event, logic_state_machine.robot_system_container_());
97  }
101  virtual ~GuardFunctor() {}
102 };
103 
112 template <class RobotSystemT, class LogicStateMachineT>
120  virtual void run(RobotSystemT &robot_system) = 0;
121 
127  template <class EventT, class FSM, class SourceState, class TargetState>
128  void operator()(EventT const &, FSM &logic_state_machine, SourceState &,
129  TargetState &) {
130  static_assert(
131  std::is_convertible<decltype(
132  logic_state_machine.robot_system_container_()),
133  RobotSystemT &>::value,
134  "Robot system in logic state machine is not the same as one used in "
135  "action functor");
136  static_assert(
137  std::is_base_of<FSM, LogicStateMachineT>::value,
138  "Template Logic state machine arg is not subclass of provided FSM");
139  run(logic_state_machine.robot_system_container_());
140  }
141 
146 };
147 
156 template <class RobotSystemT, class LogicStateMachineT>
164  virtual bool guard(RobotSystemT &robot_system) = 0;
165 
171  template <class EventT, class FSM, class SourceState, class TargetState>
172  bool operator()(EventT const &, FSM &logic_state_machine, SourceState &,
173  TargetState &) {
174  static_assert(
175  std::is_convertible<decltype(
176  logic_state_machine.robot_system_container_()),
177  RobotSystemT &>::value,
178  "Robot system in logic state machine is not the same as one used in "
179  "action functor");
180  static_assert(
181  std::is_base_of<FSM, LogicStateMachineT>::value,
182  "Template Logic state machine arg is not subclass of provided FSM");
183  return guard(logic_state_machine.robot_system_container_());
184  }
185 
190 };
191 
207 template <class RobotSystemT, class LogicStateMachineT>
220  virtual bool run(RobotSystemT &robot_system,
221  LogicStateMachineT &logic_state_machine) = 0;
222 
228  template <class EventT, class FSM, class SourceState, class TargetState>
229  bool operator()(EventT const &, FSM &logic_state_machine, SourceState &,
230  TargetState &) {
231  static_assert(
232  std::is_convertible<decltype(
233  logic_state_machine.robot_system_container_()),
234  RobotSystemT &>::value,
235  "Robot system in logic state machine is not the same as one used in "
236  "action functor");
237  static_assert(
238  std::is_base_of<FSM, LogicStateMachineT>::value,
239  "Template Logic state machine arg is not subclass of provided FSM");
240  LogicStateMachineT *logic_state_machine_cast =
241  static_cast<LogicStateMachineT *>(&logic_state_machine);
242  return run(logic_state_machine.robot_system_container_(),
243  *logic_state_machine_cast);
244  }
245 
250 };
void operator()(EventT const &, FSM &logic_state_machine, SourceState &, TargetState &)
operator () Internally calls run function
Definition: base_functors.h:128
virtual bool guard(RobotSystemT &robot_system)=0
Override this run function for different sub classes. This function performs the logic checking for e...
virtual ~GuardFunctor()
Destructor.
Definition: base_functors.h:101
Internal action that returns whether it processed an event.
Definition: base_functors.h:208
Action functor that does not require the event triggering it.
Definition: base_functors.h:113
virtual ~EventAgnosticGuardFunctor()
virtual destructor to get polymorphism
Definition: base_functors.h:189
virtual bool guard(EventT const &event, RobotSystemT &robot_system)=0
Override this guard function for different sub classes. This function decides whether to call the run...
Action Functor for a given event, robot system, state machine.
Definition: base_functors.h:68
virtual ~ActionFunctor()
Virtual destructor to obtain polymorphism.
Definition: base_functors.h:54
Action Functor for a given event, robot system, state machine.
Definition: base_functors.h:20
virtual void run(EventT const &event, RobotSystemT &robot_system)=0
Override this run function for different sub classes. This function performs the logic checking for e...
bool operator()(EventT const &, FSM &logic_state_machine, SourceState &, TargetState &)
operator () Internally calls run function
Definition: base_functors.h:229
void operator()(EventT const &event, FSM &logic_state_machine, SourceState &, TargetState &)
operator () Internally calls run function
Definition: base_functors.h:37
Guard functor that does not require the event triggering it.
Definition: base_functors.h:157
virtual ~EventAgnosticActionFunctor()
virtual destructor to get polymorphism
Definition: base_functors.h:145
virtual ~InternalActionFunctor()
virtual destructor to get polymorphism
Definition: base_functors.h:249
bool operator()(EventT const &, FSM &logic_state_machine, SourceState &, TargetState &)
operator () Internally calls run function
Definition: base_functors.h:172
virtual void run(RobotSystemT &robot_system)=0
Override this run function for different sub classes. This function performs the logic checking for e...
bool operator()(EventT const &event, FSM &logic_state_machine, SourceState &, TargetState &)
operator () Internally calls guard function
Definition: base_functors.h:85
virtual bool run(RobotSystemT &robot_system, LogicStateMachineT &logic_state_machine)=0
Override this run function for different sub classes. This function performs the logic checking for e...