]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/nameidmapping.h
Allow resetting celestial vault elements by leaving its arguments empty (#11922)
[dragonfireclient.git] / src / nameidmapping.h
index 417c441d23a7e1f0d486b70f9f74a5ec755053c7..3acb43ef120db7b0bed345872a008400f4c8127a 100644 (file)
@@ -17,66 +17,75 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef NAMEIDMAPPING_HEADER
-#define NAMEIDMAPPING_HEADER
+#pragma once
 
 #include <string>
 #include <iostream>
 #include <set>
-#include <map>
+#include <unordered_map>
 #include "irrlichttypes_bloated.h"
 
+typedef std::unordered_map<u16, std::string> IdToNameMap;
+typedef std::unordered_map<std::string, u16> NameToIdMap;
+
 class NameIdMapping
 {
 public:
        void serialize(std::ostream &os) const;
        void deSerialize(std::istream &is);
-       
-       void clear(){
+
+       void clear()
+       {
                m_id_to_name.clear();
                m_name_to_id.clear();
        }
-       void set(u16 id, const std::string &name){
+
+       void set(u16 id, const std::string &name)
+       {
                m_id_to_name[id] = name;
                m_name_to_id[name] = id;
        }
-       void removeId(u16 id){
+
+       void removeId(u16 id)
+       {
                std::string name;
                bool found = getName(id, name);
-               if(!found) return;
+               if (!found)
+                       return;
                m_id_to_name.erase(id);
                m_name_to_id.erase(name);
        }
-       void eraseName(const std::string &name){
+
+       void eraseName(const std::string &name)
+       {
                u16 id;
                bool found = getId(name, id);
-               if(!found) return;
+               if (!found)
+                       return;
                m_id_to_name.erase(id);
                m_name_to_id.erase(name);
        }
-       bool getName(u16 id, std::string &result) const{
-               std::map<u16, std::string>::const_iterator i;
+       bool getName(u16 id, std::string &result) const
+       {
+               IdToNameMap::const_iterator i;
                i = m_id_to_name.find(id);
-               if(i == m_id_to_name.end())
+               if (i == m_id_to_name.end())
                        return false;
                result = i->second;
                return true;
        }
-       bool getId(const std::string &name, u16 &result) const{
-               std::map<std::string, u16>::const_iterator i;
+       bool getId(const std::string &name, u16 &result) const
+       {
+               NameToIdMap::const_iterator i;
                i = m_name_to_id.find(name);
-               if(i == m_name_to_id.end())
+               if (i == m_name_to_id.end())
                        return false;
                result = i->second;
                return true;
        }
-       u16 size() const{
-               return m_id_to_name.size();
-       }
+       u16 size() const { return m_id_to_name.size(); }
+
 private:
-       std::map<u16, std::string> m_id_to_name;
-       std::map<std::string, u16> m_name_to_id;
+       IdToNameMap m_id_to_name;
+       NameToIdMap m_name_to_id;
 };
-
-#endif
-