36371a10ceaadd6940646376c7e8c1b0270430b4
[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 (int elevator_number);
25                 Elevator (int starting_floor, int elevator_number);
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                 int getLoad () const;
33
34         private:
35
36                 /* State Machine: Helper Functions */
37                 Event find_next_event () const;
38
39                 /* State Machine: Transition Functions */
40                 void transition_move_up ();
41                 void transition_move_down ();
42                 void transition_move_idle ();
43                 void transition_open_door ();
44                 void transition_close_door ();
45                 void transition_begin_wait ();
46                 void transition_continue_wait ();
47
48                 /* Analyze the list of stops */
49                 bool currently_at_stop () const;
50
51                 /* Elevator Status Variables */
52                 Direction       direction_;
53                 Position        position_;
54                 StopList        stops_;
55
56                 /* State Machine */
57                 State state_;
58                 int wait_;
59
60                 /* Elevator Number: Used to make calls into the GUI */
61                 int number_;
62
63                 static const float ELEVATOR_STEP = 0.1;
64 };
65
66
67 #endif /* ELEVATOR_HPP */
68
69 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */