X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=stop.cpp;h=d4cb7f7ff7c6628a64bc0de641e8be5f9f4ba994;hb=ff557197cf33a848ad2750d515f67f51113b8403;hp=1629074027fcdb06fcf7fc0dcf110f3e5464033d;hpb=90cabce172856326923f36c9a05fae01138d25aa;p=cs356-p1-elevator.git diff --git a/stop.cpp b/stop.cpp index 1629074..d4cb7f7 100644 --- a/stop.cpp +++ b/stop.cpp @@ -1,32 +1,71 @@ #include "stop.hpp" -Stop::Stop (int floor, enum direction mydirection) - : _floor(floor) - , _direction(mydirection) +Stop::Stop (const Position& position, const Direction& direction) + : position_(position) + , direction_(direction) { // Intentionally Left Empty } -bool Stop::operator== (Stop& rhs) +bool Stop::operator== (const Stop& rhs) const { - return (_floor == rhs._floor) && (_direction == rhs._direction); + if (rhs.position_ != position_) + return false; + + if (direction_ == ALL || rhs.direction_ == ALL) + return true; + + return (rhs.direction_ == direction_); +} + +bool Stop::operator< (const Stop& rhs) const +{ + /* If we do not use the direction to help differentiate, then it is + * possible that an object can be neither less, greater, or equal */ + return (position_ < rhs.position_); } -bool Stop::lowerThan (Position& rhs) +bool Stop::operator> (const Stop& rhs) const { - return (_floor < rhs._floor); + return (position_ > rhs.position_); } -bool Stop::higherThan (Position& rhs) +const Direction Stop::getDirection () const { - return (_floor > rhs._floor); + return direction_; } -#if 0 -bool Stop::operator< (Stop& rhs) +const Position Stop::getPosition () const { - return _floor < rhs._floor; + return position_; } -#endif + +std::ostream& operator<< (std::ostream& os, const Stop& rhs) +{ + os << "Stop(" << rhs.position_ << ", "; // << rhs.direction_ << ")"; + + switch (rhs.direction_) + { + case IDLE: + os << "IDLE"; + break; + case UP: + os << "UP"; + break; + case DOWN: + os << "DOWN"; + break; + case ALL: + os << "ALL"; + break; + default: + os << "UNHANDLED"; + break; + } + + os << ")"; + return os; +} + /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */