mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Settings: semi-automatic callback cleanup
This commit is contained in:
parent
9f43018df2
commit
e3813cf027
11 changed files with 25 additions and 78 deletions
|
@ -1048,21 +1048,22 @@ void Settings::registerChangedCallback(const std::string &name,
|
|||
m_callbacks[name].emplace_back(cbf, userdata);
|
||||
}
|
||||
|
||||
void Settings::deregisterChangedCallback(const std::string &name,
|
||||
SettingsChangedCallback cbf, void *userdata)
|
||||
size_t Settings::deregisterAllChangedCallbacks(const void *userdata)
|
||||
{
|
||||
MutexAutoLock lock(m_callback_mutex);
|
||||
SettingsCallbackMap::iterator it_cbks = m_callbacks.find(name);
|
||||
|
||||
if (it_cbks != m_callbacks.end()) {
|
||||
SettingsCallbackList &cbks = it_cbks->second;
|
||||
|
||||
SettingsCallbackList::iterator position =
|
||||
std::find(cbks.begin(), cbks.end(), std::make_pair(cbf, userdata));
|
||||
|
||||
if (position != cbks.end())
|
||||
cbks.erase(position);
|
||||
size_t n_removed = 0;
|
||||
for (auto &settings : m_callbacks) {
|
||||
for (auto cb = settings.second.begin(); cb != settings.second.end();) {
|
||||
if (cb->second == userdata) {
|
||||
cb = settings.second.erase(cb);
|
||||
n_removed++;
|
||||
} else {
|
||||
++cb;
|
||||
}
|
||||
}
|
||||
}
|
||||
return n_removed;
|
||||
}
|
||||
|
||||
void Settings::removeSecureSettings()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue