mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Store messages in vectors
Using std::list doesn't provide any benefits, and means a few differences compared to the more standard vector container.
This commit is contained in:
@@ -191,7 +191,7 @@ PluginCleanliness ApiDatabase::GetPluginCleanliness(const std::string& plugin) {
|
||||
// This isn't a very reliable system, because if the lists have been evaluated in some language
|
||||
// other than English, the strings will be in different languages (and the API can't tell what they'd be)
|
||||
// and the strings may be non-standard and begin with something other than "Do not clean." anyway.
|
||||
std::list<Message> messages(game_.GetMasterlist().FindPlugin(PluginMetadata(plugin)).Messages());
|
||||
std::vector<Message> messages(game_.GetMasterlist().FindPlugin(PluginMetadata(plugin)).Messages());
|
||||
|
||||
for (const auto& message : messages) {
|
||||
if (boost::starts_with(message.GetContent(LanguageCode::english).GetText(), "Do not clean")) {
|
||||
|
||||
@@ -37,10 +37,10 @@
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
using std::inserter;
|
||||
using std::list;
|
||||
using std::regex;
|
||||
using std::regex_match;
|
||||
using std::set;
|
||||
using std::vector;
|
||||
|
||||
namespace loot {
|
||||
PluginMetadata::PluginMetadata() : enabled_(true) {}
|
||||
@@ -128,11 +128,11 @@ PluginMetadata PluginMetadata::DiffMetadata(const PluginMetadata& plugin) const
|
||||
inserter(filesDiff, begin(filesDiff)));
|
||||
p.Incs(filesDiff);
|
||||
|
||||
list<Message> msgs1 = plugin.Messages();
|
||||
list<Message> msgs2 = messages_;
|
||||
msgs1.sort();
|
||||
msgs2.sort();
|
||||
list<Message> mDiff;
|
||||
vector<Message> msgs1 = plugin.Messages();
|
||||
vector<Message> msgs2 = messages_;
|
||||
std::sort(begin(msgs1), end(msgs1));
|
||||
std::sort(begin(msgs2), end(msgs2));
|
||||
vector<Message> mDiff;
|
||||
set_symmetric_difference(begin(msgs2),
|
||||
end(msgs2),
|
||||
begin(msgs1),
|
||||
@@ -206,11 +206,11 @@ PluginMetadata PluginMetadata::NewMetadata(const PluginMetadata& plugin) const {
|
||||
inserter(filesDiff, begin(filesDiff)));
|
||||
p.Incs(filesDiff);
|
||||
|
||||
list<Message> msgs1 = plugin.Messages();
|
||||
list<Message> msgs2 = messages_;
|
||||
msgs1.sort();
|
||||
msgs2.sort();
|
||||
list<Message> mDiff;
|
||||
vector<Message> msgs1 = plugin.Messages();
|
||||
vector<Message> msgs2 = messages_;
|
||||
std::sort(begin(msgs1), end(msgs1));
|
||||
std::sort(begin(msgs2), end(msgs2));
|
||||
vector<Message> mDiff;
|
||||
set_difference(begin(msgs2),
|
||||
end(msgs2),
|
||||
begin(msgs1),
|
||||
@@ -281,7 +281,7 @@ std::set<File> PluginMetadata::Incs() const {
|
||||
return incompatibilities_;
|
||||
}
|
||||
|
||||
std::list<Message> PluginMetadata::Messages() const {
|
||||
std::vector<Message> PluginMetadata::Messages() const {
|
||||
return messages_;
|
||||
}
|
||||
|
||||
@@ -301,8 +301,8 @@ std::set<Location> PluginMetadata::Locations() const {
|
||||
return locations_;
|
||||
}
|
||||
|
||||
std::list<SimpleMessage> PluginMetadata::SimpleMessages(const LanguageCode language) const {
|
||||
std::list<SimpleMessage> simpleMessages(messages_.size());
|
||||
std::vector<SimpleMessage> PluginMetadata::SimpleMessages(const LanguageCode language) const {
|
||||
std::vector<SimpleMessage> simpleMessages(messages_.size());
|
||||
std::transform(begin(messages_), end(messages_), begin(simpleMessages), [&](const Message& message) {
|
||||
return message.ToSimpleMessage(language);
|
||||
});
|
||||
@@ -334,7 +334,7 @@ void PluginMetadata::Incs(const std::set<File>& i) {
|
||||
incompatibilities_ = i;
|
||||
}
|
||||
|
||||
void PluginMetadata::Messages(const std::list<Message>& m) {
|
||||
void PluginMetadata::Messages(const std::vector<Message>& m) {
|
||||
messages_ = m;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,13 +71,13 @@ public:
|
||||
std::set<File> LoadAfter() const;
|
||||
std::set<File> Reqs() const;
|
||||
std::set<File> Incs() const;
|
||||
std::list<Message> Messages() const;
|
||||
std::vector<Message> Messages() const;
|
||||
std::set<Tag> Tags() const;
|
||||
std::set<PluginCleaningData> DirtyInfo() const;
|
||||
std::set<PluginCleaningData> CleanInfo() const;
|
||||
std::set<Location> Locations() const;
|
||||
|
||||
std::list<SimpleMessage> SimpleMessages(const LanguageCode language) const;
|
||||
std::vector<SimpleMessage> SimpleMessages(const LanguageCode language) const;
|
||||
|
||||
void Enabled(const bool enabled);
|
||||
void LocalPriority(const Priority& priority);
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
void LoadAfter(const std::set<File>& after);
|
||||
void Reqs(const std::set<File>& reqs);
|
||||
void Incs(const std::set<File>& incs);
|
||||
void Messages(const std::list<Message>& messages);
|
||||
void Messages(const std::vector<Message>& messages);
|
||||
void Tags(const std::set<Tag>& tags);
|
||||
void DirtyInfo(const std::set<PluginCleaningData>& info);
|
||||
void CleanInfo(const std::set<PluginCleaningData>& info);
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
bool operator == (const std::string& rhs) const;
|
||||
bool operator != (const std::string& rhs) const;
|
||||
protected:
|
||||
std::list<Message> messages_;
|
||||
std::vector<Message> messages_;
|
||||
std::set<Tag> tags_;
|
||||
private:
|
||||
std::string name_;
|
||||
@@ -201,7 +201,7 @@ struct convert<loot::PluginMetadata> {
|
||||
if (node["inc"])
|
||||
rhs.Incs(node["inc"].as<std::set<loot::File>>());
|
||||
if (node["msg"])
|
||||
rhs.Messages(node["msg"].as<std::list<loot::Message>>());
|
||||
rhs.Messages(node["msg"].as<std::vector<loot::Message>>());
|
||||
if (node["tag"])
|
||||
rhs.Tags(node["tag"].as<std::set<loot::Tag>>());
|
||||
if (node["dirty"]) {
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
#include "loot/error.h"
|
||||
#include "backend/game/game.h"
|
||||
|
||||
using std::list;
|
||||
|
||||
namespace loot {
|
||||
void MetadataList::Load(const boost::filesystem::path& filepath) {
|
||||
Clear();
|
||||
@@ -58,7 +56,7 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
|
||||
}
|
||||
}
|
||||
if (metadataList["globals"])
|
||||
messages_ = metadataList["globals"].as<list<Message>>();
|
||||
messages_ = metadataList["globals"].as<std::vector<Message>>();
|
||||
|
||||
if (metadataList["bash_tags"])
|
||||
bashTags_ = metadataList["bash_tags"].as<std::set<std::string>>();
|
||||
@@ -89,14 +87,14 @@ void MetadataList::Clear() {
|
||||
}
|
||||
|
||||
std::list<PluginMetadata> MetadataList::Plugins() const {
|
||||
list<PluginMetadata> pluginList(plugins_.begin(), plugins_.end());
|
||||
std::list<PluginMetadata> pluginList(plugins_.begin(), plugins_.end());
|
||||
|
||||
pluginList.insert(pluginList.end(), regexPlugins_.begin(), regexPlugins_.end());
|
||||
|
||||
return pluginList;
|
||||
}
|
||||
|
||||
std::list<Message> MetadataList::Messages() const {
|
||||
std::vector<Message> MetadataList::Messages() const {
|
||||
return messages_;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void Clear();
|
||||
|
||||
std::list<PluginMetadata> Plugins() const;
|
||||
std::list<Message> Messages() const;
|
||||
std::vector<Message> Messages() const;
|
||||
std::set<std::string> BashTags() const;
|
||||
|
||||
// Merges multiple matching regex entries if any are found.
|
||||
@@ -63,7 +63,7 @@ protected:
|
||||
std::set<std::string> bashTags_;
|
||||
std::unordered_set<PluginMetadata> plugins_;
|
||||
std::list<PluginMetadata> regexPlugins_;
|
||||
std::list<Message> messages_;
|
||||
std::vector<Message> messages_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
using std::list;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace loot {
|
||||
typedef boost::graph_traits<PluginGraph>::vertex_iterator vertex_it;
|
||||
@@ -99,7 +100,6 @@ private:
|
||||
};
|
||||
|
||||
std::vector<Plugin> PluginSorter::Sort(Game& game, const LanguageCode language) {
|
||||
using std::vector;
|
||||
// Clear existing data.
|
||||
graph_.clear();
|
||||
indexMap_.clear();
|
||||
@@ -213,7 +213,7 @@ void PluginSorter::AddPluginVertices(Game& game, const LanguageCode language) {
|
||||
graph_[v].EvalAllConditions(game);
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "\"" << graph_[v].Name() << "\" contains a condition that could not be evaluated. Details: " << e.what();
|
||||
list<Message> messages(graph_[v].Messages());
|
||||
vector<Message> messages(graph_[v].Messages());
|
||||
messages.push_back(Message(MessageType::error, (boost::format(boost::locale::translate("\"%1%\" contains a condition that could not be evaluated. Details: %2%")) % graph_[v].Name() % e.what()).str()));
|
||||
graph_[v].Messages(messages);
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ std::string QueryHandler::ApplyUserEdits(const YAML::Node& pluginMetadata) {
|
||||
newUserlistEntry.Incs(pluginMetadata["userlist"]["inc"].as<set<File>>());
|
||||
|
||||
if (pluginMetadata["userlist"]["msg"])
|
||||
newUserlistEntry.Messages(ToMessages(pluginMetadata["userlist"]["msg"].as<list<EditorMessage>>()));
|
||||
newUserlistEntry.Messages(ToMessages(pluginMetadata["userlist"]["msg"].as<vector<EditorMessage>>()));
|
||||
if (pluginMetadata["userlist"]["tag"])
|
||||
newUserlistEntry.Tags(pluginMetadata["userlist"]["tag"].as<set<Tag>>());
|
||||
if (pluginMetadata["userlist"]["dirty"])
|
||||
@@ -959,7 +959,7 @@ YAML::Node QueryHandler::GenerateDerivedMetadata(const Plugin& file, const Plugi
|
||||
tempPlugin.EvalAllConditions(lootState_.getCurrentGame());
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "\"" << tempPlugin.Name() << "\" contains a condition that could not be evaluated. Details: " << e.what();
|
||||
list<Message> messages(tempPlugin.Messages());
|
||||
vector<Message> messages(tempPlugin.Messages());
|
||||
messages.push_back(Message(MessageType::error, (format(translate("\"%1%\" contains a condition that could not be evaluated. Details: %2%")) % tempPlugin.Name() % e.what()).str()));
|
||||
tempPlugin.Messages(messages);
|
||||
}
|
||||
@@ -1031,8 +1031,8 @@ void QueryHandler::SendProgressUpdate(CefRefPtr<CefFrame> frame, const std::stri
|
||||
frame->ExecuteJavaScript("loot.Dialog.showProgress('" + message + "');", frame->GetURL(), 0);
|
||||
}
|
||||
|
||||
std::list<EditorMessage> QueryHandler::ToEditorMessages(std::list<Message> messages, const LanguageCode language) {
|
||||
std::list<EditorMessage> list;
|
||||
std::vector<EditorMessage> QueryHandler::ToEditorMessages(std::vector<Message> messages, const LanguageCode language) {
|
||||
std::vector<EditorMessage> list;
|
||||
|
||||
for (const auto& message : messages) {
|
||||
list.push_back(EditorMessage(message, language));
|
||||
@@ -1041,8 +1041,8 @@ std::list<EditorMessage> QueryHandler::ToEditorMessages(std::list<Message> messa
|
||||
return list;
|
||||
}
|
||||
|
||||
std::list<Message> QueryHandler::ToMessages(std::list<EditorMessage> messages) {
|
||||
std::list<Message> list;
|
||||
std::vector<Message> QueryHandler::ToMessages(std::vector<EditorMessage> messages) {
|
||||
std::vector<Message> list;
|
||||
|
||||
for (const auto& message : messages) {
|
||||
list.push_back(Message(
|
||||
|
||||
@@ -76,8 +76,8 @@ private:
|
||||
void CopyToClipboard(const std::string& text);
|
||||
void SendProgressUpdate(CefRefPtr<CefFrame> frame, const std::string& message);
|
||||
|
||||
std::list<EditorMessage> ToEditorMessages(std::list<Message> messages, const LanguageCode language);
|
||||
std::list<Message> ToMessages(std::list<EditorMessage> messages);
|
||||
std::vector<EditorMessage> ToEditorMessages(std::vector<Message> messages, const LanguageCode language);
|
||||
std::vector<Message> ToMessages(std::vector<EditorMessage> messages);
|
||||
|
||||
LootState& lootState_;
|
||||
};
|
||||
|
||||
@@ -241,7 +241,7 @@ TEST_P(PluginMetadataTest, mergeMetadataShouldMergeMessages) {
|
||||
plugin2.Messages({message});
|
||||
plugin1.MergeMetadata(plugin2);
|
||||
|
||||
EXPECT_EQ(std::list<Message>({message, message}), plugin1.Messages());
|
||||
EXPECT_EQ(std::vector<Message>({message, message}), plugin1.Messages());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest, mergeMetadataShouldMergeTags) {
|
||||
@@ -419,7 +419,7 @@ TEST_P(PluginMetadataTest, diffMetadataShouldOutputMessagesThatAreNotCommonToBot
|
||||
plugin2.Messages({message1, message3});
|
||||
PluginMetadata diff = plugin1.DiffMetadata(plugin2);
|
||||
|
||||
EXPECT_EQ(std::list<Message>({message2, message3}), diff.Messages());
|
||||
EXPECT_EQ(std::vector<Message>({message2, message3}), diff.Messages());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest, diffMetadataShouldOutputTagsThatAreNotCommonToBothInputPlugins) {
|
||||
@@ -575,7 +575,7 @@ TEST_P(PluginMetadataTest, newMetadataShouldOutputMessagesThatAreNotCommonToBoth
|
||||
plugin2.Messages({message1, message3});
|
||||
PluginMetadata newMetadata = plugin1.NewMetadata(plugin2);
|
||||
|
||||
EXPECT_EQ(std::list<Message>({message2}), newMetadata.Messages());
|
||||
EXPECT_EQ(std::vector<Message>({message2}), newMetadata.Messages());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest, newMetadataShouldOutputTagsThatAreNotCommonToBothInputPlugins) {
|
||||
@@ -687,7 +687,7 @@ TEST_P(PluginMetadataTest, evalAllConditionsShouldEvaluateAllMetadataConditions)
|
||||
EXPECT_EQ(expectedFiles, plugin.LoadAfter());
|
||||
EXPECT_EQ(expectedFiles, plugin.Reqs());
|
||||
EXPECT_EQ(expectedFiles, plugin.Incs());
|
||||
EXPECT_EQ(std::list<Message>({message1}), plugin.Messages());
|
||||
EXPECT_EQ(std::vector<Message>({message1}), plugin.Messages());
|
||||
EXPECT_EQ(std::set<Tag>({tag1}), plugin.Tags());
|
||||
EXPECT_EQ(std::set<PluginCleaningData>({info1}), plugin.DirtyInfo());
|
||||
EXPECT_EQ(std::set<PluginCleaningData>({info1}), plugin.CleanInfo());
|
||||
@@ -1073,7 +1073,7 @@ TEST_P(PluginMetadataTest, encodingAsYamlShouldSetMsgFieldIfMessagesExist) {
|
||||
YAML::Node node;
|
||||
node = plugin;
|
||||
|
||||
EXPECT_EQ(plugin.Messages(), node["msg"].as<std::list<Message>>());
|
||||
EXPECT_EQ(plugin.Messages(), node["msg"].as<std::vector<Message>>());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest, encodingAsYamlShouldSetTagFieldIfTagsExist) {
|
||||
@@ -1163,7 +1163,7 @@ TEST_P(PluginMetadataTest, decodingFromYamlShouldStoreAllGivenData) {
|
||||
EXPECT_EQ(std::set<File>({
|
||||
File("Blank.esm")
|
||||
}), plugin.Incs());
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::say, "content")
|
||||
}), plugin.Messages());
|
||||
EXPECT_EQ(std::set<Tag>({
|
||||
|
||||
@@ -82,7 +82,7 @@ TEST_P(MetadataListTest, loadShouldLoadGlobalMessages) {
|
||||
MetadataList metadataList;
|
||||
|
||||
EXPECT_NO_THROW(metadataList.Load(metadataPath));
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::say, "A global message."),
|
||||
}), metadataList.Messages());
|
||||
}
|
||||
@@ -170,7 +170,7 @@ TEST_P(MetadataListTest, saveShouldWriteTheLoadedMetadataToTheGivenFilePath) {
|
||||
"Relev"
|
||||
}), metadataList.BashTags());
|
||||
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::say, "A global message."),
|
||||
}), metadataList.Messages());
|
||||
|
||||
@@ -290,7 +290,7 @@ TEST_P(MetadataListTest, evalAllConditionsShouldEvaluateTheConditionsForThePlugi
|
||||
ASSERT_NO_THROW(metadataList.Load(metadataPath));
|
||||
|
||||
PluginMetadata plugin = metadataList.FindPlugin(PluginMetadata(blankEsm));
|
||||
ASSERT_EQ(std::list<Message>({
|
||||
ASSERT_EQ(std::vector<Message>({
|
||||
Message(MessageType::warn, "This is a warning."),
|
||||
Message(MessageType::say, "This message should be removed when evaluating conditions."),
|
||||
}), plugin.Messages());
|
||||
@@ -302,7 +302,7 @@ TEST_P(MetadataListTest, evalAllConditionsShouldEvaluateTheConditionsForThePlugi
|
||||
EXPECT_NO_THROW(metadataList.EvalAllConditions(game));
|
||||
|
||||
plugin = metadataList.FindPlugin(PluginMetadata(blankEsm));
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::warn, "This is a warning."),
|
||||
}), plugin.Messages());
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ TEST_P(PluginTest, checkInstallValidityShouldCheckThatRequirementsArePresent) {
|
||||
});
|
||||
|
||||
plugin.CheckInstallValidity(game_);
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::error, "This plugin requires \"" + missingEsp + "\" to be installed, but it is missing."),
|
||||
}), plugin.Messages());
|
||||
}
|
||||
@@ -294,7 +294,7 @@ TEST_P(PluginTest, checkInstallValidityShouldCheckThatIncompatibilitiesAreAbsent
|
||||
});
|
||||
|
||||
plugin.CheckInstallValidity(game_);
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::error, "This plugin is incompatible with \"" + masterFile + "\", but both are present."),
|
||||
}), plugin.Messages());
|
||||
}
|
||||
@@ -311,7 +311,7 @@ TEST_P(PluginTest, checkInstallValidityShouldGenerateMessagesFromDirtyInfo) {
|
||||
});
|
||||
|
||||
plugin.CheckInstallValidity(game_);
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
PluginCleaningData(blankEsmCrc, "utility1", info, 0, 1, 2).AsMessage(),
|
||||
PluginCleaningData(0xDEADBEEF, "utility2", info, 0, 5, 10).AsMessage(),
|
||||
}), plugin.Messages());
|
||||
@@ -321,7 +321,7 @@ TEST_P(PluginTest, checkInstallValidityShouldCheckIfAPluginsMastersAreAllPresent
|
||||
Plugin plugin(game_, blankDifferentMasterDependentEsp, false);
|
||||
|
||||
plugin.CheckInstallValidity(game_);
|
||||
EXPECT_EQ(std::list<Message>({
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
Message(MessageType::error, "This plugin requires \"" + blankDifferentEsm + "\" to be active, but it is inactive."),
|
||||
}), plugin.Messages());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user