@@ -177,10 +177,24 @@ namespace rts
177177 }
178178 };
179179
180+ template <> struct hash <const Char*>
181+ {
182+ size_t operator ()(const Char* s) const
183+ {
184+ #ifdef USING_STLPORT
185+ std::hash<const Char*> hasher;
186+ return hasher (s);
187+ #else
188+ std::hash<std::string_view> hasher;
189+ return hasher (s);
190+ #endif
191+ }
192+ };
193+
180194 // This is the equal_to overload for char* comparisons. We compare the
181195 // strings to determine whether they are equal or not.
182196 // Other overloads should go into specific header files, not here (unless
183- // they are ot be used in lots of places.)
197+ // they are to be used in lots of places.)
184198 template <> struct equal_to <const char *>
185199 {
186200 Bool operator ()(const char * s1, const char * s2) const
@@ -227,6 +241,62 @@ namespace rts
227241 return (__t1.compareNoCase (__t2) < 0 );
228242 }
229243 };
230- }
244+
245+ // TheSuperHackers @info Structs to help create maps that can use C strings for
246+ // lookups without the need to allocate a string.
247+ template <typename String>
248+ struct string_key
249+ {
250+ typedef typename String::const_pointer const_pointer;
251+
252+ static string_key temporary (const_pointer s)
253+ {
254+ string_key key;
255+ key.cstr = s;
256+ return key;
257+ }
258+
259+ string_key (const_pointer s)
260+ : storage(s)
261+ , cstr(storage.str())
262+ {}
263+
264+ string_key (const String& s)
265+ : storage(s)
266+ , cstr(storage.str())
267+ {}
268+
269+ const_pointer c_str () const
270+ {
271+ return cstr;
272+ }
273+
274+ private:
275+ string_key () {}
276+
277+ String storage;
278+ const_pointer cstr;
279+ };
280+
281+ template <typename String>
282+ struct string_key_hash
283+ {
284+ typedef typename String::const_pointer const_pointer;
285+ size_t operator ()(const string_key<String>& key) const
286+ {
287+ return hash<const_pointer>()(key.c_str ());
288+ }
289+ };
290+
291+ template <typename String>
292+ struct string_key_equal
293+ {
294+ bool operator ()(const string_key<String>& a, const string_key<String>& b) const
295+ {
296+ return strcmp (a.c_str (), b.c_str ()) == 0 ;
297+ }
298+ };
299+
300+ } // namespace rts
231301
232302#endif /* __STLTYPEDEFS_H__ */
0 commit comments