Lunchbox  1.8.0
hash.h
1 
2 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_HASH_H
19 #define LUNCHBOX_HASH_H
20 
21 #include <lunchbox/refPtr.h>
22 #include <lunchbox/stdExt.h>
23 
24 namespace lunchbox
25 {
27  template<class K, class T> class PtrHash
28 #ifdef _MSC_VER
29  : public stde::hash_map< K, T, stde::hash_compare< const void* > >
30 #else
31  : public stde::hash_map< K, T, stde::hash< const void* > >
32 #endif
33  {};
34 
36 #ifdef _MSC_VER
37  template< typename T >
38  class hashRefPtr : public stde::hash_compare< RefPtr< T > >
39  {
40  public:
41  size_t operator() ( const RefPtr< T >& key ) const
42  {
43  stde::hash_compare< const void* > comp;
44  return comp( key.get( ));
45  }
46 
47  bool operator() ( const RefPtr< T >& k1, const RefPtr< T >& k2 ) const
48  {
49  return k1 < k2;
50  }
51  };
52 
53  template< class K, class T > class RefPtrHash
54  : public stde::hash_map< RefPtr< K >, T, hashRefPtr< K > >
55  {};
56 
57 #else
58  template< typename T > struct hashRefPtr
59  {
60  size_t operator()( RefPtr< T > key ) const
61  {
62  return stde::hash< const void* >()( key.get() );
63  }
64  };
65 
67  template< class K, class T > class RefPtrHash
68  : public stde::hash_map< RefPtr< K >, T, hashRefPtr< K > >
69  {};
70 #endif
71 
73 template<class T> class UUIDHash : public stde::hash_map<lunchbox::UUID, T> {};
74 
75 }
76 #endif // LUNCHBOX_HASH_H