#include "Employees.h" #include "Centers.h" Employees::Employees(std::string basePath, Centers& centers) { std::string filePath = basePath + "/Employees.csv"; std::cout << "Reading file " << filePath << " for Employees\n"; std::ifstream file; file.open(filePath, std::ios::in); if (!file.is_open()) throw std::runtime_error("Invalid file path"); std::string line; while (getline(file, line)) { if (line.empty()) continue; std::istringstream stream(line); std::string id; getline(stream, id, ','); std::string centerId; getline(stream, centerId, ','); //std::cout << "Employee " << id << ", Center: " << centerId << "\n"; Center* center = centers.get(stoi(centerId)); std::string competence; getline(stream, competence, ','); std::string profession; getline(stream, profession, ','); if (center == nullptr) throw std::runtime_error("Invalid center"); Employee* employee = new Employee{ stoi(id), center, competence, profession }; center->addEmployee(employee); this->employees.push_back(employee); } file.close(); }