Add the hacks to fix disabling of buttons
[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 class bad_direction { };
17
18 typedef std::list<Stop> StopList;
19
20 enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR };
21 enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR };
22
23 class Elevator
24 {
25         public:
26                 Elevator (int elevator_number);
27                 Elevator (int starting_floor, int elevator_number);
28
29                 void stop_at (Stop &stop);
30                 float distance_from (Position& pos) const;
31                 float distance_from (Stop& s) const;
32                 void move ();
33                 bool is_idle () const;
34                 int getLoad () const;
35                 bool willStopAt (int floor, Direction direction) const;
36
37         private:
38
39                 /* State Machine: Helper Functions */
40                 Event find_next_event () const;
41
42                 /* State Machine: Transition Functions */
43                 void transition_move_up ();
44                 void transition_move_down ();
45                 void transition_move_idle ();
46                 void transition_open_door ();
47                 void transition_close_door ();
48                 void transition_begin_wait ();
49                 void transition_continue_wait ();
50
51                 /* Analyze the list of stops */
52                 bool currently_at_stop () const;
53
54                 /* Elevator Status Variables */
55                 Direction       direction_;
56                 Position        position_;
57                 StopList        stops_;
58
59                 /* State Machine */
60                 State state_;
61                 int wait_;
62
63                 /* Elevator Number: Used to make calls into the GUI */
64                 int number_;
65
66                 static const float ELEVATOR_STEP = 0.1;
67 };
68
69
70 #endif /* ELEVATOR_HPP */
71
72 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */