b85fee9efabb771d0c6e2620963b52037e98d789
[cs356-p1-elevator.git] / elevator.cpp
1 #include "elevator.hpp"
2
3 Elevator::Elevator ()
4         : _stops()
5         , _pos()
6         , _direction(IDLE)
7         , _door_status(CLOSED)
8 {
9         // Intentionally Left Empty
10 }
11
12 void Elevator::stop_at (int floor, enum direction _direction)
13 {
14         std::cout << "Adding Stop: Floor=" << floor << " Dir=" << _direction << std::endl;
15         //_stops.insert (Stop(floor, _direction));
16         _stops.push_back (Stop(floor, _direction));
17 }
18
19 /*
20  * Will check if direction needs to be changed, then change it.
21  *
22  * Will move this Elevator one step in the correct direction.
23  *
24  * The correct direction is defined based on the current direction:
25  *
26  * IDLE: Move in the direction that has the most stops
27  *                      - Ex: if there are 10 stops above us, and two below, move DOWN
28  *
29  * UP: Move upwards
30  *
31  * DOWN: Move downwards
32  */
33 void Elevator::move ()
34 {
35         std::cout << "move()" << std::endl;
36 }
37
38 enum direction Elevator::find_best_direction ()
39 {
40         /* Make sure that the current direction is IDLE */
41         if (_direction != IDLE)
42                 throw bad_direction();
43
44         std::vector<Stop>::const_iterator it;
45         int above, below;
46
47         for (above=0, below=0, it = _stops.begin(); it != _stops.end(); it++)
48         {
49 #if 0
50                 if (_pos.lowerThan (*it))
51                         above++;
52
53                 if (_pos.higherThan (*it))
54                         below++;
55 #endif
56         }
57
58         std::cout << "above=" << above << "  below=" << below << std::endl;
59
60         return UP;
61 }
62
63
64
65
66
67
68
69 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */