Imported Upstream version 14.48.2
[platform/upstream/libzypp.git] / zypp / base / Tr1hash.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/Tr1hash.h
10  *
11 */
12 #ifndef ZYPP_BASE_TR1HASH_H
13 #define ZYPP_BASE_TR1HASH_H
14
15 #include <iosfwd>
16 #include <tr1/unordered_set>
17 #include <tr1/unordered_map>
18
19 /** Define hash function for id based classes.
20  * Class has to provide a method \c id() retuning a unique number.
21  * \code
22  *  // in global namespace define:
23  *  ZYPP_DEFINE_ID_HASHABLE( ::zypp::sat::Sovable )
24  * \endcode
25  */
26 #define ZYPP_DEFINE_ID_HASHABLE(C)           \
27 namespace std { namespace tr1 {              \
28   template<class _Tp> struct hash;           \
29   template<> struct hash<C>                  \
30   {                                          \
31     size_t operator()( const C & __s ) const \
32     { return __s.id(); }                     \
33   };                                         \
34 }}
35
36 ///////////////////////////////////////////////////////////////////
37 namespace std
38 { /////////////////////////////////////////////////////////////////
39   ///////////////////////////////////////////////////////////////////
40   namespace tr1
41   { /////////////////////////////////////////////////////////////////
42
43     /** clone function for RW_pointer */
44     template<class _D>
45     inline unordered_set<_D> * rwcowClone( const std::tr1::unordered_set<_D> * rhs )
46     { return new std::tr1::unordered_set<_D>( *rhs ); }
47
48     /** clone function for RW_pointer */
49     template<class _K, class _V>
50     inline std::tr1::unordered_map<_K,_V> * rwcowClone( const std::tr1::unordered_map<_K,_V> * rhs )
51     { return new std::tr1::unordered_map<_K,_V>( *rhs ); }
52
53     /////////////////////////////////////////////////////////////////
54   } // namespace tr1
55   ///////////////////////////////////////////////////////////////////
56   /////////////////////////////////////////////////////////////////
57 } // namespace std
58 ///////////////////////////////////////////////////////////////////
59 #endif // ZYPP_BASE_TR1HASH_H