Skip to content
Snippets Groups Projects
Commit caaca1a7 authored by Franck Dary's avatar Franck Dary
Browse files

AddToHypothesis is now sorted

parent 1baa7d2a
No related branches found
No related tags found
No related merge requests found
...@@ -79,6 +79,17 @@ bool doIfNameMatch(const std::regex & reg, std::string_view name, const std::fun ...@@ -79,6 +79,17 @@ bool doIfNameMatch(const std::regex & reg, std::string_view name, const std::fun
bool choiceWithProbability(float probability); bool choiceWithProbability(float probability);
template <typename T>
std::string join(const std::string & delim, const std::vector<T> elems)
{
std::string result;
for (unsigned int i = 0; i < elems.size(); i++)
result = fmt::format("{}{}{}", result, elems[i], i == elems.size()-1 ? "" : delim);
return result;
}
}; };
template <> template <>
......
...@@ -147,18 +147,23 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde ...@@ -147,18 +147,23 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde
{ {
auto apply = [colName, lineIndex, addition](Config & config, Action &) auto apply = [colName, lineIndex, addition](Config & config, Action &)
{ {
auto & current = config.getLastNotEmptyHyp(colName, lineIndex); auto currentElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
current = util::isEmpty(current) ? addition : current.get() + '|' + addition; currentElems.emplace_back(addition);
std::sort(currentElems.begin(), currentElems.end());
config.getLastNotEmptyHyp(colName, lineIndex) = util::join("|", currentElems);
}; };
auto undo = [colName, lineIndex](Config & config, Action &) auto undo = [colName, lineIndex, addition](Config & config, Action &)
{ {
std::string newValue = config.getLastNotEmpty(colName, lineIndex); auto curElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
while (!newValue.empty() and newValue.back() == '|') std::vector<std::string> newElems;
newValue.pop_back(); for (auto & elem : curElems)
if (!newValue.empty()) if (elem != addition)
newValue.pop_back(); newElems.emplace_back(elem);
config.getLastNotEmpty(colName, lineIndex) = newValue;
config.getLastNotEmptyHyp(colName, lineIndex) = util::join("|", newElems);
}; };
auto appliable = [colName, lineIndex, addition](const Config & config, const Action &) auto appliable = [colName, lineIndex, addition](const Config & config, const Action &)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment