Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2015-05-29 11:18:39 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:49:28 +0300
commite5b4c8e86709129d8d42aca719e5c9bedb1b3875 (patch)
tree37aba14d2cc1cede57b9b5ca64c37f1c087ff665
parentccc576381e789d31234362f5c64b4d172262cf88 (diff)
Added Settings::Delete() to clear settings.
-rw-r--r--platform/settings.cpp22
-rw-r--r--platform/settings.hpp6
2 files changed, 22 insertions, 6 deletions
diff --git a/platform/settings.cpp b/platform/settings.cpp
index 4a50da4264..df3c446691 100644
--- a/platform/settings.cpp
+++ b/platform/settings.cpp
@@ -56,22 +56,22 @@ namespace Settings
void StringStorage::Save() const
{
- /// @todo Add mutex.
+ // @TODO(AlexZ): Should we use mutex here?
try
{
FileWriter file(GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME));
- for (ContainerT::const_iterator it = m_values.begin(); it != m_values.end(); ++it)
+ for (auto const & value : m_values)
{
- string line(it->first);
+ string line(value.first);
line += DELIM_CHAR;
- line += it->second;
+ line += value.second;
line += "\n";
file.Write(line.data(), line.size());
}
}
catch (RootException const & ex)
{
- // Ignore all settings saving exceptions
+ // Ignore all settings saving exceptions.
LOG(LWARNING, (ex.Msg()));
}
}
@@ -84,7 +84,7 @@ namespace Settings
bool StringStorage::GetValue(string const & key, string & outValue)
{
- ContainerT::const_iterator found = m_values.find(key);
+ auto const found = m_values.find(key);
if (found == m_values.end())
return false;
@@ -98,6 +98,16 @@ namespace Settings
Save();
}
+ void StringStorage::DeleteKeyAndValue(string const & key)
+ {
+ auto const found = m_values.find(key);
+ if (found != m_values.end())
+ {
+ m_values.erase(found);
+ Save();
+ }
+ }
+
////////////////////////////////////////////////////////////////////////////////////////////
template <> string ToString<string>(string const & str)
diff --git a/platform/settings.hpp b/platform/settings.hpp
index 122075d8ba..c5cca5e6ae 100644
--- a/platform/settings.hpp
+++ b/platform/settings.hpp
@@ -21,6 +21,7 @@ namespace Settings
bool GetValue(string const & key, string & outValue);
void SetValue(string const & key, string const & value);
+ void DeleteKeyAndValue(string const & key);
};
/// Retrieve setting
@@ -37,6 +38,11 @@ namespace Settings
StringStorage::Instance().SetValue(key, ToString(value));
}
+ void Delete(string const & key)
+ {
+ StringStorage::Instance().DeleteKeyAndValue(key);
+ }
+
enum Units { Metric = 0, Yard, Foot };
/// Use this function for running some stuff once according to date.