1 // Boost.Bimap 2 // 3 // Copyright (c) 2006-2007 Matias Capeletto 4 // 5 // Distributed under the Boost Software License, Version 1.0. 6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 9 /// \file views/vector_map_view.hpp 10 /// \brief View of a side of a bimap. 11 12 #ifndef BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP 13 #define BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP 14 15 #if defined(_MSC_VER) 16 #pragma once 17 #endif 18 19 #include <boost/config.hpp> 20 21 #include <boost/bimap/container_adaptor/vector_map_adaptor.hpp> 22 #include <boost/bimap/support/iterator_type_by.hpp> 23 #include <boost/bimap/detail/map_view_base.hpp> 24 #include <boost/bimap/container_adaptor/detail/comparison_adaptor.hpp> 25 26 namespace boost { 27 namespace bimaps { 28 namespace views { 29 30 /// \brief View of a side of a bimap. 31 /** 32 33 This class uses container_adaptor and iterator_adaptor to wrapped a index of the 34 multi_index bimap core. 35 36 See also const_map_view. 37 **/ 38 template< class Tag, class BimapType > 39 class vector_map_view 40 : 41 public BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR( 42 vector_map_adaptor, 43 Tag,BimapType, 44 reverse_map_view_iterator, const_reverse_map_view_iterator 45 ), 46 47 public ::boost::bimaps::detail:: 48 map_view_base< vector_map_view<Tag,BimapType>,Tag,BimapType > 49 { 50 typedef BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR( 51 vector_map_adaptor, 52 Tag,BimapType, 53 reverse_map_view_iterator, const_reverse_map_view_iterator 54 55 ) base_; 56 57 BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(vector_map_view,Tag,BimapType) 58 59 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::data_extractor 60 < 61 Tag, 62 BOOST_DEDUCED_TYPENAME BimapType::relation 63 64 >::type key_from_base_value; 65 66 public: 67 68 typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type; 69 vector_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c)70 vector_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c) : 71 base_(c) {} 72 operator =(const vector_map_view & v)73 vector_map_view & operator=(const vector_map_view & v) 74 { 75 this->base() = v.base(); 76 return *this; 77 } 78 79 BOOST_DEDUCED_TYPENAME base_::const_reference operator [](BOOST_DEDUCED_TYPENAME base_::size_type n) const80 operator[](BOOST_DEDUCED_TYPENAME base_::size_type n) const 81 { 82 return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()( 83 this->base().operator[](n) 84 ); 85 } 86 87 BOOST_DEDUCED_TYPENAME base_::const_reference at(BOOST_DEDUCED_TYPENAME base_::size_type n) const88 at(BOOST_DEDUCED_TYPENAME base_::size_type n) const 89 { 90 return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()( 91 this->base().at(n) 92 ); 93 } 94 95 BOOST_DEDUCED_TYPENAME base_::reference operator [](BOOST_DEDUCED_TYPENAME base_::size_type n)96 operator[](BOOST_DEDUCED_TYPENAME base_::size_type n) 97 { 98 return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()( 99 const_cast<BOOST_DEDUCED_TYPENAME base_::base_type::value_type &>( 100 this->base().operator[](n) 101 )); 102 } 103 104 BOOST_DEDUCED_TYPENAME base_::reference at(BOOST_DEDUCED_TYPENAME base_::size_type n)105 at(BOOST_DEDUCED_TYPENAME base_::size_type n) 106 { 107 return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()( 108 const_cast<BOOST_DEDUCED_TYPENAME base_::base_type::value_type &>( 109 this->base().at(n) 110 )); 111 } 112 113 BOOST_BIMAP_VIEW_ASSIGN_IMPLEMENTATION(base_) 114 BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(base_)115 BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(base_) 116 117 // Lists operations 118 119 void splice(BOOST_DEDUCED_TYPENAME base_::iterator position, vector_map_view & x) 120 { 121 this->base().splice( 122 this->template functor< 123 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), 124 x.base() 125 ); 126 } 127 splice(BOOST_DEDUCED_TYPENAME base_::iterator position,vector_map_view & x,BOOST_DEDUCED_TYPENAME base_::iterator i)128 void splice(BOOST_DEDUCED_TYPENAME base_::iterator position, 129 vector_map_view & x, 130 BOOST_DEDUCED_TYPENAME base_::iterator i) 131 { 132 this->base().splice( 133 this->template functor< 134 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), 135 x.base(), 136 this->template functor< 137 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(i) 138 ); 139 } 140 splice(BOOST_DEDUCED_TYPENAME base_::iterator position,vector_map_view & x,BOOST_DEDUCED_TYPENAME base_::iterator first,BOOST_DEDUCED_TYPENAME base_::iterator last)141 void splice(BOOST_DEDUCED_TYPENAME base_::iterator position, 142 vector_map_view & x, 143 BOOST_DEDUCED_TYPENAME base_::iterator first, 144 BOOST_DEDUCED_TYPENAME base_::iterator last) 145 { 146 this->base().splice( 147 this->template functor< 148 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), 149 x.base(), 150 this->template functor< 151 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(first), 152 this->template functor< 153 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(last) 154 ); 155 } 156 remove(BOOST_DEDUCED_TYPENAME::boost::call_traits<BOOST_DEDUCED_TYPENAME base_::value_type>::param_type value)157 void remove(BOOST_DEDUCED_TYPENAME ::boost::call_traits< 158 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type value) 159 { 160 this->base().remove( 161 this->template functor< 162 BOOST_DEDUCED_TYPENAME base_::value_to_base>()(value) 163 ); 164 } 165 166 template< class Predicate > remove_if(Predicate pred)167 void remove_if(Predicate pred) 168 { 169 this->base().remove_if( 170 ::boost::bimaps::container_adaptor::detail::unary_check_adaptor 171 < 172 Predicate, 173 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 174 key_from_base_value 175 176 >( pred, key_from_base_value() ) 177 ); 178 } 179 unique()180 void unique() 181 { 182 this->base().unique( 183 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 184 < 185 std::equal_to<BOOST_DEDUCED_TYPENAME base_::key_type>, 186 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 187 key_from_base_value 188 189 >(std::equal_to<BOOST_DEDUCED_TYPENAME base_::key_type>(), 190 key_from_base_value() ) 191 ); 192 } 193 194 template< class BinaryPredicate > unique(BinaryPredicate binary_pred)195 void unique(BinaryPredicate binary_pred) 196 { 197 this->base().unique( 198 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 199 < 200 BinaryPredicate, 201 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 202 key_from_base_value 203 204 >( binary_pred, key_from_base_value() ) 205 ); 206 } 207 merge(vector_map_view & x)208 void merge(vector_map_view & x) 209 { 210 this->base().merge(x.base(), 211 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 212 < 213 std::less<BOOST_DEDUCED_TYPENAME base_::key_type>, 214 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 215 key_from_base_value 216 217 >( std::less<BOOST_DEDUCED_TYPENAME base_::key_type>(), 218 key_from_base_value() ) 219 ); 220 } 221 222 template< class Compare > merge(vector_map_view & x,Compare comp)223 void merge(vector_map_view & x, Compare comp) 224 { 225 this->base().merge(x.base(), 226 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 227 < 228 Compare, 229 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 230 key_from_base_value 231 232 >( comp, key_from_base_value() ) 233 ); 234 } 235 sort()236 void sort() 237 { 238 this->base().sort( 239 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 240 < 241 std::less<BOOST_DEDUCED_TYPENAME base_::key_type>, 242 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 243 key_from_base_value 244 245 >( std::less<BOOST_DEDUCED_TYPENAME base_::key_type>(), 246 key_from_base_value() ) 247 ); 248 } 249 250 template< class Compare > sort(Compare comp)251 void sort(Compare comp) 252 { 253 this->base().sort( 254 ::boost::bimaps::container_adaptor::detail::comparison_adaptor 255 < 256 Compare, 257 BOOST_DEDUCED_TYPENAME base_::base_type::value_type, 258 key_from_base_value 259 260 >( comp, key_from_base_value() ) 261 ); 262 } 263 reverse()264 void reverse() 265 { 266 this->base().reverse(); 267 } 268 269 // Rearrange Operations 270 relocate(BOOST_DEDUCED_TYPENAME base_::iterator position,BOOST_DEDUCED_TYPENAME base_::iterator i)271 void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position, 272 BOOST_DEDUCED_TYPENAME base_::iterator i) 273 { 274 this->base().relocate( 275 this->template functor< 276 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), 277 this->template functor< 278 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(i) 279 ); 280 } 281 relocate(BOOST_DEDUCED_TYPENAME base_::iterator position,BOOST_DEDUCED_TYPENAME base_::iterator first,BOOST_DEDUCED_TYPENAME base_::iterator last)282 void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position, 283 BOOST_DEDUCED_TYPENAME base_::iterator first, 284 BOOST_DEDUCED_TYPENAME base_::iterator last) 285 { 286 this->base().relocate( 287 this->template functor< 288 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), 289 this->template functor< 290 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(first), 291 this->template functor< 292 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(last) 293 ); 294 } 295 296 }; 297 298 299 } // namespace views 300 301 /*===========================================================================*/ 302 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,TYPENAME) \ 303 typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \ 304 BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME)); 305 /*===========================================================================*/ 306 307 /*===========================================================================*/ 308 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \ 309 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,reverse_iterator) \ 310 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_reverse_iterator) 311 /*===========================================================================*/ 312 313 namespace detail { 314 315 template< class Tag, class BimapType > 316 struct left_map_view_extra_typedefs< ::boost::bimaps::views::vector_map_view<Tag,BimapType> > 317 { 318 private: typedef ::boost::bimaps::views::vector_map_view<Tag,BimapType> map_view_; 319 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,left) 320 }; 321 322 template< class Tag, class BimapType > 323 struct right_map_view_extra_typedefs< ::boost::bimaps::views::vector_map_view<Tag,BimapType> > 324 { 325 private: typedef ::boost::bimaps::views::vector_map_view<Tag,BimapType> map_view_; 326 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,right) 327 }; 328 329 } // namespace detail 330 331 /*===========================================================================*/ 332 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF 333 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY 334 /*===========================================================================*/ 335 336 } // namespace bimaps 337 } // namespace boost 338 339 #endif // BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP 340 341