Make File::GetName() return a Filename

This commit is contained in:
Oliver Hamlet
2020-07-11 19:14:05 +01:00
parent 15d98c9c20
commit 062ab24139
6 changed files with 47 additions and 45 deletions
+5 -4
View File
@@ -28,6 +28,7 @@
#include "loot/api_decorator.h"
#include "loot/metadata/conditional_metadata.h"
#include "loot/metadata/filename.h"
namespace loot {
/**
@@ -73,7 +74,7 @@ public:
* Get the filename of the file.
* @return The file's filename.
*/
LOOT_API std::string GetName() const;
LOOT_API Filename GetName() const;
/**
* Get the display name of the file.
@@ -82,7 +83,7 @@ public:
LOOT_API std::string GetDisplayName() const;
private:
std::string name_;
Filename name_;
std::string display_;
};
@@ -94,7 +95,7 @@ LOOT_API bool operator!=(const File& lhs, const File& rhs);
/**
* Check if the first File object is greater than the second File object.
* @returns True if the second File object is less than the first File object,
* @returns True if the second File object is less than the first File object,
* false otherwise.
*/
LOOT_API bool operator>(const File& lhs, const File& rhs);
@@ -102,7 +103,7 @@ LOOT_API bool operator>(const File& lhs, const File& rhs);
/**
* Check if the first File object is less than or equal to the second File
* object.
* @returns True if the first File object is not greater than the second File
* @returns True if the first File object is not greater than the second File
* object, false otherwise.
*/
LOOT_API bool operator<=(const File& lhs, const File& rhs);
+5 -5
View File
@@ -33,7 +33,7 @@ File::File() {}
File::File(const std::string& name,
const std::string& display,
const std::string& condition) :
name_(name),
name_(Filename(name)),
display_(display),
ConditionalMetadata(condition) {}
@@ -54,19 +54,19 @@ bool File::operator<(const File& rhs) const {
return false;
}
return CompareFilenames(name_, rhs.name_) < 0;
return name_ < rhs.name_;
}
bool File::operator==(const File& rhs) const {
return display_ == rhs.display_ && GetCondition() == rhs.GetCondition() &&
CompareFilenames(name_, rhs.name_) == 0;
name_ == rhs.name_;
}
std::string File::GetName() const { return name_; }
Filename File::GetName() const { return name_; }
std::string File::GetDisplayName() const {
if (display_.empty())
return name_;
return std::string(name_);
else
return display_;
}
+7 -6
View File
@@ -37,12 +37,12 @@ template<>
struct convert<loot::File> {
static Node encode(const loot::File& rhs) {
Node node;
node["name"] = rhs.GetName();
node["name"] = std::string(rhs.GetName());
if (rhs.IsConditional())
node["condition"] = rhs.GetCondition();
if (rhs.GetDisplayName() != rhs.GetName())
if (rhs.GetDisplayName() != std::string(rhs.GetName()))
node["display"] = rhs.GetDisplayName();
return node;
@@ -84,17 +84,18 @@ struct convert<loot::File> {
inline Emitter& operator<<(Emitter& out, const loot::File& rhs) {
if (!rhs.IsConditional() &&
(rhs.GetDisplayName().empty() || rhs.GetDisplayName() == rhs.GetName()))
out << YAML::SingleQuoted << rhs.GetName();
(rhs.GetDisplayName().empty() ||
rhs.GetDisplayName() == std::string(rhs.GetName())))
out << YAML::SingleQuoted << std::string(rhs.GetName());
else {
out << BeginMap << Key << "name" << Value << YAML::SingleQuoted
<< rhs.GetName();
<< std::string(rhs.GetName());
if (rhs.IsConditional())
out << Key << "condition" << Value << YAML::SingleQuoted
<< rhs.GetCondition();
if (rhs.GetDisplayName() != rhs.GetName())
if (rhs.GetDisplayName() != std::string(rhs.GetName()))
out << Key << "display" << Value << YAML::SingleQuoted
<< rhs.GetDisplayName();
+14 -14
View File
@@ -190,18 +190,18 @@ void PluginGraph::AddPluginVertices(Game& game,
// implement it generally.
auto loadedPlugins = game.GetCache()->GetPlugins();
std::sort(loadedPlugins.begin(),
loadedPlugins.end(),
[](const auto& lhs, const auto& rhs) {
if (!lhs) {
return false;
}
loadedPlugins.end(),
[](const auto& lhs, const auto& rhs) {
if (!lhs) {
return false;
}
if (!rhs) {
return true;
}
if (!rhs) {
return true;
}
return *lhs < *rhs;
});
return *lhs < *rhs;
});
for (const auto& plugin : loadedPlugins) {
auto masterlistMetadata =
@@ -472,26 +472,26 @@ void PluginGraph::AddSpecificEdges() {
}
for (const auto& file : graph_[*vit].GetMasterlistRequirements()) {
auto parentVertex = GetVertexByName(file.GetName());
auto parentVertex = GetVertexByName(std::string(file.GetName()));
if (parentVertex.has_value()) {
AddEdge(parentVertex.value(), *vit, EdgeType::masterlistRequirement);
}
}
for (const auto& file : graph_[*vit].GetUserRequirements()) {
auto parentVertex = GetVertexByName(file.GetName());
auto parentVertex = GetVertexByName(std::string(file.GetName()));
if (parentVertex.has_value()) {
AddEdge(parentVertex.value(), *vit, EdgeType::userRequirement);
}
}
for (const auto& file : graph_[*vit].GetMasterlistLoadAfterFiles()) {
auto parentVertex = GetVertexByName(file.GetName());
auto parentVertex = GetVertexByName(std::string(file.GetName()));
if (parentVertex.has_value()) {
AddEdge(parentVertex.value(), *vit, EdgeType::masterlistLoadAfter);
}
}
for (const auto& file : graph_[*vit].GetUserLoadAfterFiles()) {
auto parentVertex = GetVertexByName(file.GetName());
auto parentVertex = GetVertexByName(std::string(file.GetName()));
if (parentVertex.has_value()) {
AddEdge(parentVertex.value(), *vit, EdgeType::userLoadAfter);
}
+15 -15
View File
@@ -36,7 +36,7 @@ namespace test {
TEST(File, defaultConstructorShouldInitialiseEmptyStrings) {
File file;
EXPECT_EQ("", file.GetName());
EXPECT_EQ("", std::string(file.GetName()));
EXPECT_EQ("", file.GetDisplayName());
EXPECT_EQ("", file.GetCondition());
}
@@ -44,7 +44,7 @@ TEST(File, defaultConstructorShouldInitialiseEmptyStrings) {
TEST(File, stringsConstructorShouldStoreGivenStrings) {
File file("name", "display", "condition");
EXPECT_EQ("name", file.GetName());
EXPECT_EQ("name", std::string(file.GetName()));
EXPECT_EQ("display", file.GetDisplayName());
EXPECT_EQ("condition", file.GetCondition());
}
@@ -279,9 +279,9 @@ TEST(File, emittingAsYamlShouldSingleQuoteValues) {
File file("name1", "display1", "condition1");
YAML::Emitter emitter;
emitter << file;
std::string expected = "name: '" + file.GetName() + "'\ncondition: '" +
file.GetCondition() + "'\ndisplay: '" +
file.GetDisplayName() + "'";
std::string expected = "name: '" + std::string(file.GetName()) +
"'\ncondition: '" + file.GetCondition() +
"'\ndisplay: '" + file.GetDisplayName() + "'";
EXPECT_EQ(expected, emitter.c_str());
}
@@ -291,7 +291,7 @@ TEST(File, emittingAsYamlShouldOutputAsAScalarIfOnlyTheNameStringIsNotEmpty) {
YAML::Emitter emitter;
emitter << file;
EXPECT_EQ("'" + file.GetName() + "'", emitter.c_str());
EXPECT_EQ("'" + std::string(file.GetName()) + "'", emitter.c_str());
}
TEST(File, emittingAsYamlShouldOmitDisplayFieldIfItMatchesTheNameField) {
@@ -299,15 +299,15 @@ TEST(File, emittingAsYamlShouldOmitDisplayFieldIfItMatchesTheNameField) {
YAML::Emitter emitter;
emitter << file;
EXPECT_EQ("'" + file.GetName() + "'", emitter.c_str());
EXPECT_EQ("'" + std::string(file.GetName()) + "'", emitter.c_str());
}
TEST(File, emittingAsYamlShouldOmitAnEmptyConditionString) {
File file("name1", "display1");
YAML::Emitter emitter;
emitter << file;
std::string expected = "name: '" + file.GetName() + "'\ndisplay: '" +
file.GetDisplayName() + "'";
std::string expected = "name: '" + std::string(file.GetName()) +
"'\ndisplay: '" + file.GetDisplayName() + "'";
EXPECT_EQ(expected, emitter.c_str());
}
@@ -317,7 +317,7 @@ TEST(File, encodingAsYamlShouldStoreDataCorrectly) {
YAML::Node node;
node = file;
EXPECT_EQ(file.GetName(), node["name"].as<std::string>());
EXPECT_EQ(std::string(file.GetName()), node["name"].as<std::string>());
EXPECT_EQ(file.GetDisplayName(), node["display"].as<std::string>());
EXPECT_EQ(file.GetCondition(), node["condition"].as<std::string>());
}
@@ -327,7 +327,7 @@ TEST(File, encodingAsYamlShouldOmitEmptyFields) {
YAML::Node node;
node = file;
EXPECT_EQ(file.GetName(), node["name"].as<std::string>());
EXPECT_EQ(std::string(file.GetName()), node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
}
@@ -337,7 +337,7 @@ TEST(File, encodingAsYamlShouldOmitDisplayFieldIfItMatchesTheNameField) {
YAML::Node node;
node = file;
EXPECT_EQ(file.GetName(), node["name"].as<std::string>());
EXPECT_EQ(std::string(file.GetName()), node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
}
@@ -347,7 +347,7 @@ TEST(File, decodingFromYamlShouldSetDataCorrectly) {
"{name: name1, display: display1, condition: 'file(\"Foo.esp\")'}");
File file = node.as<File>();
EXPECT_EQ(node["name"].as<std::string>(), file.GetName());
EXPECT_EQ(node["name"].as<std::string>(), std::string(file.GetName()));
EXPECT_EQ(node["display"].as<std::string>(), file.GetDisplayName());
EXPECT_EQ(node["condition"].as<std::string>(), file.GetCondition());
}
@@ -357,7 +357,7 @@ TEST(File,
YAML::Node node = YAML::Load("{name: name1, display: display1}");
File file = node.as<File>();
EXPECT_EQ(node["name"].as<std::string>(), file.GetName());
EXPECT_EQ(node["name"].as<std::string>(), std::string(file.GetName()));
EXPECT_EQ(node["display"].as<std::string>(), file.GetDisplayName());
EXPECT_TRUE(file.GetCondition().empty());
}
@@ -368,7 +368,7 @@ TEST(
YAML::Node node = YAML::Load("name1");
File file = node.as<File>();
EXPECT_EQ(node.as<std::string>(), file.GetName());
EXPECT_EQ(node.as<std::string>(), std::string(file.GetName()));
EXPECT_EQ(node.as<std::string>(), file.GetDisplayName());
EXPECT_TRUE(file.GetCondition().empty());
}
+1 -1
View File
@@ -41,7 +41,7 @@ along with LOOT. If not, see
namespace loot {
namespace test {
void PrintTo(const File& value, ::std::ostream* os) {
*os << "File(\"" << value.GetName() << "\", "
*os << "File(\"" << std::string(value.GetName()) << "\", "
<< "\"" << value.GetDisplayName() << "\", "
<< "\"" << value.GetCondition() << "\""
<< ")";