3 #ifndef CDSUNIT_STD_MAP_GCC_H
4 #define CDSUNIT_STD_MAP_GCC_H
7 #include <mutex> //unique_lock
11 template <typename Key, typename Value, typename Lock,
12 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<std::pair<Key const, Value> >::other
14 class StdMap: public std::map<Key, Value, std::less<Key>, Alloc>
17 typedef std::unique_lock<Lock> scoped_lock;
18 typedef std::map<Key, Value, std::less<Key>, Alloc> base_class;
20 typedef typename base_class::mapped_type value_type;
21 typedef typename base_class::value_type pair_type;
22 typedef size_t item_counter;
24 StdMap( size_t /*nMapSize*/, size_t /*nLoadFactor*/ )
27 bool find( const Key& key )
29 scoped_lock al( m_lock );
30 return base_class::find( key ) != base_class::end();
33 bool insert( const Key& key, const Value& val )
35 scoped_lock al( m_lock );
36 return base_class::insert( typename base_class::value_type(key, val)).second;
39 template <typename T, typename Func>
40 bool insert( const Key& key, const T& val, Func func )
42 scoped_lock al( m_lock );
43 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
45 func( pRet.first->second, val );
51 template <typename T, typename Func>
52 std::pair<bool, bool> ensure( const T& key, Func func )
54 scoped_lock al( m_lock );
55 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
57 func( true, *pRet.first );
58 return std::make_pair( true, true );
61 func( false, *pRet.first );
62 return std::make_pair( true, false );
66 bool erase( const Key& key )
68 scoped_lock al( m_lock );
69 return base_class::erase( key ) != 0;
72 template <typename T, typename Func>
73 bool erase( const T& key, Func func )
75 scoped_lock al( m_lock );
76 typename base_class::iterator it = base_class::find( key );
77 if ( it != base_class::end() ) {
79 base_class::erase( it );
85 std::ostream& dump( std::ostream& stm ) { return stm; }
89 #endif // #ifndef CDSUNIT_STD_MAP_GCC_H