Make PluginMetadata::GetLocations() return a std::vector

The collection is only ever iterated over, and the uniqueness and
ordering don't matter.
This commit is contained in:
Oliver Hamlet
2020-07-11 19:14:05 +01:00
parent d5881047cc
commit 14bdbe1fdf
4 changed files with 15 additions and 19 deletions
+3 -3
View File
@@ -142,7 +142,7 @@ public:
* Get the locations at which this plugin can be found.
* @return The locations at which this plugin can be found.
*/
LOOT_API std::set<Location> GetLocations() const;
LOOT_API std::vector<Location> GetLocations() const;
/**
* Get the plugin's messages as SimpleMessage objects for the given language.
@@ -219,7 +219,7 @@ public:
* @param locations
* The locations to set.
*/
LOOT_API void SetLocations(const std::set<Location>& locations);
LOOT_API void SetLocations(const std::vector<Location>& locations);
/**
* Check if no plugin metadata is set.
@@ -275,7 +275,7 @@ private:
std::vector<Tag> tags_;
std::vector<PluginCleaningData> dirtyInfo_;
std::vector<PluginCleaningData> cleanInfo_;
std::set<Location> locations_;
std::vector<Location> locations_;
};
}
+6 -11
View File
@@ -69,7 +69,7 @@ void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) {
dirtyInfo_ = mergeVectors(dirtyInfo_, plugin.dirtyInfo_);
cleanInfo_ = mergeVectors(cleanInfo_, plugin.cleanInfo_);
locations_.insert(begin(plugin.locations_), end(plugin.locations_));
locations_ = mergeVectors(locations_, plugin.locations_);
return;
}
@@ -103,14 +103,7 @@ PluginMetadata PluginMetadata::NewMetadata(const PluginMetadata& plugin) const {
p.SetTags(diffVectors(tags_, plugin.tags_));
p.SetDirtyInfo(diffVectors(dirtyInfo_, plugin.dirtyInfo_));
p.SetCleanInfo(diffVectors(cleanInfo_, plugin.cleanInfo_));
set<Location> locationsDiff;
set_difference(begin(locations_),
end(locations_),
begin(plugin.locations_),
end(plugin.locations_),
inserter(locationsDiff, begin(locationsDiff)));
p.SetLocations(locationsDiff);
p.SetLocations(diffVectors(locations_, plugin.locations_));
return p;
}
@@ -141,7 +134,9 @@ std::vector<PluginCleaningData> PluginMetadata::GetCleanInfo() const {
return cleanInfo_;
}
std::set<Location> PluginMetadata::GetLocations() const { return locations_; }
std::vector<Location> PluginMetadata::GetLocations() const {
return locations_;
}
std::vector<SimpleMessage> PluginMetadata::GetSimpleMessages(
const std::string& language) const {
@@ -187,7 +182,7 @@ void PluginMetadata::SetCleanInfo(const std::vector<PluginCleaningData>& info) {
cleanInfo_ = info;
}
void PluginMetadata::SetLocations(const std::set<Location>& locations) {
void PluginMetadata::SetLocations(const std::vector<Location>& locations) {
locations_ = locations;
}
+1 -1
View File
@@ -121,7 +121,7 @@ struct convert<loot::PluginMetadata> {
node["clean"].as<std::vector<loot::PluginCleaningData>>());
}
if (node["url"])
rhs.SetLocations(node["url"].as<std::set<loot::Location>>());
rhs.SetLocations(node["url"].as<std::vector<loot::Location>>());
return true;
}
@@ -261,7 +261,8 @@ TEST_P(PluginMetadataTest, mergeMetadataShouldMergeLocationData) {
plugin2.SetLocations({location1, location2});
plugin1.MergeMetadata(plugin2);
EXPECT_EQ(std::set<Location>({location1, location2}), plugin1.GetLocations());
EXPECT_EQ(std::vector<Location>({location1, location2}),
plugin1.GetLocations());
}
TEST_P(PluginMetadataTest, newMetadataShouldUseSourcePluginName) {
@@ -435,7 +436,7 @@ TEST_P(PluginMetadataTest,
plugin2.SetLocations({location1, location3});
PluginMetadata newMetadata = plugin1.NewMetadata(plugin2);
EXPECT_EQ(std::set<Location>({location2}), newMetadata.GetLocations());
EXPECT_EQ(std::vector<Location>({location2}), newMetadata.GetLocations());
}
TEST_P(PluginMetadataTest, simpleMessagesShouldReturnMessagesAsSimpleMessages) {
@@ -853,7 +854,7 @@ TEST_P(PluginMetadataTest, encodingAsYamlShouldSetUrlFieldIfLocationsExist) {
YAML::Node node;
node = plugin;
EXPECT_EQ(plugin.GetLocations(), node["url"].as<std::set<Location>>());
EXPECT_EQ(plugin.GetLocations(), node["url"].as<std::vector<Location>>());
}
TEST_P(PluginMetadataTest, decodingFromYamlShouldStoreAllGivenData) {
@@ -894,7 +895,7 @@ TEST_P(PluginMetadataTest, decodingFromYamlShouldStoreAllGivenData) {
plugin.GetDirtyInfo());
EXPECT_EQ(std::vector<PluginCleaningData>({PluginCleaningData(6, "utility")}),
plugin.GetCleanInfo());
EXPECT_EQ(std::set<Location>({Location("http://www.example.com")}),
EXPECT_EQ(std::vector<Location>({Location("http://www.example.com")}),
plugin.GetLocations());
}