--- /dev/null
+test: test.o elevator.o position.o stop.o
+ g++ -o $@ $^
+
+run: test
+ ./test
+
+clean:
+ rm -f *.o test
+
+all: test
+
+.PHONY: run clean all
--- /dev/null
+/*
+ * CS356 Project 01 -- Elevator Simulator
+ *
+ * Direction Enumeration
+ */
+
+#ifndef DIRECTION_HPP
+#define DIRECTION_HPP
+
+enum direction { IDLE, UP, DOWN };
+
+#endif /* DIRECTION_HPP */
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+#include "elevator.hpp"
+
+Elevator::Elevator ()
+ : _stops()
+ , _pos()
+ , _direction(IDLE)
+ , _door_status(CLOSED)
+{
+ // Intentionally Left Empty
+}
+
+void Elevator::stop_at (int floor, enum direction _direction)
+{
+ std::cout << "Adding Stop: Floor=" << floor << " Dir=" << _direction << std::endl;
+ //_stops.insert (Stop(floor, _direction));
+ _stops.push_back (Stop(floor, _direction));
+}
+
+/*
+ * Will check if direction needs to be changed, then change it.
+ *
+ * Will move this Elevator one step in the correct direction.
+ *
+ * The correct direction is defined based on the current direction:
+ *
+ * IDLE: Move in the direction that has the most stops
+ * - Ex: if there are 10 stops above us, and two below, move DOWN
+ *
+ * UP: Move upwards
+ *
+ * DOWN: Move downwards
+ */
+void Elevator::move ()
+{
+ std::cout << "move()" << std::endl;
+}
+
+enum direction Elevator::find_best_direction ()
+{
+ /* Make sure that the current direction is IDLE */
+ if (_direction != IDLE)
+ throw bad_direction();
+
+ std::vector<Stop>::const_iterator it;
+ int above, below;
+
+ for (above=0, below=0, it = _stops.begin(); it != _stops.end(); it++)
+ {
+ if (_pos.lowerThan (*it))
+ above++;
+
+ if (_pos.higherThan (*it))
+ below++;
+ }
+
+ std::cout << "above=" << above << " below=" << below << std::endl;
+
+ return UP;
+}
+
+
+
+
+
+
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+/*
+ * CS356 Project 01 -- Elevator Simulator
+ *
+ * Elevator Class Specification
+ */
+
+#ifndef ELEVATOR_HPP
+#define ELEVATOR_HPP
+
+#include <iostream>
+//#include <set>
+#include <vector>
+#include "position.hpp"
+#include "direction.hpp"
+#include "stop.hpp"
+
+
+enum door_status { CLOSED, OPEN };
+const int elevator_step = 0.1;
+
+class bad_direction { };
+
+class Elevator
+{
+ public:
+ /*
+ * PURPOSE: Construct a new Elevator object
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: A new Elevator will be constructed
+ */
+ Elevator ();
+
+ /*
+ * PURPOSE: Tell the elevator to stop at the given floor,
+ * PURPOSE: going in the given direction.
+ *
+ * REQUIRE: floor is a valid floor
+ * REQUIRE: direction is a valid direction
+ *
+ * PROMISE: The elevator will stop at the floor when it gets there
+ */
+ void stop_at (int floor, enum direction _direction);
+
+ /*
+ * PURPOSE: The elevator will move 1/10th of a floor in the current
+ * PURPOSE: direction.
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: The elevator will move if it has floors to stop at, otherwise
+ * PROMISE: it will sit idle at its current place.
+ */
+ void move ();
+
+ protected:
+ /*
+ * PURPOSE: Find the direction we should move in
+ *
+ * REQUIRE: _direction must be IDLE
+ *
+ * PROMISE: The best direction to move will be returned
+ */
+ enum direction find_best_direction ();
+
+ private:
+ /* Storage for all of the places that we will be stopping */
+ //std::set<Stop> _stops;
+ std::vector<Stop> _stops;
+
+ /* Storage for the current elevator position */
+ Position _pos;
+
+ /* Stores the current direction */
+ enum direction _direction;
+
+ /* Stores the current door status */
+ enum door_status _door_status;
+
+};
+
+#endif /* ELEVATOR_HPP */
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+#include "position.hpp"
+
+Position::Position ()
+ : _major(0)
+ , _minor(0)
+{
+ // Intentionally Empty
+}
+
+Position::Position (int initial_position)
+ : _major(initial_position)
+ , _minor(0)
+{
+ // Intentionally Empty
+}
+
+bool Position::operator== (const Position& rhs)
+{
+ return (_major == rhs._major) && (_minor == rhs._minor);
+}
+
+
+bool Position::operator== (const int rhs)
+{
+ return (_major == rhs) && (_minor == 0);
+}
+
+Position& Position::operator+= (const float rhs)
+{
+ int major = (int)rhs;
+ int minor = (int)((rhs - major) * 10);
+
+ _major += major;
+ _minor += minor;
+
+ return *this;
+}
+
+Position& Position::operator-= (const float rhs)
+{
+ *this += -rhs;
+
+ return *this;
+}
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+/*
+ * CS356 Project 01 -- Elevator Simulator
+ *
+ * Position Class Specification
+ */
+
+#ifndef POSITION_HPP
+#define POSITION_HPP
+
+class Position
+{
+ public:
+ /*
+ * PURPOSE: Construct a new Position object
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: A new Position object will be created, that
+ * PROMISE: starts at position 0.
+ */
+ Position ();
+
+ /*
+ * PURPOSE: Construct a new Position object
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: A new Position object will be created, and will
+ * PROMISE: start at position initial_position
+ */
+ Position (int initial_position);
+
+ /*
+ * PURPOSE: Compare two position objects
+ *
+ * REQUIRE: rhs is a valid Position object
+ *
+ * PROMISE: True if rhs is at the same position, false otherwise
+ */
+ bool operator== (const Position& rhs);
+
+ /*
+ * PURPOSE: Compare a Position and a float
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: True if rhs is within 0.05 of this Position
+ */
+ bool operator== (const int rhs);
+
+ /*
+ * PURPOSE: Add to this Position
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: This Position will have the rhs added to it
+ */
+ Position& operator+= (const float rhs);
+
+ /*
+ * PURPOSE: Subtract from this Position
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: This Position will have the rhs added to it
+ */
+ Position& operator-= (const float rhs);
+
+ protected:
+ private:
+ int _major;
+ int _minor;
+};
+
+#endif /* POSITION_HPP */
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+#include "stop.hpp"
+
+Stop::Stop (int floor, enum direction mydirection)
+ : _floor(floor)
+ , _direction(mydirection)
+{
+ // Intentionally Left Empty
+}
+
+bool Stop::operator== (Stop& rhs)
+{
+ return (_floor == rhs._floor) && (_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: */
--- /dev/null
+/*
+ * CS356 Project 01 -- Elevator Simulator
+ *
+ * Stop Class Specification
+ */
+
+#ifndef STOP_HPP
+#define STOP_HPP
+
+#include "position.hpp"
+#include "direction.hpp"
+
+class Stop
+{
+ public:
+ /* PURPOSE: Construct a new Stop object, and set the floor and direction
+ *
+ * REQUIRE: Nothing
+ *
+ * PROMISE: A new Stop object will be created
+ */
+ Stop (int floor, enum direction mydirection);
+
+ /*
+ * PURPOSE: Check if this and another Stop object is equivalent
+ *
+ * REQUIRE: rhs is a valid Stop object
+ *
+ * PROMISE: Return true if this and rhs are equivalent, false otherwise
+ */
+ bool operator== (Stop& rhs);
+
+ private:
+ /* Storage for the floor */
+ Position _floor;
+
+ /* Storage for the direction */
+ enum direction _direction;
+};
+
+#endif /* STOP_HPP */
+
+/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
--- /dev/null
+#include <iostream>
+using namespace std;
+
+#include "elevator.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);
+
+ return 0;
+}
+