BUGFIX: Elevators did not handle Requests in the correct order
[cs356-p1-elevator.git] / stop.cpp
1 #include "stop.hpp"
2
3 Stop::Stop (const Position& position, const Direction& direction)
4         : position_(position)
5         , direction_(direction)
6 {
7         // Intentionally Left Empty
8 }
9
10 bool Stop::operator== (const Stop& rhs) const
11 {
12         if (rhs.position_ != position_)
13                 return false;
14
15         /* This is here to keep the order with "ALL" stops correct */
16         if (direction_ == ALL || rhs.direction_ == ALL)
17                 return true;
18
19         return (rhs.direction_ == direction_);
20 }
21
22 bool Stop::operator< (const Stop& rhs) const
23 {
24         /* If we do not use the direction to help differentiate, then it is
25          * possible that an object can be neither less, greater, or equal */
26         return (position_ < rhs.position_);
27 }
28
29 bool Stop::operator> (const Stop& rhs) const
30 {
31         return (position_ > rhs.position_);
32 }
33
34 const Direction Stop::getDirection () const
35 {
36         return direction_;
37 }
38
39 const Position Stop::getPosition () const
40 {
41         return position_;
42 }
43
44 std::ostream& operator<< (std::ostream& os, const Stop& rhs)
45 {
46         os << "Stop(" << rhs.position_ << ", "; // << rhs.direction_ << ")";
47
48         switch (rhs.direction_)
49         {
50                 case IDLE:
51                         os << "IDLE";
52                         break;
53                 case UP:
54                         os << "UP";
55                         break;
56                 case DOWN:
57                         os << "DOWN";
58                         break;
59                 case ALL:
60                         os << "ALL";
61                         break;
62                 default:
63                         os << "UNHANDLED";
64                         break;
65         }
66
67         os << ")";
68         return os;
69 }
70
71 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */