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
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 <>
......
......@@ -147,18 +147,23 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde
{
auto apply = [colName, lineIndex, addition](Config & config, Action &)
{
auto & current = config.getLastNotEmptyHyp(colName, lineIndex);
current = util::isEmpty(current) ? addition : current.get() + '|' + addition;
auto currentElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
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);
while (!newValue.empty() and newValue.back() == '|')
newValue.pop_back();
if (!newValue.empty())
newValue.pop_back();
config.getLastNotEmpty(colName, lineIndex) = newValue;
auto curElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
std::vector<std::string> newElems;
for (auto & elem : curElems)
if (elem != addition)
newElems.emplace_back(elem);
config.getLastNotEmptyHyp(colName, lineIndex) = util::join("|", newElems);
};
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.
Finish editing this message first!
Please register or to comment