#include "ReadingMachine.hpp" #include "util.hpp" ReadingMachine::ReadingMachine(const std::string & filename) { std::regex nameRegex("Name : (.+)[\n]"); 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(classifierRegex, buffer, [this](auto sm) { classifier.reset(new Classifier(sm[1], sm[2], sm[3])); })) continue; } catch(std::exception & e) {util::myThrow(fmt::format("during reading of '{}' : {}", filename, e.what()));} } std::fclose(file); }