mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Move MergeGroups()
This commit is contained in:
@@ -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) :
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user