Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / pd_lib / pd_string_mapper.h
blob411e70b36112141b3a2e7554fd196f85c2bce351
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef NL_PD_STRING_MAPPER_H
21 #define NL_PD_STRING_MAPPER_H
23 #include <nel/misc/types_nl.h>
24 #include <nel/misc/stream.h>
25 #include <map>
26 #include <string>
27 #include <vector>
29 /**
30 * A Class that maps a string to an uint32
31 * \author Benjamin Legros
32 * \author Nevrax France
33 * \date 2003
35 class CPDStringMapper
37 public:
39 /// Unknown String Id
40 enum
42 UnknownString = 0xfffffff
45 /// Constructor
46 CPDStringMapper();
49 /// Get String from Id
50 const std::string& getString(uint32 id) const;
52 /// Get Id from String
53 uint32 getId(const std::string& str) const;
55 /// Set Mapping
56 void setMapping(const std::string& str, uint32 id);
59 /// Serial Mapper
60 void serial(NLMISC::IStream& f);
62 /// Rebuild Id Mapping
63 void buildIdMap();
66 private:
68 /// Mapping of string to id
69 typedef std::map<std::string, uint32> TStringMap;
71 /// Mapping of id to string
72 typedef std::map<uint32, TStringMap::iterator> TIdMap;
74 /// String Mapping
75 TStringMap _StringMap;
77 /// Id Mapping
78 TIdMap _IdMap;
80 /// Unknown String
81 static std::string _UnknownString;
87 * -- Inlines
92 * Get String from Id
94 inline const std::string& CPDStringMapper::getString(uint32 id) const
96 TIdMap::const_iterator it = _IdMap.find(id);
98 if (it == _IdMap.end())
100 return _UnknownString;
103 TStringMap::iterator its = (*it).second;
104 return (*its).first;
108 * Get Id from String
110 inline uint32 CPDStringMapper::getId(const std::string& str) const
112 std::string lowMapStr = NLMISC::toLowerAscii(str);
113 TStringMap::const_iterator it = _StringMap.find(lowMapStr);
115 return (it == _StringMap.end()) ? UnknownString : (*it).second;
119 #endif // NL_PD_STRING_MAPPER_H
121 /* End of pd_string_mapper.h */