33 lines
701 B
C++
33 lines
701 B
C++
#include "ParticipantRepo.h"
|
|
#include <stdexcept>
|
|
#include <fstream>
|
|
|
|
ParticipantRepo::ParticipantRepo(std::string file_name)
|
|
{
|
|
this->_file_name = file_name;
|
|
this->read_from_file();
|
|
}
|
|
|
|
std::vector<Participant> ParticipantRepo::get_all()
|
|
{
|
|
return this->_participants;
|
|
}
|
|
|
|
int ParticipantRepo::size()
|
|
{
|
|
return this->_participants.size();
|
|
}
|
|
|
|
void ParticipantRepo::read_from_file()
|
|
{
|
|
std::ifstream file(this->_file_name);
|
|
if(!file.is_open())
|
|
throw std::runtime_error("File could not be opened!");
|
|
std::string line;
|
|
while(std::getline(file, line) && !line.empty())
|
|
{
|
|
Participant p(line);
|
|
this->_participants.push_back(p);
|
|
}
|
|
file.close();
|
|
} |