summaryrefslogtreecommitdiff
path: root/src/settings.h
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.h
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.h')
-rw-r--r--src/settings.h39
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;
};