5 int State::_id_counter = 0;
13 _transitions.push_back(
Transition(event_name, from, to));
14 to._state_machine_ptr =
this;
15 from._state_machine_ptr =
this;
20 for (
auto transition : _transitions ) {
21 watch(transition.event_name(), [
this, transition](
Event& e) {
22 if ( _current->
id() == transition.from().id() ) {
24 _current = &transition.to();
35 if ( _initial == NULL ) {
36 throw(
Exception(
"State machine started without an initial state (call set_initial(...) first)"));
43 if ( _current == NULL ) {
44 throw(
Exception(
"State machine updated without a valid current state (call set_initial(...) first)"));
StateMachine & add_transition(std::string event_name, State &from, State &to)
virtual void entry(const Event &e)=0
StateMachine & set_initial(State &s)
Events that can be emitted, watched, and responded to with event handlers.
States for finite state machines (FSM)
States for the StateMachine class.
virtual void exit(const Event &e)=0
An exception class for Elma.
A finite state machine class.