3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef NAMEIDMAPPING_HEADER
21 #define NAMEIDMAPPING_HEADER
26 #include "irrlichttypes_bloated.h"
27 #include "util/cpp11_container.h"
32 void serialize(std::ostream &os) const;
33 void deSerialize(std::istream &is);
41 void set(u16 id, const std::string &name){
42 m_id_to_name[id] = name;
43 m_name_to_id[name] = id;
45 void removeId(u16 id){
47 bool found = getName(id, name);
49 m_id_to_name.erase(id);
50 m_name_to_id.erase(name);
52 void eraseName(const std::string &name){
54 bool found = getId(name, id);
56 m_id_to_name.erase(id);
57 m_name_to_id.erase(name);
59 bool getName(u16 id, std::string &result) const{
60 UNORDERED_MAP<u16, std::string>::const_iterator i;
61 i = m_id_to_name.find(id);
62 if(i == m_id_to_name.end())
67 bool getId(const std::string &name, u16 &result) const{
68 UNORDERED_MAP<std::string, u16>::const_iterator i;
69 i = m_name_to_id.find(name);
70 if(i == m_name_to_id.end())
76 return m_id_to_name.size();
79 UNORDERED_MAP<u16, std::string> m_id_to_name;
80 UNORDERED_MAP<std::string, u16> m_name_to_id;