Remove old VC std::map from tests
[libcds.git] / tests / unit / map2 / std_hash_map_vc.h
1 //$$CDS-header$$
2
3 #ifndef __CDSUNIT_STD_HASH_MAP_VC_H
4 #define __CDSUNIT_STD_HASH_MAP_VC_H
5
6 #include <hash_map>
7 #include <functional>   // ref
8 #include <mutex>    //unique_lock
9
10 namespace map2 {
11     template <typename Key, typename Value, typename Lock, class Alloc = CDS_DEFAULT_ALLOCATOR>
12     class StdHashMap: public stdext::hash_map<Key, Value, stdext::hash_compare<Key, std::less<Key> >, Alloc>
13     {
14     public:
15         Lock m_lock;
16         typedef std::unique_lock<Lock> AutoLock;
17         typedef stdext::hash_map<Key, Value, stdext::hash_compare<Key, std::less<Key> >, Alloc>   base_class;
18     public:
19         typedef typename base_class::mapped_type value_type;
20         typedef typename base_class::value_type  pair_type;
21         typedef size_t      item_counter;
22
23         StdHashMap( size_t nMapSize, size_t nLoadFactor )
24         {}
25
26         bool find( const Key& key )
27         {
28             AutoLock al( m_lock );
29             return base_class::find( key ) != base_class::end();
30         }
31
32         bool insert( const Key& key, const Value& val )
33         {
34             AutoLock al( m_lock );
35             return base_class::insert( base_class::value_type(key, val)).second;
36         }
37
38         template <typename T, typename Func>
39         bool insert( const Key& key, const T& val, Func func )
40         {
41             AutoLock al( m_lock );
42             std::pair<base_class::iterator, bool> pRet = base_class::insert( base_class::value_type(key, Value() ));
43             if ( pRet.second ) {
44                 func( pRet.first->second, val );
45                 return true;
46             }
47             return false;
48         }
49
50         template <typename T, typename Func>
51         std::pair<bool, bool> ensure( const T& key, Func func )
52         {
53             AutoLock al( m_lock );
54             std::pair<base_class::iterator, bool> pRet = base_class::insert( base_class::value_type(key, Value() ));
55             if ( pRet.second ) {
56                 func( true, *pRet.first );
57                 return std::make_pair( true, true );
58             }
59             else {
60                 func( false, *pRet.first );
61                 return std::make_pair( true, false );
62             }
63         }
64
65         bool erase( const Key& key )
66         {
67             AutoLock al( m_lock );
68             return base_class::erase( key ) != 0;
69         }
70
71         template <typename T, typename Func>
72         bool erase( const T& key, Func func )
73         {
74             AutoLock al( m_lock );
75             base_class::iterator it = base_class::find( key );
76             if ( it != base_class::end() ) {
77                 func( *it );
78                 return base_class::erase( key ) != 0;
79             }
80             return false;
81         }
82
83
84         std::ostream& dump( std::ostream& stm ) { return stm; }
85     };
86 }   // namespace map2
87
88 #endif  // #ifndef __CDSUNIT_STD_HASH_MAP_VC_H