Add Elevator Number to Elevators
authorIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 04:14:00 +0000 (21:14 -0700)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 04:14:00 +0000 (21:14 -0700)
All of the Elevators need a unique number so that they can call into the
GUI and update their positions, etc.

Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
elevator.cpp
elevator.hpp
elevatorcontroller.cpp

index d4e7cfb..4a5eb37 100644 (file)
@@ -1,21 +1,23 @@
 #include "elevator.hpp"
 
-Elevator::Elevator ()
+Elevator::Elevator (int elevator_number)
        : state_(STATE_IDLE)
        , wait_(0)
        , direction_(IDLE)
        , position_()
        , stops_()
+       , number_(elevator_number)
 {
        // Intentionally Left Empty
 }
 
-Elevator::Elevator (int starting_floor)
+Elevator::Elevator (int starting_floor, int elevator_number)
        : state_(STATE_IDLE)
        , wait_(0)
        , direction_(IDLE)
        , position_(starting_floor)
        , stops_()
+       , number_(elevator_number)
 {
        // Intentionally Left Empty
 }
index de8d71b..a5b5500 100644 (file)
@@ -21,8 +21,8 @@ enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR
 class Elevator
 {
        public:
-               Elevator ();
-               Elevator (int starting_floor);
+               Elevator (int elevator_number);
+               Elevator (int starting_floor, int elevator_number);
 
                void stop_at (Stop &stop);
                float distance_from (Position& pos) const;
@@ -56,6 +56,9 @@ class Elevator
                State state_;
                int wait_;
 
+               /* Elevator Number: Used to make calls into the GUI */
+               int number_;
+
                static const float ELEVATOR_STEP = 0.1;
 };
 
index 2baea64..d5f760c 100644 (file)
@@ -10,7 +10,7 @@ ElevatorController::ElevatorController (int floors, int elevators)
 
        /* Create and add all of the elevators */
        for (int i=0; i<number_of_elevators_; i++)
-               elevators_.push_back (Elevator());
+               elevators_.push_back (Elevator(i));
 }
 
 static int choose_random_number_in_range (int low, int high)