382e283e108eb6fc0a73b9d781b32247f524c80d
[platform/upstream/libzypp.git] / zypp / base / Hash.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/Hash.h
10  *
11 */
12 #ifndef ZYPP_BASE_HASH_H
13 #define ZYPP_BASE_HASH_H
14
15 #include <iosfwd>
16 #include <unordered_set>
17 #include <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::Solvable )
24  * \endcode
25  */
26 #define ZYPP_DEFINE_ID_HASHABLE(C)              \
27 namespace std {                                 \
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   /** clone function for RW_pointer */
40   template<class D>
41   inline unordered_set<D> * rwcowClone( const std::unordered_set<D> * rhs )
42   { return new std::unordered_set<D>( *rhs ); }
43
44   /** clone function for RW_pointer */
45   template<class K, class V>
46   inline std::unordered_map<K,V> * rwcowClone( const std::unordered_map<K,V> * rhs )
47   { return new std::unordered_map<K,V>( *rhs ); }
48 } // namespace std
49 ///////////////////////////////////////////////////////////////////
50 #endif // ZYPP_BASE_HASH_H