fsm
composite_state.h
1 #pragma once
2 
3 #include "state.h"
4 #include "state_machine.h"
5 
6 namespace escad::new_fsm {
7 
8 template <class Derived, class NestedMachine, class Context = detail::NoContext>
9 class composite_state : public state<Derived, Context> {
10 
11 public:
12  composite_state(Context &context, NestedMachine &&nested)
13  : state<Derived, Context>{context}, nested_(nested) {}
14 
15  template <class Event> bool dispatch(const Event &event) {
16  return nested_.dispatch(event);
17  }
18 
19  template <class State> auto nested_in() const {
20  return nested_.template is_in<State>();
21  }
22 
23  template <class State> auto &nested_state() {
24  return nested_.template state<State>();
25  }
26 
27  template <class State> void nested_emplace() {
28  nested_.template emplace<State>();
29  }
30 
31  mpl::const_reference_t<NestedMachine> nested() { return nested_; }
32 
33 private:
34  NestedMachine nested_;
35 };
36 
37 } // namespace escad::new_fsm
Definition: testJsonContexts.cpp:18
Base class for an event.
Definition: states.h:31
Definition: composite_state.h:9
state is a CRTP base class for states.
Definition: state.h:202
This file contains the definition of the state class and related helper templates.
Definition: composite_state.h:6