1 /* 2 (C) Copyright 2001 Alexandre Courbot <alexandrecourbot@linuxgames.com> 3 (C) Copyright 2004/2016 Kai Sterker <kai.sterker@gmail.com> 4 Part of the Adonthell Project <http://adonthell.nongnu.org> 5 6 Adonthell is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 Adonthell is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Adonthell. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 /** 21 * @file str_hash.h 22 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 23 * @author Kai Sterker <kai.sterker@gmail.com> 24 * 25 * @brief Declares the hash<string> type, to be able to declare 26 * hash_maps with strings as keys. 27 */ 28 29 #ifndef STR_HASH_H 30 #define STR_HASH_H 31 32 #include "config.h" 33 34 #ifdef HAVE_UNORDERED_MAP 35 #include <unordered_map> 36 #include <unordered_set> 37 38 #define hash_map unordered_map 39 #define hash_set unordered_set 40 41 #elif HAVE_TR1_UNORDERED_MAP 42 #include <tr1/unordered_map> 43 #include <tr1/unordered_set> 44 45 #define hash_map tr1::unordered_map 46 #define hash_set tr1::unordered_set 47 48 #else 49 50 // gcc < 4.4 51 #if __GNUG__ > 2 52 #include <ext/hash_map> 53 #include <ext/hash_set> 54 #else 55 #include <hash_map> 56 #include <hash_set> 57 #endif 58 #include <string> 59 60 #if __GNUG__ > 2 61 namespace __gnu_cxx 62 #else 63 namespace std 64 #endif 65 { 66 /** 67 * Hash function for strings. 68 */ 69 template<> struct hash<std::string> 70 { 71 size_t operator() (const std::string & __s) const 72 { 73 return __stl_hash_string (__s.c_str()); 74 } 75 }; 76 } 77 78 #if __GNUG__ > 2 79 namespace std { using namespace __gnu_cxx; } 80 #endif 81 82 #endif 83 #endif // STR_HASH_H 84