OptimisationProblem/structures/Missions.cpp

58 lines
1.1 KiB
C++
Raw Permalink Normal View History

2023-07-17 00:19:10 +02:00
#include "Missions.h"
#include "Mission.h"
#include "Centers.h"
Missions::Missions(std::string basePath, Centers& centers)
{
std::string filePath = basePath + "/Missions.csv";
std::cout << "Reading file " << filePath << " for Missions\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 day;
getline(stream, day, ',');
std::string start;
getline(stream, start, ',');
std::string end;
getline(stream, end, ',');
std::string competence;
getline(stream, competence, ',');
std::string profession;
getline(stream, profession, ',');
Mission* mission = new Mission { stoi(id), stoi(day), stoi(start), stoi(end), competence, profession };
this->missions.push_back(mission);
}
file.close();
}
MissionList* Missions::copy()
{
MissionList* list = new MissionList { this->missions };
return list;
}
int Missions::size()
{
return this->missions.size();
}