Elma
An event loop manager for embedded systems
 All Classes Files Functions Enumerations
state.h
1 #ifndef _STATE_H
2 #define _STATE_H
3 
4 #include <string>
5 #include "elma.h"
6 
7 namespace elma {
8 
9  class StateMachine;
10 
12 
14  class State {
15 
16  friend class StateMachine;
17 
18  public:
19 
21  State() : _name("unnamed state"), _state_machine_ptr(NULL) {
22  _id = _id_counter++;
23  }
24 
26  State(std::string name) : _name(name), _state_machine_ptr(NULL) {
27  _id = _id_counter++;
28  }
29 
31  inline std::string name() { return _name; }
32 
34  inline int id() { return _id; }
35 
40  virtual void entry(const Event& e) = 0;
41 
44  virtual void during() = 0;
45 
50  virtual void exit(const Event& e) = 0;
51 
54  void emit(const Event& e);
55 
56  private:
57  std::string _name;
58  int _id;
59  static int _id_counter;
60  StateMachine * _state_machine_ptr;
61 
62  };
63 
64 }
65 
66 #endif
int id()
Definition: state.h:34
virtual void entry(const Event &e)=0
State()
Construct an unnamed State.
Definition: state.h:21
Events that can be emitted, watched, and responded to with event handlers.
Definition: event.h:23
States for the StateMachine class.
Definition: state.h:14
virtual void exit(const Event &e)=0
std::string name()
Definition: state.h:31
State(std::string name)
Construct a state with the given name.
Definition: state.h:26
void emit(const Event &e)
Definition: state.cc:5
virtual void during()=0
A finite state machine class.
Definition: state_machine.h:13
Definition: manager.h:11