TDT4102-Ovinger/Oving8/Oving 8/Meeting.cpp

125 lines
2.1 KiB
C++
Raw Normal View History

2019-03-03 21:46:58 +01:00
#include "Meeting.h"
2019-03-04 15:10:11 +01:00
Meeting::Meeting(int d, int sT, int eT, Campus loc, string sub, Person * lead) :
day{ d }, startTime{ sT }, endTime{ eT }, location{ loc }, subject{ sub }, leader{ lead }
2019-03-03 21:46:58 +01:00
{
2019-03-04 15:10:11 +01:00
addParticipant(lead);
meetings.emplace(this);
2019-03-03 21:46:58 +01:00
}
int Meeting::getDay() const
{
return day;
}
int Meeting::getStartTime() const
{
return startTime;
}
int Meeting::getEndTime() const
{
return endTime;
}
Campus Meeting::getLocation() const
{
return location;
}
string Meeting::getSubject() const
{
return subject;
}
const Person* Meeting::getLeader() const
{
return leader;
}
2019-03-04 15:10:11 +01:00
void Meeting::addParticipant(Person * person)
2019-03-03 21:46:58 +01:00
{
2019-03-04 15:10:11 +01:00
participants.emplace(person);
2019-03-03 21:46:58 +01:00
}
2019-03-04 15:10:11 +01:00
set<const Person*> Meeting::getParticipants() const
2019-03-03 21:46:58 +01:00
{
2019-03-04 15:10:11 +01:00
return participants;
2019-03-03 21:46:58 +01:00
}
2019-03-04 15:10:11 +01:00
vector<string> Meeting::getParticipantList() const
{
vector<string> names;
for (auto p : participants)
{
names.push_back(p->getName());
}
return names;
2019-03-03 21:46:58 +01:00
}
2019-03-04 15:10:11 +01:00
vector<const Person*> Meeting::findPotentialCoDriving() const
{
vector<const Person*> drivers;
for (const auto m : meetings)
{
if (m->getLocation() == this->location) {
if (m->getDay() == this->day &&
abs(m->getStartTime() - this->startTime) <= 100 &&
abs(m->getEndTime() - this->endTime) <= 100)
{
for (const auto p : m->getParticipants()) {
if (p->hasAvalibleSeats())
drivers.push_back(p);
}
}
}
}
return drivers;
2019-03-03 21:46:58 +01:00
}
ostream & operator<<(ostream & os, const Campus & c)
{
2019-03-04 15:10:11 +01:00
switch (c)
{
case Campus::Trondheim: os << "Trondheim";
break;
case Campus::<EFBFBD>lesund: os << "<EFBFBD>lesund";
break;
case Campus::Gj<EFBFBD>vik: os << "Gj<EFBFBD>vik";
break;
}
return os;
}
2019-03-03 21:46:58 +01:00
2019-03-04 15:10:11 +01:00
ostream& operator<<(ostream & os, const Meeting & m)
{
os << "Subject: " << m.getSubject() << endl;
os << "Location: " << m.getLocation() << endl;
os << "Starttime: " << m.getStartTime() << endl;
os << "Endtime: " << m.getEndTime() << endl;
os << "Leader: " << m.getLeader()->getName() << endl;
os << "Participants: " << endl;
for (auto p : m.getParticipantList())
{
os << p << endl;
2019-03-03 21:46:58 +01:00
}
return os;
}
2019-03-04 15:10:11 +01:00
set<const Meeting*> Meeting::meetings;
Meeting::~Meeting()
{
meetings.erase(this);
}