cmtkHashMapSTL.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2009 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 269 $
00025 //
00026 //  $LastChangedDate: 2009-07-17 15:14:48 -0700 (Fri, 17 Jul 2009) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
00029 //
00030 */
00031 
00032 #ifndef __cmtkHashMapSTL_h_included_
00033 #define __cmtkHashMapSTL_h_included_
00034 
00035 #include <cmtkconfig.h>
00036 
00037 #define HAVE_STL_HASH_MAP
00038 
00039 #if defined(__APPLE__)
00040 #  include <hash_map.h>
00041 #elif defined(HAVE_UNORDERED_MAP)
00042 #  include <unordered_map>
00043 #elif defined(HAVE_UNORDERED_MAP_TR1)
00044 #  include <tr1/unordered_map>
00045 #elif defined(HAVE_HASH_MAP_H)
00046 #  include <hash_map.h>
00047 #elif defined(HAVE_HASH_MAP)
00048 #  include <hash_map>
00049 #else
00050 #  undef HAVE_STL_HASH_MAP
00051 #endif
00052 
00053 #ifdef __APPLE__
00054 namespace __gnu_cxx
00055 {
00056 
00057   template<>
00058     struct hash<unsigned long long>
00059     {
00060       size_t
00061       operator()(unsigned long long __x) const
00062       { return (__x & 0xffff) ^ (__x >> 32 ); }
00063     };
00064 
00065 }
00066 #endif // #ifdef __APPLE__
00067 
00068 #ifdef HAVE_STL_HASH_MAP
00069 namespace
00070 cmtk
00071 {
00072 
00073 #ifndef __APPLE__
00074 
00075 template<typename TKey>
00076 struct HashFunctionInteger
00077 {
00079   size_t operator()( const TKey x ) const
00080   { 
00081     return static_cast<size_t>( x ); 
00082   }
00083 };
00084 #endif // #ifdef __APPLE__
00085 
00091 template<
00092   class TKey, 
00093   class TValue, 
00094 #ifndef __APPLE__
00095   class THashFunc = HashFunctionInteger<TKey>
00096 #else
00097   class THashFunc = __gnu_cxx::hash<TKey>
00098 #endif
00099   >
00100 class HashMapSTL : 
00102 #if defined(__APPLE__)
00103     public __gnu_cxx::hash_map<TKey,TValue,THashFunc>
00104 #elif defined(_MSC_VER)
00105     public std::tr1::unordered_map<TKey,TValue,THashFunc>
00106 #elif defined(HAVE_UNORDERED_MAP)
00107     public std::unordered_map<TKey,TValue,THashFunc>
00108 #elif defined(HAVE_UNORDERED_MAP_TR1)
00109     public std::tr1::unordered_map<TKey,TValue,THashFunc>
00110 #elif defined(__GNUC__)
00111     public __gnu_cxx::hash_map<TKey,TValue,THashFunc>
00112 #else
00113     public std::hash_map<TKey,TValue,THashFunc>
00114 #endif
00115 {
00116 };
00117 
00118 } // namespace cmtk
00119 
00120 #endif // #ifdef HAVE_STL_HASH_MAP
00121 #endif // #ifndef __cmtkHashMapSTL_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines