summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2018-06-03 14:39:38 +0200
committerLéo Lam <leo@innovatetechnologi.es>2018-06-03 14:53:56 +0200
commit7e79bf97abf57130d21d635d908ff3ca12e89fb4 (patch)
tree1e0ce96272daa24a9e2528a57d4e587e5e44d46f /Source/Core
parentcba32b12e77c8f023ca5efeda7c386b856ad3f47 (diff)
IniFile: Use templates for Get()
Gets rid of duplicated code.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/IniFile.cpp84
-rw-r--r--Source/Core/Common/IniFile.h18
2 files changed, 11 insertions, 91 deletions
diff --git a/Source/Core/Common/IniFile.cpp b/Source/Core/Common/IniFile.cpp
index d24149b6da..604c4b0fc9 100644
--- a/Source/Core/Common/IniFile.cpp
+++ b/Source/Core/Common/IniFile.cpp
@@ -110,90 +110,6 @@ bool IniFile::Section::Get(const std::string& key, std::vector<std::string>* out
return true;
}
-bool IniFile::Section::Get(const std::string& key, int* value, int defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, s64* value, s64 default_value) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = default_value;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, u64* value, u64 default_value) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = default_value;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, bool* value, bool defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, float* value, float defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
bool IniFile::Section::Exists(const std::string& key) const
{
return values.find(key) != values.end();
diff --git a/Source/Core/Common/IniFile.h b/Source/Core/Common/IniFile.h
index 4830422ea3..f11a4b9d32 100644
--- a/Source/Core/Common/IniFile.h
+++ b/Source/Core/Common/IniFile.h
@@ -55,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);