diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2018-06-04 12:44:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-04 12:44:57 +0200 |
| commit | 8074192a85557feaf84d4aaab9ab42b02464220b (patch) | |
| tree | 397fdd6af48ef94001e5df65102495ea4b89139d /Source/Core/Common/IniFile.h | |
| parent | 472e0d55b807c7a5be847f113109ee4b38b48e80 (diff) | |
| parent | 7154bfd82559747681313531b5d53ab44bd88493 (diff) | |
Merge pull request #7057 from leoetlino/string
Config/StringUtil/IniFile: Get rid of some duplicated code
Diffstat (limited to 'Source/Core/Common/IniFile.h')
| -rw-r--r-- | Source/Core/Common/IniFile.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/Source/Core/Common/IniFile.h b/Source/Core/Common/IniFile.h index 697e700e7e..f11a4b9d32 100644 --- a/Source/Core/Common/IniFile.h +++ b/Source/Core/Common/IniFile.h @@ -12,6 +12,7 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" +#include "Common/StringUtil.h" struct CaseInsensitiveStringCompare { @@ -35,20 +36,17 @@ public: 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, const std::string& defaultValue); - void Set(const std::string& key, u32 newValue); - void Set(const std::string& key, u64 new_value); - void Set(const std::string& key, float newValue); - 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> + void Set(const std::string& key, const T& new_value) + { + Set(key, ValueToString(new_value)); + } 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) - Set(key, newValue); + if (new_value != default_value) + Set(key, new_value); else Delete(key); } @@ -57,13 +55,17 @@ public: bool Get(const std::string& key, std::string* value, const std::string& defaultValue = NULL_STRING) const; - bool Get(const std::string& key, int* value, int defaultValue = 0) const; - bool Get(const std::string& key, s64* value, s64 default_value = 0) const; - bool Get(const std::string& key, u32* value, u32 defaultValue = 0) const; - bool Get(const std::string& key, u64* value, u64 default_value = 0) const; - bool Get(const std::string& key, bool* value, bool defaultValue = false) const; - bool Get(const std::string& key, float* value, float defaultValue = 0.0f) const; - bool Get(const std::string& key, double* value, double defaultValue = 0.0) const; + template <typename T> + bool Get(const std::string& key, T* value, + const std::common_type_t<T>& default_value = {}) const + { + std::string temp; + bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) + return true; + *value = default_value; + return false; + } bool Get(const std::string& key, std::vector<std::string>* values) const; void SetLines(const std::vector<std::string>& lines); |
