IniFile: Use templates for Set()
This commit is contained in:
parent
fc0193c4b1
commit
cba32b12e7
|
@ -57,55 +57,11 @@ void IniFile::Section::Set(const std::string& key, const std::string& newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, const std::string& newValue,
|
|
||||||
const std::string& defaultValue)
|
|
||||||
{
|
|
||||||
if (newValue != defaultValue)
|
|
||||||
Set(key, newValue);
|
|
||||||
else
|
|
||||||
Delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, const std::vector<std::string>& newValues)
|
void IniFile::Section::Set(const std::string& key, const std::vector<std::string>& newValues)
|
||||||
{
|
{
|
||||||
Set(key, JoinStrings(newValues, ","));
|
Set(key, JoinStrings(newValues, ","));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, u32 newValue)
|
|
||||||
{
|
|
||||||
Set(key, StringFromFormat("0x%08x", newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, u64 new_value)
|
|
||||||
{
|
|
||||||
Set(key, StringFromFormat("0x%016" PRIx64, new_value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, float newValue)
|
|
||||||
{
|
|
||||||
Set(key, StringFromFormat("%#.9g", newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, double newValue)
|
|
||||||
{
|
|
||||||
Set(key, StringFromFormat("%#.17g", newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, int newValue)
|
|
||||||
{
|
|
||||||
Set(key, std::to_string(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, s64 newValue)
|
|
||||||
{
|
|
||||||
Set(key, StringFromFormat("%" PRId64, newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IniFile::Section::Set(const std::string& key, bool newValue)
|
|
||||||
{
|
|
||||||
Set(key, ValueToString(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IniFile::Section::Get(const std::string& key, std::string* value,
|
bool IniFile::Section::Get(const std::string& key, std::string* value,
|
||||||
const std::string& defaultValue) const
|
const std::string& defaultValue) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "Common/CommonFuncs.h"
|
#include "Common/CommonFuncs.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
struct CaseInsensitiveStringCompare
|
struct CaseInsensitiveStringCompare
|
||||||
{
|
{
|
||||||
|
@ -35,20 +36,17 @@ public:
|
||||||
bool Delete(const std::string& key);
|
bool Delete(const std::string& key);
|
||||||
|
|
||||||
void Set(const std::string& key, const std::string& newValue);
|
void Set(const std::string& key, const std::string& newValue);
|
||||||
void Set(const std::string& key, const std::string& newValue, const std::string& defaultValue);
|
template <typename T>
|
||||||
void Set(const std::string& key, u32 newValue);
|
void Set(const std::string& key, const T& new_value)
|
||||||
void Set(const std::string& key, u64 new_value);
|
{
|
||||||
void Set(const std::string& key, float newValue);
|
Set(key, ValueToString(new_value));
|
||||||
void Set(const std::string& key, double newValue);
|
}
|
||||||
void Set(const std::string& key, int newValue);
|
|
||||||
void Set(const std::string& key, s64 new_value);
|
|
||||||
void Set(const std::string& key, bool newValue);
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Set(const std::string& key, T newValue, const T defaultValue)
|
void Set(const std::string& key, const T& new_value, const std::common_type_t<T>& default_value)
|
||||||
{
|
{
|
||||||
if (newValue != defaultValue)
|
if (new_value != default_value)
|
||||||
Set(key, newValue);
|
Set(key, new_value);
|
||||||
else
|
else
|
||||||
Delete(key);
|
Delete(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue