From 7528986e4449febead9b18b6118f0b096f7cf800 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 19 Aug 2017 14:25:35 +0200 Subject: Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) * Code modernization: src/p*, src/q*, src/r*, src/s* (partial) * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Spelling: vertice -> vertex --- src/settings.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 1fa4ac528..ea54ab348 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -169,9 +169,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const { MutexAutoLock lock(m_mutex); - for (SettingEntries::const_iterator it = m_settings.begin(); - it != m_settings.end(); ++it) - printEntry(os, it->first, it->second, tab_depth); + for (const auto &setting_it : m_settings) + printEntry(os, setting_it.first, setting_it.second, tab_depth); } @@ -323,7 +322,7 @@ bool Settings::parseCommandLine(int argc, char *argv[], ValueType type = n->second.type; - std::string value = ""; + std::string value; if (type == VALUETYPE_FLAG) { value = "true"; @@ -506,7 +505,7 @@ bool Settings::getNoiseParamsFromValue(const std::string &name, np.persist = stof(f.next(",")); std::string optional_params = f.next(""); - if (optional_params != "") + if (!optional_params.empty()) np.lacunarity = stof(optional_params); return true; @@ -549,9 +548,8 @@ bool Settings::exists(const std::string &name) const std::vector Settings::getNames() const { std::vector names; - for (SettingEntries::const_iterator i = m_settings.begin(); - i != m_settings.end(); ++i) { - names.push_back(i->first); + for (const auto &settings_it : m_settings) { + names.push_back(settings_it.first); } return names; } @@ -861,9 +859,9 @@ bool Settings::remove(const std::string &name) delete it->second.group; m_settings.erase(it); return true; - } else { - return false; } + + return false; } @@ -887,8 +885,7 @@ void Settings::updateValue(const Settings &other, const std::string &name) MutexAutoLock lock(m_mutex); try { - std::string val = other.get(name); - m_settings[name] = val; + m_settings[name] = other.get(name); } catch (SettingNotFoundException &e) { } } @@ -965,7 +962,7 @@ void Settings::registerChangedCallback(const std::string &name, SettingsChangedCallback cbf, void *userdata) { MutexAutoLock lock(m_callback_mutex); - m_callbacks[name].push_back(std::make_pair(cbf, userdata)); + m_callbacks[name].emplace_back(cbf, userdata); } void Settings::deregisterChangedCallback(const std::string &name, -- cgit v1.2.3