diff --git a/Oving 8/Oving 8/Meeting.cpp b/Oving 8/Oving 8/Meeting.cpp index f83e608..3f479cb 100644 --- a/Oving 8/Oving 8/Meeting.cpp +++ b/Oving 8/Oving 8/Meeting.cpp @@ -3,8 +3,12 @@ -Meeting::Meeting() + +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 } { + addParticipant(lead); + meetings.emplace(this); } int Meeting::getDay() const @@ -37,36 +41,84 @@ const Person* Meeting::getLeader() const return leader; } - -Meeting::~Meeting() +void Meeting::addParticipant(Person * person) { + participants.emplace(person); } -Campus begin(Campus c) +set Meeting::getParticipants() const { - return Campus::First; + return participants; + } -Campus end(Campus c) +vector Meeting::getParticipantList() const { - return Campus::Last; + vector names; + for (auto p : participants) + { + names.push_back(p->getName()); + } + return names; } -Campus operator++(Campus& x) { - return x = (Campus)(std::underlying_type::type(x) + 1); -} +vector Meeting::findPotentialCoDriving() const +{ + vector drivers; -Campus operator*(Campus c) { - return c; + 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; } - ostream & operator<<(ostream & os, const Campus & c) { - - //string campus; - for (auto city : c) { - os << city << endl; + switch (c) + { + case Campus::Trondheim: os << "Trondheim"; + break; + case Campus::Ålesund: os << "Ålesund"; + break; + case Campus::Gjøvik: os << "Gjøvik"; + break; } return os; } + +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; + } + return os; +} + +set Meeting::meetings; + + + +Meeting::~Meeting() +{ + meetings.erase(this); +} diff --git a/Oving 8/Oving 8/Meeting.h b/Oving 8/Oving 8/Meeting.h index ef1bdf5..230e0f4 100644 --- a/Oving 8/Oving 8/Meeting.h +++ b/Oving 8/Oving 8/Meeting.h @@ -5,19 +5,11 @@ enum class Campus { - trondheim, - ålesund, - gjøvik, - - First = trondheim, - Last = gjøvik + Trondheim, + Ålesund, + Gjøvik }; -Campus begin(Campus c); -Campus end(Campus c); -Campus operator++(Campus& x); -Campus operator*(Campus c); - ostream& operator<<(ostream& os, const Campus& c); @@ -26,22 +18,45 @@ class Meeting int day; int startTime; int endTime; - Campus location; - string subject; - const Person* leader; - set participants; -public: - Meeting(); + Campus location; + + string subject; + + const Person* leader; + + set participants; + + static set meetings; + +public: + Meeting(int d, int sT, int eT, Campus loc, string sub, Person* lead); + int getDay() const; int getStartTime() const; int getEndTime() const; + Campus getLocation() const; + string getSubject() const; + const Person* getLeader() const; - virtual ~Meeting(); + void addParticipant(Person* person); + + set getParticipants() const; + vector getParticipantList() const; + + vector findPotentialCoDriving() const; + + ~Meeting(); }; +ostream& operator<<(ostream& os, const Meeting& m); + + + + + diff --git a/Oving 8/Oving 8/MeetingWindow.cpp b/Oving 8/Oving 8/MeetingWindow.cpp new file mode 100644 index 0000000..189b070 --- /dev/null +++ b/Oving 8/Oving 8/MeetingWindow.cpp @@ -0,0 +1,39 @@ +#include "MeetingWindow.h" + +using namespace Graph_lib; + + +Vector_ref MeetingWindow::getPeople() +{ + return people; +} + +MeetingWindow::MeetingWindow(Point xy, int w, int h, const string & title) : + Window{ xy, w, h, title }, + quitBtn{ Point{x_max() - pad - btnW, pad }, btnW, btnH, "Quit", cb_quit }, + newPersBtn{ newPersPos, btnW, btnH, "New Person", cb_newPers }, + name{nameInPos, fieldW, fieldH, "Name"}, + email{mailInPos, fieldW, fieldH, "E-Mail"} +{ + attach(quitBtn); + attach(newPersBtn); + attach(name); + attach(email); + + ti = title; +} + +void MeetingWindow::cb_quit(Address, Address pw) { reference_to(pw).quit(); } + +void MeetingWindow::cb_newPers(Address, Address pw){ reference_to(pw).newPers(); } + +void MeetingWindow::newPers() +{ + cout << name.get_string() << " --- " << email.get_string() << endl; + people.push_back(new Person{ name.get_string(), email.get_string() }); + redraw(); +} + +MeetingWindow::~MeetingWindow() +{ +} diff --git a/Oving 8/Oving 8/MeetingWindow.h b/Oving 8/Oving 8/MeetingWindow.h new file mode 100644 index 0000000..0c15ca3 --- /dev/null +++ b/Oving 8/Oving 8/MeetingWindow.h @@ -0,0 +1,53 @@ +#pragma once +#include "GUI.h" +#include "Graph.h" +#include "Meeting.h" +#include "std_lib_facilities.h" + +using namespace Graph_lib; + +class MeetingWindow : public Graph_lib::Window +{ + static constexpr int pad = 50; + static constexpr int fieldPad = 100; + static constexpr int fieldH = 50; + static constexpr int fieldW = 200; + static constexpr int btnH = 50; + static constexpr int btnW = 100; + + static constexpr Point nameInPos{ pad, pad }; + static constexpr Point mailInPos{ pad, nameInPos.y + fieldH + pad }; + static constexpr Point newPersPos{ pad, mailInPos.y + fieldH + pad }; + + + Button quitBtn; + Button newPersBtn; + + In_box name; + In_box email; + + string ti; + + Vector_ref people; + + +public: + + Vector_ref getPeople(); + + MeetingWindow(Point xy, int w, int h, const string& title); + + // Callback + static void cb_quit(Address, Address pw); // cb for quitbtn + static void cb_newPers(Address, Address pw); // cb for newPersBtn + + + // Callback-functions + void quit() { cout << ti + ": quit called\n"; hide(); } // action to be done when quit_button is pressed + void newPers(); + + + + ~MeetingWindow(); +}; + diff --git a/Oving 8/Oving 8/Oving 8.vcxproj b/Oving 8/Oving 8/Oving 8.vcxproj index 485a6f3..74887b5 100644 --- a/Oving 8/Oving 8/Oving 8.vcxproj +++ b/Oving 8/Oving 8/Oving 8.vcxproj @@ -22,11 +22,13 @@ + + diff --git a/Oving 8/Oving 8/Oving 8.vcxproj.filters b/Oving 8/Oving 8/Oving 8.vcxproj.filters index c8fa99d..76b6c4e 100644 --- a/Oving 8/Oving 8/Oving 8.vcxproj.filters +++ b/Oving 8/Oving 8/Oving 8.vcxproj.filters @@ -27,6 +27,9 @@ Source Files + + Source Files + @@ -38,5 +41,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Oving 8/Oving 8/main.cpp b/Oving 8/Oving 8/main.cpp index 444e38f..128e6eb 100644 --- a/Oving 8/Oving 8/main.cpp +++ b/Oving 8/Oving 8/main.cpp @@ -1,24 +1,57 @@ // Example program in TDT4102_Graphics template, from PPP page 415 +#include "GUI.h" #include "Graph.h" -#include "Simple_window.h" +#include "MeetingWindow.h" #include "Meeting.h" +// The following pragma turns off the console +//#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") + +using namespace Graph_lib; + int main() { + /* Car c1{ 5 }; Car c2{ 0 }; + Car c3{ 4 }; Person p1{ "Oyvind", "mail", &c1 }; Person p2{ "Ulrik", "mail2" }; Person p3{ "Live", "mail3", &c2 }; + Person p4{ "Per", "mail4", &c3 }; + cout << p1 << endl; cout << p2 << endl; cout << p3 << endl; + + + Meeting m1{ 13, 1300, 1500, Campus::Trondheim, "Test", &p1 }; + m1.addParticipant(&p2); + m1.addParticipant(&p3); + + Meeting m2{ 13, 1200, 1500, Campus::Trondheim, "Test", &p4 }; + + cout << m1; + + m1.findPotentialCoDriving(); + + */ + + MeetingWindow win{Point{100, 100}, 600, 400, "Meetings" }; + + gui_main(); + + for (const auto p : win.getPeople()) + { + cout << p->getName() << endl; + } keep_window_open(); + return 0; }