mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add int64_t support to INI parser (#12374)
This commit is contained in:
parent
6ba6184602
commit
3b60740128
|
@ -155,6 +155,23 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
int64_t GetInt64(const std::string& name, int64_t defaultValue) const override
|
||||
{
|
||||
int64_t result = defaultValue;
|
||||
std::string value;
|
||||
if (TryGetString(name, &value))
|
||||
{
|
||||
try
|
||||
{
|
||||
result = std::stoll(value);
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
float GetFloat(const std::string& name, float defaultValue) const override
|
||||
{
|
||||
float result = defaultValue;
|
||||
|
@ -388,6 +405,11 @@ public:
|
|||
return defaultValue;
|
||||
}
|
||||
|
||||
int64_t GetInt64([[maybe_unused]] const std::string& name, int64_t defaultValue) const override
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
float GetFloat([[maybe_unused]] const std::string& name, float defaultValue) const override
|
||||
{
|
||||
return defaultValue;
|
||||
|
|
|
@ -24,6 +24,7 @@ interface IIniReader
|
|||
|
||||
virtual bool GetBoolean(const std::string& name, bool defaultValue) const abstract;
|
||||
virtual int32_t GetInt32(const std::string& name, int32_t defaultValue) const abstract;
|
||||
virtual int64_t GetInt64(const std::string& name, int64_t defaultValue) const abstract;
|
||||
virtual float GetFloat(const std::string& name, float defaultValue) const abstract;
|
||||
virtual std::string GetString(const std::string& name, const std::string& defaultValue) const abstract;
|
||||
virtual bool TryGetString(const std::string& name, std::string* outValue) const abstract;
|
||||
|
|
|
@ -48,6 +48,11 @@ public:
|
|||
WriteProperty(name, std::to_string(value));
|
||||
}
|
||||
|
||||
void WriteInt64(const std::string& name, int64_t value) override
|
||||
{
|
||||
WriteProperty(name, std::to_string(value));
|
||||
}
|
||||
|
||||
void WriteFloat(const std::string& name, float value) override
|
||||
{
|
||||
WriteProperty(name, std::to_string(value));
|
||||
|
|
|
@ -24,6 +24,7 @@ interface IIniWriter
|
|||
|
||||
virtual void WriteBoolean(const std::string& name, bool value) abstract;
|
||||
virtual void WriteInt32(const std::string& name, int32_t value) abstract;
|
||||
virtual void WriteInt64(const std::string& name, int64_t value) abstract;
|
||||
virtual void WriteFloat(const std::string& name, float value) abstract;
|
||||
virtual void WriteString(const std::string& name, const std::string& value) abstract;
|
||||
virtual void WriteEnum(const std::string& name, const std::string& key) abstract;
|
||||
|
|
|
@ -39,6 +39,8 @@ TEST_F(IniReaderTest, create_empty)
|
|||
ASSERT_EQ(ir->GetEnum<int32_t>("spanish", 12345, Enum_Currency), 12345);
|
||||
ASSERT_EQ(ir->GetFloat("inquisition", 1.234f), 1.234f);
|
||||
ASSERT_EQ(ir->GetInt32("universal_answer", 42), 42);
|
||||
ASSERT_EQ(
|
||||
ir->GetInt64("heat_death_of_the_universe", std::numeric_limits<int64_t>::max()), std::numeric_limits<int64_t>::max());
|
||||
delete ir;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue