1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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>
30 * A Class that maps a string to an uint32
31 * \author Benjamin Legros
32 * \author Nevrax France
42 UnknownString
= 0xfffffff
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;
56 void setMapping(const std::string
& str
, uint32 id
);
60 void serial(NLMISC::IStream
& f
);
62 /// Rebuild Id Mapping
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
;
75 TStringMap _StringMap
;
81 static std::string _UnknownString
;
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
;
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 */