30 std::ifstream f(selectionFile.c_str());
32 {
throw std::invalid_argument(
"LoadSelection> could not open file " + selectionFile);}
39 std::regex comment(
"^\\#.*");
41 std::string selection;
42 while(std::getline(f, line))
45 if (std::all_of(line.begin(), line.end(), isspace))
47 else if (std::regex_search(line, comment))
52 if (!selection.empty())
53 {
throw std::invalid_argument(
"Multiple selections (non-empty lines) found in file - only one should be specified.");}
54 std::vector<std::string> results;
55 std::regex wspace(
"\\s+");
57 std::sregex_token_iterator iter(line.begin(), line.end(), wspace, -1);
58 std::sregex_token_iterator end;
59 for (; iter != end; ++iter)
61 std::string res = (*iter).str();
64 results.push_back(res);
66 if (results.size() != 1)
68 std::cerr <<
"Error on line " << lineCounter <<
"\"" << line <<
"\"" << std::endl;
69 throw std::invalid_argument(
"More than one word on line -> no white space allowed");
72 {selection = results[0];}