3 #ifndef __CDSUNIT_STD_MAP_VC_H
4 #define __CDSUNIT_STD_MAP_VC_H
10 template <typename Key, typename Value, typename Lock, class Alloc = CDS_DEFAULT_ALLOCATOR>
11 class StdMap: public std::map<Key, Value, std::less<Key>, Alloc>
14 typedef cds::lock::scoped_lock<Lock> AutoLock;
15 typedef std::map<Key, Value, std::less<Key>, Alloc> base_class;
17 typedef typename base_class::mapped_type value_type;
18 typedef typename base_class::value_type pair_type;
19 typedef size_t item_counter;
21 StdMap( size_t nMapSize, size_t nLoadFactor )
24 bool find( const Key& key )
26 AutoLock al( m_lock );
27 return base_class::find( key ) != base_class::end();
30 bool insert( const Key& key, const Value& val )
32 AutoLock al( m_lock );
33 return base_class::insert( base_class::value_type(key, val)).second;
36 template <typename T, typename Func>
37 bool insert( const Key& key, const T& val, Func func )
39 AutoLock al( m_lock );
40 std::pair<base_class::iterator, bool> pRet = base_class::insert( base_class::value_type(key, Value() ));
42 cds::unref(func)( pRet.first->second, val );
48 template <typename T, typename Func>
49 std::pair<bool, bool> ensure( const T& key, Func func )
51 AutoLock al( m_lock );
52 std::pair<base_class::iterator, bool> pRet = base_class::insert( base_class::value_type(key, Value() ));
54 cds::unref(func)( true, *pRet.first );
55 return std::make_pair( true, true );
58 cds::unref(func)( false, *pRet.first );
59 return std::make_pair( true, false );
63 bool erase( const Key& key )
65 AutoLock al( m_lock );
66 return base_class::erase( key ) != 0;
69 template <typename T, typename Func>
70 bool erase( const T& key, Func func )
72 AutoLock al( m_lock );
73 base_class::iterator it = base_class::find( key );
74 if ( it != base_class::end() ) {
75 cds::unref(func)( *it );
77 base_class::erase( it );
83 std::ostream& dump( std::ostream& stm ) { return stm; }
87 #endif // #ifndef __CDSUNIT_STD_MAP_VC_H