for (above=0, below=0, it = _stops.begin(); it != _stops.end(); it++)
{
+#if 0
if (_pos.lowerThan (*it))
above++;
if (_pos.higherThan (*it))
below++;
+#endif
}
std::cout << "above=" << above << " below=" << below << std::endl;
return *this;
}
+bool Position::operator< (const Position& rhs)
+{
+ if (_major < rhs._major)
+ return true;
+
+ if (_major == rhs._major)
+ if (_minor < rhs._minor)
+ return true;
+
+ return false;
+}
+#include <iostream>
+
+bool Position::operator> (const Position& rhs)
+{
+ if (_major > rhs._major)
+ return true;
+
+ if (_major == rhs._major)
+ if (_minor > rhs._minor)
+ return true;
+
+ return false;
+}
+
+
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
*/
Position& operator-= (const float rhs);
+ bool operator< (const Position& rhs);
+ bool operator> (const Position& rhs);
+
protected:
- private:
int _major;
int _minor;
+
+ private:
};
#endif /* POSITION_HPP */
#include "stop.hpp"
Stop::Stop (int floor, enum direction mydirection)
- : _floor(floor)
+ : Position(floor)
, _direction(mydirection)
{
// Intentionally Left Empty
bool Stop::operator== (Stop& rhs)
{
- return (_floor == rhs._floor) && (_direction == rhs._direction);
+ return (Position::operator==(rhs)) && (_direction == rhs._direction);
}
-bool Stop::lowerThan (Position& rhs)
-{
- return (_floor < rhs._floor);
-}
-
-bool Stop::higherThan (Position& rhs)
-{
- return (_floor > rhs._floor);
-}
-
-#if 0
-bool Stop::operator< (Stop& rhs)
-{
- return _floor < rhs._floor;
-}
-#endif
-
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
#include "position.hpp"
#include "direction.hpp"
-class Stop
+class Stop : public Position
{
public:
/* PURPOSE: Construct a new Stop object, and set the floor and direction
bool operator== (Stop& rhs);
private:
- /* Storage for the floor */
- Position _floor;
/* Storage for the direction */
enum direction _direction;
#include <iostream>
using namespace std;
-#include "elevator.hpp"
+//#include "elevator.hpp"
+#include "stop.hpp"
int main (int argc, char *argv[])
{
- Elevator e;
-
- e.stop_at (2, UP);
- e.stop_at (3, UP);
- e.stop_at (4, UP);
- e.stop_at (5, DOWN);
- e.stop_at (6, DOWN);
-
- e.move ();
-
- Elevator e2;
-
- e.stop_at (3, DOWN);
+ Stop s1 (1, DOWN);
+ Stop s2 (2, DOWN);
+
+ if (s1 > s2)
+ cout << "s1 > s2" << endl;
+ else if (s1 == s2)
+ cout << "s1 == s2" << endl;
+ else if (s1 < s2)
+ cout << "s1 < s2" << endl;
+ else
+ cout << "BAD BAD BAD" << endl;
return 0;
}