Newer
Older
Franck Dary
committed
#include "ReadingMachine.hpp"
#include "util.hpp"
Franck Dary
committed
ReadingMachine::ReadingMachine(const std::string & filename)
{
std::regex nameRegex("Name : (.+)[\n]");
Franck Dary
committed
std::regex classifierRegex("Classifier : (.+) (.+) (.+)[\n]");
std::FILE * file = std::fopen(filename.c_str(), "r");
char buffer[1024];
while (!std::feof(file))
{
if (buffer != std::fgets(buffer, 1024, file))
break;
try
{
if (util::doIfNameMatch(nameRegex, buffer, [this](auto sm){name = sm[1];}))
continue;
if (util::doIfNameMatch(strategyRegex, buffer, [this](auto sm){}))
continue;
if (util::doIfNameMatch(classifierRegex, buffer, [this](auto sm){classifier.reset(new Classifier(sm[1], sm[2], sm[3]));}))
Franck Dary
committed
continue;
} catch(std::exception & e) {util::myThrow(fmt::format("during reading of '{}' : {}", filename, e.what()));}
}
std::fclose(file);
}