1 #ifndef CROMBIE_UNCERTAINTY_H 2 #define CROMBIE_UNCERTAINTY_H 18 namespace Uncertainty {
43 std::string expr (
const std::string&
key,
const std::string& inexpr,
const std::string&
suff)
const;
46 template<
typename A,
typename... Args>
Types::strings exprs (A arg, Args... args)
const;
66 std::vector<std::pair<unsigned, std::string>> otherbranches {};
88 bool is_env = tokens.front().back() ==
':';
90 tokens.front().pop_back();
91 auto branchname = tokens.back();
93 auto newenv = config.
env_branches.insert({tokens.front(), {branchname}});
94 auto iter = tokens.begin();
95 for (
auto splitpos = (++iter)->find(
':');
96 iter != tokens.end() and splitpos != std::string::npos;
97 splitpos = (++iter)->find(
':')) {
99 unsigned bin = std::stoi(iter->substr(0, splitpos));
100 auto suff = iter->substr(splitpos+1);
101 newenv.first->second.otherbranches.emplace_back(bin, branchname +
"_" + suff);
103 config.
full_infos.emplace_back(newenv.first->first, suff, bin);
108 auto eq_pos = tokens.front().find(
'=');
109 auto sysname = eq_pos == std::string::npos ? tokens.front() : tokens.front().substr(0, eq_pos);
110 auto branchname = eq_pos == std::string::npos ? tokens.front() : tokens.front().substr(eq_pos, tokens.front().size() - eq_pos);
114 auto iter = tokens.begin();
115 for (++iter; iter != tokens.end(); ++iter)
116 branches.push_back(*iter);
118 config.
updown_branches.insert({sysname, {branchname, std::move(branches)}});
119 for (
auto& updown : {
"Up",
"Down"})
120 config.
full_infos.emplace_back(sysname, updown);
130 std::ifstream{config} >> unc;
136 std::string output = inexpr;
140 bool isupdown = (suff ==
"Up" or suff ==
"Down");
143 auto& info = updown_branches.at(key);
145 branches = info.second;
148 branches.push_back(env_branches.at(key).branch);
150 for (
auto&
branch : branches) {
151 std::regex expr {std::string(
"\\b") +
branch +
"\\b"};
152 std::string replace =
branch +
'_' + name +
suff;
153 output = std::regex_replace(output, expr, replace);
162 for (
auto& sys : full_systematic_infos()) {
163 Debug::Debug(__PRETTY_FUNCTION__, sys.bin, sys.key, sys.suff);
164 auto check = expr(sys.key, arg, sys.suff);
167 output.push_back(std::move(check));
175 for (
auto& arg : args) {
176 auto single = exprs(arg);
177 output.insert(output.end(), std::make_move_iterator(single.begin()), std::make_move_iterator(single.end()));
186 auto single = exprs(arg);
187 output.insert(output.end(), std::make_move_iterator(single.begin()), std::make_move_iterator(single.end()));
189 auto more = exprs(args...);
190 output.insert(output.end(), std::make_move_iterator(more.begin()), std::make_move_iterator(more.end()));
197 auto comp = [] (
auto& branches) {
198 return Misc::comprehension<std::string>(branches, [] (
auto& i) {
return i.first;});
201 auto output = comp(updown_branches);
202 auto other = comp(env_branches);
204 output.insert(output.end(),
205 std::make_move_iterator(other.begin()),
206 std::make_move_iterator(other.end()));