X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=stop.cpp;h=d4cb7f7ff7c6628a64bc0de641e8be5f9f4ba994;hb=2172ce055533d5865d58538ee00bf609e59b0f99;hp=ce491fcc1e0d9c59393b4c8efc362179cf294742;hpb=dd9988b5db6dc820c5fcd07f88513d126e926d22;p=cs356-p1-elevator.git diff --git a/stop.cpp b/stop.cpp index ce491fc..d4cb7f7 100644 --- a/stop.cpp +++ b/stop.cpp @@ -1,28 +1,71 @@ #include "stop.hpp" -Stop::Stop (int floor, enum direction mydirection) - : Position(floor) - , _direction(mydirection) +Stop::Stop (const Position& position, const Direction& direction) + : position_(position) + , direction_(direction) { // Intentionally Left Empty } -Stop::Stop (Position pos, enum direction mydirection) - : Position (pos) - , _direction (mydirection) +bool Stop::operator== (const Stop& rhs) const { - // Intentionally Left Empty + 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::operator== (Stop& rhs) +bool Stop::operator> (const Stop& rhs) const { - return (Position::operator==(rhs)) && (_direction == rhs._direction); + return (position_ > rhs.position_); } -std::ostream& operator<< (std::ostream& os, Stop& rhs) +const Direction Stop::getDirection () const { - os << "Stop: " << "help me" << " dir=" << rhs._direction; + return direction_; +} + +const Position Stop::getPosition () const +{ + return position_; +} + +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: */