Move MergeGroups()

This commit is contained in:
Oliver Hamlet
2025-01-17 23:13:13 +00:00
parent 86cdff1f21
commit 60da16e9d0
3 changed files with 40 additions and 39 deletions
+40
View File
@@ -35,6 +35,46 @@
#include "loot/exception/file_access_error.h"
#include "loot/metadata/group.h"
namespace {
using loot::Group;
std::vector<Group> MergeGroups(const std::vector<Group>& masterlistGroups,
const std::vector<Group>& userGroups) {
auto mergedGroups = masterlistGroups;
std::vector<Group> newGroups;
for (const auto& userGroup : userGroups) {
auto groupIt =
std::find_if(mergedGroups.begin(),
mergedGroups.end(),
[&](const Group& existingGroup) {
return existingGroup.GetName() == userGroup.GetName();
});
if (groupIt == mergedGroups.end()) {
newGroups.push_back(userGroup);
} else {
// Replace the masterlist group description with the userlist group
// description if the latter is not empty.
auto description = userGroup.GetDescription().empty()
? groupIt->GetDescription()
: userGroup.GetDescription();
auto afterGroups = groupIt->GetAfterGroups();
auto userAfterGroups = userGroup.GetAfterGroups();
afterGroups.insert(
afterGroups.end(), userAfterGroups.begin(), userAfterGroups.end());
*groupIt = Group(userGroup.GetName(), afterGroups, description);
}
}
mergedGroups.insert(mergedGroups.end(), newGroups.cbegin(), newGroups.cend());
return mergedGroups;
}
}
namespace loot {
ApiDatabase::ApiDatabase(
std::shared_ptr<ConditionEvaluator> conditionEvaluator) :
-36
View File
@@ -332,40 +332,4 @@ std::vector<Vertex> GetGroupsPath(const GroupGraph& graph,
return path;
}
std::vector<Group> MergeGroups(const std::vector<Group>& masterlistGroups,
const std::vector<Group>& userGroups) {
auto mergedGroups = masterlistGroups;
std::vector<Group> newGroups;
for (const auto& userGroup : userGroups) {
auto groupIt =
std::find_if(mergedGroups.begin(),
mergedGroups.end(),
[&](const Group& existingGroup) {
return existingGroup.GetName() == userGroup.GetName();
});
if (groupIt == mergedGroups.end()) {
newGroups.push_back(userGroup);
} else {
// Replace the masterlist group description with the userlist group
// description if the latter is not empty.
auto description = userGroup.GetDescription().empty()
? groupIt->GetDescription()
: userGroup.GetDescription();
auto afterGroups = groupIt->GetAfterGroups();
auto userAfterGroups = userGroup.GetAfterGroups();
afterGroups.insert(
afterGroups.end(), userAfterGroups.begin(), userAfterGroups.end());
*groupIt = Group(userGroup.GetName(), afterGroups, description);
}
}
mergedGroups.insert(mergedGroups.end(), newGroups.cbegin(), newGroups.cend());
return mergedGroups;
}
}
-3
View File
@@ -56,8 +56,5 @@ GetPredecessorGroups(const GroupGraph& groupGraph);
std::vector<Vertex> GetGroupsPath(const GroupGraph& groupGraph,
const std::string& fromGroupName,
const std::string& toGroupName);
std::vector<Group> MergeGroups(const std::vector<Group>& masterlistGroups,
const std::vector<Group>& userGroups);
}
#endif