19#include "SelectionLoader.hh"
31 std::ifstream f(selectionFile.c_str());
33 {
throw std::invalid_argument(
"LoadSelection> could not open file " + selectionFile);}
40 std::regex comment(
"^\\#.*");
42 std::string selection;
43 while(std::getline(f, line))
46 if (std::all_of(line.begin(), line.end(), isspace))
48 else if (std::regex_search(line, comment))
53 if (!selection.empty())
54 {
throw std::invalid_argument(
"Multiple selections (non-empty lines) found in file - only one should be specified.");}
55 std::vector<std::string> results;
56 std::regex wspace(
"\\s+");
58 std::sregex_token_iterator iter(line.begin(), line.end(), wspace, -1);
59 std::sregex_token_iterator end;
60 for (; iter != end; ++iter)
62 std::string res = (*iter).str();
65 results.push_back(res);
67 if (results.size() != 1)
69 std::cerr <<
"Error on line " << lineCounter <<
"\"" << line <<
"\"" << std::endl;
70 throw std::invalid_argument(
"More than one word on line -> no white space allowed");
73 {selection = results[0];}
std::string LoadSelection(const std::string &selectionFile)
Load a selection from a text file.