-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_no_gui.cpp
64 lines (53 loc) · 1.81 KB
/
main_no_gui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "appointment.h"
#include "worker.h"
#include "doctor.h"
#include "nurse.h"
#include "schedule.h"
using namespace std;
int main() {
vector<Worker*> workers;
vector<Appointment> appointments;
ifstream jsonFile("example.json");
boost::property_tree::ptree pt;
boost::property_tree::read_json(jsonFile, pt);
const auto& jsonWorkers = pt.get_child("workers");
const auto& jsonAppointments = pt.get_child("appointments");
for (const auto& worker : jsonWorkers) {
auto& child = worker.second;
std::string role = child.get<std::string>("role");
if (role == "Nurse") {
workers.push_back(new Nurse(child.get<std::string>("name") ));
} else if (role == "Doctor") {
workers.push_back(new Doctor(child.get<std::string>("name") ));
}
}
for (const auto& appointment : jsonAppointments) {
auto& child = appointment.second;
appointments.emplace_back(Appointment(
stringToType(child.get<std::string>("type")),
child.get<std::string>("time"),
child.get<std::string>("patientName")
)
);
}
// for (auto& worker : workers) {
// std::cout << worker << std::endl;
// }
//
// for (auto& apt : appointments) {
// std::cout << apt << std::endl;
// }
std::sort(appointments.begin(), appointments.end(), [](auto& a, auto& b) { return a.getTimeEnd() < b.getTimeEnd(); });
schedule(workers, appointments);
for (auto& worker : workers) {
std::cout << *worker;
std::cout << worker->getWorkingMinutes() << " minutes" << std::endl << std::endl;
}
return 0;
}