diff options
Diffstat (limited to 'src/settings.h')
-rw-r--r-- | src/settings.h | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/settings.h b/src/settings.h index 80d41fd79..b19733514 100644 --- a/src/settings.h +++ b/src/settings.h @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "threading/mutex.h" #include <string> -#include <map> +#include "util/cpp11_container.h" #include <list> #include <set> @@ -35,8 +35,17 @@ struct NoiseParams; extern Settings *g_settings; extern std::string g_settings_path; -/** function type to register a changed callback */ -typedef void (*setting_changed_callback)(const std::string &name, void *data); +// Type for a settings changed callback function +typedef void (*SettingsChangedCallback)(const std::string &name, void *data); + +typedef std::vector< + std::pair< + SettingsChangedCallback, + void * + > +> SettingsCallbackList; + +typedef UNORDERED_MAP<std::string, SettingsCallbackList> SettingsCallbackMap; enum ValueType { VALUETYPE_STRING, @@ -89,6 +98,8 @@ struct SettingsEntry { bool is_group; }; +typedef UNORDERED_MAP<std::string, SettingsEntry> SettingEntries; + class Settings { public: Settings() {} @@ -209,24 +220,28 @@ public: void clearDefaults(); void updateValue(const Settings &other, const std::string &name); void update(const Settings &other); - void registerChangedCallback(std::string name, setting_changed_callback cbf, void *userdata = NULL); - void deregisterChangedCallback(std::string name, setting_changed_callback cbf, void *userdata = NULL); -private: + void registerChangedCallback(const std::string &name, + SettingsChangedCallback cbf, void *userdata = NULL); + void deregisterChangedCallback(const std::string &name, + SettingsChangedCallback cbf, void *userdata = NULL); +private: void updateNoLock(const Settings &other); void clearNoLock(); void clearDefaultsNoLock(); - void doCallbacks(std::string name); + void doCallbacks(const std::string &name) const; + + SettingEntries m_settings; + SettingEntries m_defaults; - std::map<std::string, SettingsEntry> m_settings; - std::map<std::string, SettingsEntry> m_defaults; + SettingsCallbackMap m_callbacks; - std::map<std::string, std::vector<std::pair<setting_changed_callback,void*> > > m_callbacks; + mutable Mutex m_callback_mutex; - mutable Mutex m_callbackMutex; - mutable Mutex m_mutex; // All methods that access m_settings/m_defaults directly should lock this. + // All methods that access m_settings/m_defaults directly should lock this. + mutable Mutex m_mutex; }; |