ScummVM API documentation
hash-str.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
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 General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_HASH_STR_H
23 #define COMMON_HASH_STR_H
24 
25 #include "common/hashmap.h"
26 #include "common/str.h"
27 
28 namespace Common {
29 
30 uint hashit(const char *str);
31 uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string
32 inline uint hashit_lower(const String &str) { return hashit_lower(str.c_str()); }
33 
34 // FIXME: The following functors obviously are not consistently named
35 
37  bool operator()(const String& x, const String& y) const { return x.equals(y); }
38 };
39 
41  uint operator()(const String& x) const { return x.hash(); }
42 };
43 
44 
46  bool operator()(const String& x, const String& y) const { return x.equalsIgnoreCase(y); }
47 };
48 
50  uint operator()(const String& x) const { return hashit_lower(x.c_str()); }
51 };
52 
53 // Specalization of the Hash functor for String objects.
54 // We do case sensitve hashing here, because that is what
55 // the default EqualTo is compatible with. If one wants to use
56 // case insensitve hashing, then only because one wants to use
57 // IgnoreCase_EqualTo, and then one has to specify a custom
58 // hash anyway.
59 template<>
60 struct Hash<String> {
61  uint operator()(const String& s) const {
62  return s.hash();
63  }
64 };
65 
66 template<>
67 struct Hash<U32String> {
68  uint operator()(const U32String& s) const {
69  return s.hash();
70  }
71 };
72 
73 template<>
74 struct Hash<const char *> {
75  uint operator()(const char *s) const {
76  return hashit(s);
77  }
78 };
79 
80 // String map -- by default case insensitive
82 
83 } // End of namespace Common
84 
85 #endif
Definition: str.h:59
bool equals(const BaseString &x) const
Definition: func.h:527
Definition: hash-str.h:40
Definition: ustr.h:57
Definition: algorithm.h:29
Definition: hash-str.h:49
Definition: hash-str.h:45
Definition: hash-str.h:36