54 lines
988 B
C++
54 lines
988 B
C++
#include "Centers.h"
|
|
|
|
Centers::Centers(std::string basePath)
|
|
{
|
|
std::string filePath = basePath + "/centres.csv";
|
|
std::cout << "Reading file " << filePath << " for Centers\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 name;
|
|
getline(stream, name, ',');
|
|
|
|
//std::cout << id << " " << name << "\n";
|
|
Center* center = new Center{ stoi(id), name };
|
|
this->centers.push_back(center);
|
|
}
|
|
|
|
file.close();
|
|
}
|
|
|
|
Center* Centers::get(int id)
|
|
{
|
|
for (Center* center : this->centers)
|
|
{
|
|
if (center->id == id)
|
|
{
|
|
return center;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void Centers::print()
|
|
{
|
|
std::cout << "Registered centers:\n";
|
|
for (Center* center : this->centers)
|
|
{
|
|
std::cout << center->id << ": " << center->name << "\n";
|
|
}
|
|
} |