3 #ifndef __CDS_CONTAINER_STRIPED_MAP_STD_HASH_MAP_MSVC_ADAPTER_H
4 #define __CDS_CONTAINER_STRIPED_MAP_STD_HASH_MAP_MSVC_ADAPTER_H
6 #ifndef __CDS_CONTAINER_STRIPED_MAP_STD_HASH_MAP_ADAPTER_H
7 # error <cds/container/striped_map/std_hash_map.h> must be included instead of <cds/container/striped_map/std_hash_map_vc.h> header
10 #include <cds/container/striped_set/adapter.h>
14 namespace cds { namespace container {
15 namespace striped_set {
17 // Copy policy for map
18 template <typename Key, typename T, typename Traits, typename Alloc>
19 struct copy_item_policy< stdext::hash_map< Key, T, Traits, Alloc > >
21 typedef stdext::hash_map< Key, T, Traits, Alloc > map_type;
22 typedef typename map_type::value_type pair_type;
23 typedef typename map_type::iterator iterator;
25 void operator()( map_type& map, iterator itWhat )
27 std::pair< typename map_type::iterator, bool> res = map.insert( *itWhat );
28 assert( res.second ) ; // succesful insert
32 // Swap policy for map
33 template <typename Key, typename T, typename Traits, typename Alloc>
34 struct swap_item_policy< stdext::hash_map< Key, T, Traits, Alloc > >
36 typedef stdext::hash_map< Key, T, Traits, Alloc > map_type;
37 typedef typename map_type::value_type pair_type;
38 typedef typename map_type::iterator iterator;
40 void operator()( map_type& map, iterator itWhat )
42 pair_type newVal( itWhat->first, typename pair_type::second_type() );
43 std::pair< typename map_type::iterator, bool> res = map.insert( newVal );
44 assert( res.second ) ; // succesful insert
45 std::swap( res.first->second, itWhat->second );
49 #ifdef CDS_MOVE_SEMANTICS_SUPPORT
50 // Move policy for map
51 template <typename Key, typename T, typename Traits, typename Alloc>
52 struct move_item_policy< stdext::hash_map< Key, T, Traits, Alloc > >
54 typedef stdext::hash_map< Key, T, Traits, Alloc > map_type;
55 typedef typename map_type::value_type pair_type;
56 typedef typename map_type::iterator iterator;
58 void operator()( map_type& map, iterator itWhat )
60 map.insert( std::move( *itWhat ) );
64 } // namespace striped_set
65 }} // namespace cds::container
67 namespace cds { namespace intrusive { namespace striped_set {
69 /// stdext::hash_map adapter for hash map bucket
70 template <typename Key, typename T, class Traits, class Alloc, CDS_SPEC_OPTIONS>
71 class adapt< stdext::hash_map< Key, T, Traits, Alloc>, CDS_OPTIONS >
74 typedef stdext::hash_map< Key, T, Traits, Alloc> container_type ; ///< underlying container type
77 /// Adapted container type
78 class adapted_container: public cds::container::striped_set::adapted_container
81 typedef typename container_type::value_type value_type ; ///< value type stored in the container
82 typedef typename container_type::key_type key_type;
83 typedef typename container_type::mapped_type mapped_type;
84 typedef typename container_type::iterator iterator ; ///< container iterator
85 typedef typename container_type::const_iterator const_iterator ; ///< container const iterator
87 static bool const has_find_with = false;
88 static bool const has_erase_with = false;
92 typedef typename cds::opt::select<
93 typename cds::opt::value<
94 typename cds::opt::find_option<
95 cds::opt::copy_policy< cds::container::striped_set::move_item >
99 , cds::container::striped_set::copy_item, cds::container::striped_set::copy_item_policy<container_type>
100 , cds::container::striped_set::swap_item, cds::container::striped_set::swap_item_policy<container_type>
101 #ifdef CDS_MOVE_SEMANTICS_SUPPORT
102 , cds::container::striped_set::move_item, cds::container::striped_set::move_item_policy<container_type>
109 container_type m_Map;
113 template <typename Q, typename Func>
114 bool insert( const Q& key, Func f )
116 std::pair<iterator, bool> res = m_Map.insert( value_type( key, mapped_type() ) );
118 ::cds::unref(f)( *res.first );
122 template <typename Q, typename Func>
123 std::pair<bool, bool> ensure( const Q& val, Func func )
125 std::pair<iterator, bool> res = m_Map.insert( value_type( val, mapped_type() ));
126 ::cds::unref(func)( res.second, *res.first );
127 return std::make_pair( true, res.second );
130 template <typename Q, typename Func>
131 bool erase( const Q& key, Func f )
133 iterator it = m_Map.find( key_type(key) );
134 if ( it == m_Map.end() )
136 ::cds::unref(f)( *it );
141 template <typename Q, typename Func>
142 bool find( Q& val, Func f )
144 iterator it = m_Map.find( key_type(val) );
145 if ( it == m_Map.end() )
147 ::cds::unref(f)( *it, val );
156 iterator begin() { return m_Map.begin(); }
157 const_iterator begin() const { return m_Map.begin(); }
158 iterator end() { return m_Map.end(); }
159 const_iterator end() const { return m_Map.end(); }
161 void move_item( adapted_container& /*from*/, iterator itWhat )
163 assert( m_Map.find( itWhat->first ) == m_Map.end() );
164 copy_item()( m_Map, itWhat );
174 typedef adapted_container type ; ///< Result of \p adapt metafunction
177 }}} // namespace cds::intrusive::striped_set
182 #endif // #ifndef __CDS_CONTAINER_STRIPED_MAP_STD_HASH_MAP_MSVC_ADAPTER_H