X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fsettings.h;h=8c4f6e559e05cfedc9f0c21953d947a6b9f80c69;hb=001de6ffbac83bcd41ecda075d79d265a69c7d42;hp=0af861a58683b79db16e587097091ac341b6e34c;hpb=33b874fea3948dfcbcc2d6761c28b325ca4aa367;p=minetest.git diff --git a/src/settings.h b/src/settings.h index 0af861a58..8c4f6e559 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 -#include +#include "util/cpp11_container.h" #include #include @@ -45,7 +45,7 @@ typedef std::vector< > > SettingsCallbackList; -typedef std::map SettingsCallbackMap; +typedef UNORDERED_MAP SettingsCallbackMap; enum ValueType { VALUETYPE_STRING, @@ -74,30 +74,29 @@ struct ValueSpec { }; struct SettingsEntry { - SettingsEntry() - { - group = NULL; - is_group = false; - } - - SettingsEntry(const std::string &value_) - { - value = value_; - group = NULL; - is_group = false; - } - - SettingsEntry(Settings *group_) - { - group = group_; - is_group = true; - } + SettingsEntry() : + group(NULL), + is_group(false) + {} + + SettingsEntry(const std::string &value_) : + value(value_), + group(NULL), + is_group(false) + {} + + SettingsEntry(Settings *group_) : + group(group_), + is_group(true) + {} std::string value; Settings *group; bool is_group; }; +typedef UNORDERED_MAP SettingEntries; + class Settings { public: Settings() {} @@ -127,8 +126,6 @@ class Settings { static bool checkNameValid(const std::string &name); static bool checkValueValid(const std::string &value); - static std::string sanitizeName(const std::string &name); - static std::string sanitizeValue(const std::string &value); static std::string getMultiline(std::istream &is, size_t *num_lines=NULL); static void printEntry(std::ostream &os, const std::string &name, const SettingsEntry &entry, u32 tab_depth=0); @@ -139,7 +136,7 @@ class Settings { const SettingsEntry &getEntry(const std::string &name) const; Settings *getGroup(const std::string &name) const; - std::string get(const std::string &name) const; + const std::string &get(const std::string &name) const; bool getBool(const std::string &name) const; u16 getU16(const std::string &name) const; s16 getS16(const std::string &name) const; @@ -231,8 +228,8 @@ class Settings { void doCallbacks(const std::string &name) const; - std::map m_settings; - std::map m_defaults; + SettingEntries m_settings; + SettingEntries m_defaults; SettingsCallbackMap m_callbacks;