// Lab 14
// Programmer: Arthur Zvenigorodsky
// Editor used: Eclipse IDE for C/C++ Linux Developers
// Compiler used: GCC C++ Compiler
#include <iostream>
using std::ostream;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include "Rider.h"
#include "Floor.h"
#include "Elevator.h"
Floor::Floor(const char* name, const int location)
: NAME(name), location(location)
{
}
// non-inline functions
bool Floor::isPreferredDirectionUp() const // based on Rider with smallest ID
{
// if there are no downRiders. return true
if (!(hasDownRiders()))
{
return 1;
}
else if (!(hasUpRiders()))
{
return 0;
}
// if the ID of the first upRider (upRider[0]) is less than that of the first downRider
else if (upRiders[0] < downRiders[0])
{
return 1;
}
else
{
return 0;
}
}
void Floor::addNewRider(const Rider& rider) // add to up- or down-vector
{
// if added rider's destination is greater than the floor's location
if (rider.getDestination().getLocation() > this->getLocation())
{
// add rider to the upRiders vector
upRiders.push_back(rider);
}
// else add rider to the downRiders vector
{
downRiders.push_back(rider);
}
}
// removeUpRiders -- int is max #of riders...
vector<Rider> Floor::removeUpRiders(int max)
{
vector<Rider> removedRiders;
if (hasUpRiders())
{
vector<Rider> remainingRiders;
for (int i = 0; i < upRiders.size(); i++)
{
if (max > removedRiders.size())
{
removedRiders.push_back(upRiders[i]);
}
else
{
remainingRiders.push_back(upRiders[i]);
}
}
upRiders = remainingRiders;
}
return removedRiders;
}
// removeDownRiders -- ...to move onto elevator
vector<Rider> Floor::removeDownRiders(int max)
{
vector<Rider> removedRiders;
if (hasDownRiders())
{
vector<Rider> remainingRiders;
for (int i = 0; i < downRiders.size(); i++)
{
if (max > removedRiders.size())
{
removedRiders.push_back(downRiders[i]);
}
else
{
remainingRiders.push_back(downRiders[i]);
}
}
downRiders = remainingRiders;
}
return removedRiders;
}
// friend function
ostream& operator<<(ostream& out, const Floor& f)
{
out << "Name: " << f.getName() << "\nLocation: " << f.getLocation() << "\nNumber of Up Riders: " << f.getUpRiderCount() << "\nNumber of Down Riders: " << f.getDownRiderCount();
return out;
}