Add distance_from(Stop)
[cs356-p1-elevator.git] / elevator.hpp
1 /*
2  * CS356 Project 01 -- Elevator Simulator
3  *
4  * Elevator Class Specification
5  */
6
7 #ifndef ELEVATOR_HPP
8 #define ELEVATOR_HPP
9
10 #include <iostream>
11 #include <list>
12 #include "direction.hpp"
13 #include "position.hpp"
14 #include "stop.hpp"
15
16 typedef std::list<Stop> StopList;
17
18 enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR };
19 enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR };
20
21 class Elevator
22 {
23         public:
24                 Elevator ();
25                 Elevator (int starting_floor);
26
27                 void stop_at (Stop &stop);
28                 float distance_from (Position& pos) const;
29                 float distance_from (Stop& s) const;
30                 void move ();
31                 bool is_idle () const;
32
33         private:
34
35                 /* State Machine: Helper Functions */
36                 Event find_next_event () const;
37
38                 /* State Machine: Transition Functions */
39                 void transition_move_up ();
40                 void transition_move_down ();
41                 void transition_move_idle ();
42                 void transition_open_door ();
43                 void transition_close_door ();
44                 void transition_begin_wait ();
45                 void transition_continue_wait ();
46
47                 /* Analyze the list of stops */
48                 bool currently_at_stop () const;
49
50                 /* Elevator Status Variables */
51                 Direction       direction_;
52                 Position        position_;
53                 StopList        stops_;
54
55                 /* State Machine */
56                 State state_;
57                 int wait_;
58
59                 static const float ELEVATOR_STEP = 0.1;
60 };
61
62
63 #endif /* ELEVATOR_HPP */
64
65 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */