3 // Copyright (c) 2006-2007 Matias Capeletto
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)
9 /// \file views/map_view.hpp
10 /// \brief View of a side of a bimap that is signature compatible with std::map.
12 #ifndef BOOST_BIMAP_VIEWS_MAP_VIEW_HPP
13 #define BOOST_BIMAP_VIEWS_MAP_VIEW_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #include <boost/bimap/container_adaptor/map_adaptor.hpp>
22 #include <boost/bimap/detail/map_view_base.hpp>
28 /// \brief View of a side of a bimap that is signature compatible with std::map.
31 This class uses container_adaptor and iterator_adaptor to wrapped a index of the
32 multi_index bimap core so it can be used as a std::map.
34 See also const_map_view.
37 template< class Tag, class BimapType >
40 public BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
43 reverse_iterator_type_by,const_reverse_iterator_type_by
45 public ::boost::bimaps::detail::
46 map_view_base< map_view<Tag,BimapType>,Tag,BimapType >,
47 public ::boost::bimaps::detail::
48 unique_map_view_access< map_view<Tag,BimapType>, Tag, BimapType>::type
50 typedef BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
53 reverse_iterator_type_by,const_reverse_iterator_type_by
57 BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(map_view,Tag,BimapType)
59 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
60 unique_map_view_access<
61 map_view<Tag,BimapType>, Tag, BimapType
63 >::type unique_map_view_access_;
67 typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type;
69 map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c) : base_(c) {}
71 using unique_map_view_access_::at;
72 using unique_map_view_access_::operator[];
74 BOOST_BIMAP_MAP_VIEW_RANGE_IMPLEMENTATION(base_)
76 map_view & operator=(const map_view & v)
78 this->base() = v.base();
82 // It can be used enable_if here but the error message when there
83 // is no info is very clear like this
85 template< class CompatibleKey >
86 const info_type & info_at(const CompatibleKey& k) const
88 BOOST_DEDUCED_TYPENAME base_::const_iterator iter = this->find(k);
89 if( iter == this->end() )
91 ::boost::throw_exception(
92 std::out_of_range("bimap<>: invalid key")
98 template< class CompatibleKey >
99 info_type & info_at(const CompatibleKey& k)
101 BOOST_DEDUCED_TYPENAME base_::iterator iter = this->find(k);
102 if( iter == this->end() )
104 ::boost::throw_exception(
105 std::out_of_range("bimap<>: invalid key")
114 /*===========================================================================*/
115 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,TYPENAME) \
116 typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \
117 BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME));
118 /*===========================================================================*/
120 /*===========================================================================*/
121 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \
122 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,reverse_iterator) \
123 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_reverse_iterator) \
124 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,range_type) \
125 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_range_type) \
126 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,key_compare)
127 /*===========================================================================*/
131 template< class Tag, class BimapType >
132 struct left_map_view_extra_typedefs< ::boost::bimaps::views::map_view<Tag,BimapType> >
134 private: typedef ::boost::bimaps::views::map_view<Tag,BimapType> map_view_;
135 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,left)
138 template< class Tag, class BimapType >
139 struct right_map_view_extra_typedefs< ::boost::bimaps::views::map_view<Tag,BimapType> >
141 private: typedef ::boost::bimaps::views::map_view<Tag,BimapType> map_view_;
142 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,right)
145 } // namespace detail
147 /*===========================================================================*/
148 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF
149 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY
150 /*===========================================================================*/
152 } // namespace bimaps
155 #endif // BOOST_BIMAP_VIEWS_MAP_VIEW_HPP