mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Make PluginInterface::GetHeaderVersion() return an optional
While the value could actually be NaN, that's also what esplugin uses to signal that the version could not be found, and either way a NaN value is useless.
This commit is contained in:
@@ -48,10 +48,10 @@ public:
|
||||
/**
|
||||
* Get the value of the version field in the HEDR subrecord of the plugin's
|
||||
* TES4 record.
|
||||
* @return The value of the version field, or NaN if the field could not be
|
||||
* found.
|
||||
* @return The value of the version field, or an empty optional if that value
|
||||
* is NaN or could not be found.
|
||||
*/
|
||||
virtual float GetHeaderVersion() const = 0;
|
||||
virtual std::optional<float> GetHeaderVersion() const = 0;
|
||||
|
||||
/**
|
||||
* Get the plugin's version number from its description field.
|
||||
|
||||
+6
-1
@@ -90,14 +90,19 @@ Plugin::Plugin(const GameType gameType,
|
||||
|
||||
std::string Plugin::GetName() const { return name_; }
|
||||
|
||||
float Plugin::GetHeaderVersion() const {
|
||||
std::optional<float> Plugin::GetHeaderVersion() const {
|
||||
float version;
|
||||
|
||||
auto ret = esp_plugin_header_version(esPlugin.get(), &version);
|
||||
if (ret != ESP_OK) {
|
||||
throw FileAccessError(name_ +
|
||||
" : esplugin error code: " + std::to_string(ret));
|
||||
}
|
||||
|
||||
if (std::isnan(version)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public:
|
||||
const bool headerOnly);
|
||||
|
||||
std::string GetName() const;
|
||||
float GetHeaderVersion() const;
|
||||
std::optional<float> GetHeaderVersion() const;
|
||||
std::optional<std::string> GetVersion() const;
|
||||
std::vector<std::string> GetMasters() const;
|
||||
std::vector<Tag> GetBashTags() const;
|
||||
|
||||
@@ -140,7 +140,7 @@ private:
|
||||
class OtherPluginType : public PluginInterface {
|
||||
public:
|
||||
std::string GetName() const { return ""; }
|
||||
float GetHeaderVersion() const { return 0.0f; }
|
||||
std::optional<float> GetHeaderVersion() const { return 0.0f; }
|
||||
std::optional<std::string> GetVersion() const { return std::nullopt; }
|
||||
std::vector<std::string> GetMasters() const {
|
||||
return std::vector<std::string>();
|
||||
@@ -189,11 +189,11 @@ TEST_P(PluginTest, loadingHeaderOnlyShouldReadHeaderData) {
|
||||
EXPECT_EQ("5.0", plugin.GetVersion());
|
||||
|
||||
if (GetParam() == GameType::tes3) {
|
||||
EXPECT_FLOAT_EQ(1.2f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(1.2f, plugin.GetHeaderVersion().value());
|
||||
} else if (GetParam() == GameType::tes4) {
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion().value());
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion().value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,11 +215,11 @@ TEST_P(PluginTest, loadingWholePluginShouldReadHeaderData) {
|
||||
EXPECT_EQ("5.0", plugin.GetVersion());
|
||||
|
||||
if (GetParam() == GameType::tes3) {
|
||||
EXPECT_FLOAT_EQ(1.2f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(1.2f, plugin.GetHeaderVersion().value());
|
||||
} else if (GetParam() == GameType::tes4) {
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion().value());
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion());
|
||||
EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion().value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user