-
Notifications
You must be signed in to change notification settings - Fork 176
/
elevator.hpp
55 lines (39 loc) · 1.21 KB
/
elevator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef ELEVATOR_HPP_INCLUDED
#define ELEVATOR_HPP_INCLUDED
#include <tinyfsm.hpp>
// ----------------------------------------------------------------------------
// Event declarations
//
struct FloorEvent : tinyfsm::Event
{
int floor;
};
struct Call : FloorEvent { };
struct FloorSensor : FloorEvent { };
struct Alarm : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// Elevator (FSM base class) declaration
//
class Elevator
: public tinyfsm::Fsm<Elevator>
{
/* NOTE: react(), entry() and exit() functions need to be accessible
* from tinyfsm::Fsm class. You might as well declare friendship to
* tinyfsm::Fsm, and make these functions private:
*
* friend class Fsm;
*/
public:
/* default reaction for unhandled events */
void react(tinyfsm::Event const &) { };
virtual void react(Call const &);
virtual void react(FloorSensor const &);
void react(Alarm const &);
virtual void entry(void) { }; /* entry actions in some states */
void exit(void) { }; /* no exit actions at all */
protected:
static constexpr int initial_floor = 0;
static int current_floor;
static int dest_floor;
};
#endif