summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/settings.cpp
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 56afa6133..c4c3c9073 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -196,9 +196,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const
{
MutexAutoLock lock(m_mutex);
- for (std::map<std::string, SettingsEntry>::const_iterator
- it = m_settings.begin();
- it != m_settings.end(); ++it)
+ for (SettingEntries::const_iterator it = m_settings.begin();
+ it != m_settings.end(); ++it)
printEntry(os, it->first, it->second, tab_depth);
}
@@ -231,7 +230,7 @@ void Settings::printEntry(std::ostream &os, const std::string &name,
bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
const std::string &end, u32 tab_depth)
{
- std::map<std::string, SettingsEntry>::const_iterator it;
+ SettingEntries::const_iterator it;
std::set<std::string> present_entries;
std::string line, name, value;
bool was_modified = false;
@@ -381,7 +380,7 @@ const SettingsEntry &Settings::getEntry(const std::string &name) const
{
MutexAutoLock lock(m_mutex);
- std::map<std::string, SettingsEntry>::const_iterator n;
+ SettingEntries::const_iterator n;
if ((n = m_settings.find(name)) == m_settings.end()) {
if ((n = m_defaults.find(name)) == m_defaults.end())
throw SettingNotFoundException("Setting [" + name + "] not found.");
@@ -572,9 +571,8 @@ bool Settings::exists(const std::string &name) const
std::vector<std::string> Settings::getNames() const
{
std::vector<std::string> names;
- for (std::map<std::string, SettingsEntry>::const_iterator
- i = m_settings.begin();
- i != m_settings.end(); ++i) {
+ for (SettingEntries::const_iterator i = m_settings.begin();
+ i != m_settings.end(); ++i) {
names.push_back(i->first);
}
return names;
@@ -880,7 +878,7 @@ bool Settings::remove(const std::string &name)
{
MutexAutoLock lock(m_mutex);
- std::map<std::string, SettingsEntry>::iterator it = m_settings.find(name);
+ SettingEntries::iterator it = m_settings.find(name);
if (it != m_settings.end()) {
delete it->second.group;
m_settings.erase(it);
@@ -912,7 +910,6 @@ void Settings::updateValue(const Settings &other, const std::string &name)
try {
std::string val = other.get(name);
-
m_settings[name] = val;
} catch (SettingNotFoundException &e) {
}
@@ -968,8 +965,9 @@ void Settings::updateNoLock(const Settings &other)
void Settings::clearNoLock()
{
- std::map<std::string, SettingsEntry>::const_iterator it;
- for (it = m_settings.begin(); it != m_settings.end(); ++it)
+
+ for (SettingEntries::const_iterator it = m_settings.begin();
+ it != m_settings.end(); ++it)
delete it->second.group;
m_settings.clear();
@@ -978,46 +976,45 @@ void Settings::clearNoLock()
void Settings::clearDefaultsNoLock()
{
- std::map<std::string, SettingsEntry>::const_iterator it;
- for (it = m_defaults.begin(); it != m_defaults.end(); ++it)
+ for (SettingEntries::const_iterator it = m_defaults.begin();
+ it != m_defaults.end(); ++it)
delete it->second.group;
m_defaults.clear();
}
-void Settings::registerChangedCallback(std::string name,
- setting_changed_callback cbf, void *userdata)
+void Settings::registerChangedCallback(const std::string &name,
+ SettingsChangedCallback cbf, void *userdata)
{
- MutexAutoLock lock(m_callbackMutex);
+ MutexAutoLock lock(m_callback_mutex);
m_callbacks[name].push_back(std::make_pair(cbf, userdata));
}
-void Settings::deregisterChangedCallback(std::string name, setting_changed_callback cbf, void *userdata)
+void Settings::deregisterChangedCallback(const std::string &name,
+ SettingsChangedCallback cbf, void *userdata)
{
- MutexAutoLock lock(m_callbackMutex);
- std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
- if (iterToVector != m_callbacks.end())
- {
- std::vector<std::pair<setting_changed_callback, void*> > &vector = iterToVector->second;
+ MutexAutoLock lock(m_callback_mutex);
+ SettingsCallbackMap::iterator it_cbks = m_callbacks.find(name);
- std::vector<std::pair<setting_changed_callback, void*> >::iterator position =
- std::find(vector.begin(), vector.end(), std::make_pair(cbf, userdata));
+ if (it_cbks != m_callbacks.end()) {
+ SettingsCallbackList &cbks = it_cbks->second;
- if (position != vector.end())
- vector.erase(position);
+ SettingsCallbackList::iterator position =
+ std::find(cbks.begin(), cbks.end(), std::make_pair(cbf, userdata));
+
+ if (position != cbks.end())
+ cbks.erase(position);
}
}
-void Settings::doCallbacks(const std::string name)
+void Settings::doCallbacks(const std::string &name) const
{
- MutexAutoLock lock(m_callbackMutex);
- std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
- if (iterToVector != m_callbacks.end())
- {
- std::vector<std::pair<setting_changed_callback, void*> >::iterator iter;
- for (iter = iterToVector->second.begin(); iter != iterToVector->second.end(); ++iter)
- {
- (iter->first)(name, iter->second);
- }
+ MutexAutoLock lock(m_callback_mutex);
+
+ SettingsCallbackMap::const_iterator it_cbks = m_callbacks.find(name);
+ if (it_cbks != m_callbacks.end()) {
+ SettingsCallbackList::const_iterator it;
+ for (it = it_cbks->second.begin(); it != it_cbks->second.end(); ++it)
+ (it->first)(name, it->second);
}
}