| 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/list_map_view.hpp |
| 10 | /// \brief View of a side of a bimap. |
| 11 | |
| 12 | #ifndef BOOST_BIMAP_VIEWS_LIST_MAP_VIEW_HPP |
| 13 | #define BOOST_BIMAP_VIEWS_LIST_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/list_map_adaptor.hpp> |
| 22 | #include <boost/bimap/relation/support/pair_by.hpp> |
| 23 | #include <boost/bimap/support/iterator_type_by.hpp> |
| 24 | #include <boost/bimap/detail/map_view_base.hpp> |
| 25 | #include <boost/bimap/relation/support/data_extractor.hpp> |
| 26 | #include <boost/bimap/relation/detail/to_mutable_relation_functor.hpp> |
| 27 | |
| 28 | namespace boost { |
| 29 | namespace bimaps { |
| 30 | namespace views { |
| 31 | |
| 32 | #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES |
| 33 | |
| 34 | template< class Tag, class BimapType > |
| 35 | struct list_map_view_base |
| 36 | { |
| 37 | typedef ::boost::bimaps::container_adaptor::list_map_adaptor |
| 38 | < |
| 39 | BOOST_DEDUCED_TYPENAME BimapType::core_type:: |
| 40 | BOOST_NESTED_TEMPLATE index<Tag>::type, |
| 41 | ::boost::bimaps::detail:: map_view_iterator<Tag,BimapType>, |
| 42 | ::boost::bimaps::detail:: const_map_view_iterator<Tag,BimapType>, |
| 43 | ::boost::bimaps::detail:: reverse_map_view_iterator<Tag,BimapType>, |
| 44 | ::boost::bimaps::detail::const_reverse_map_view_iterator<Tag,BimapType>, |
| 45 | ::boost::bimaps::container_adaptor::support::iterator_facade_to_base |
| 46 | < |
| 47 | ::boost::bimaps::detail:: map_view_iterator<Tag,BimapType>, |
| 48 | ::boost::bimaps::detail::const_map_view_iterator<Tag,BimapType> |
| 49 | |
| 50 | >, |
| 51 | ::boost::mpl::na, |
| 52 | ::boost::mpl::na, |
| 53 | ::boost::bimaps::relation::detail:: |
| 54 | pair_to_relation_functor<Tag, BOOST_DEDUCED_TYPENAME BimapType::relation >, |
| 55 | ::boost::bimaps::relation::support:: |
| 56 | get_pair_functor<Tag, BOOST_DEDUCED_TYPENAME BimapType::relation >, |
| 57 | |
| 58 | BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::data_extractor |
| 59 | < |
| 60 | Tag, |
| 61 | BOOST_DEDUCED_TYPENAME BimapType::relation |
| 62 | |
| 63 | >::type |
| 64 | |
| 65 | > type; |
| 66 | }; |
| 67 | |
| 68 | #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES |
| 69 | |
| 70 | /// \brief View of a side of a bimap. |
| 71 | /** |
| 72 | |
| 73 | This class uses container_adaptor and iterator_adaptor to wrapped a index of the |
| 74 | multi_index bimap core. |
| 75 | |
| 76 | See also const_list_map_view. |
| 77 | **/ |
| 78 | template< class Tag, class BimapType > |
| 79 | class list_map_view |
| 80 | : |
| 81 | public list_map_view_base<Tag,BimapType>::type, |
| 82 | public ::boost::bimaps::detail:: |
| 83 | map_view_base< list_map_view<Tag,BimapType>,Tag,BimapType > |
| 84 | |
| 85 | { |
| 86 | typedef BOOST_DEDUCED_TYPENAME list_map_view_base<Tag,BimapType>::type base_; |
| 87 | |
| 88 | BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(list_map_view,Tag,BimapType) |
| 89 | |
| 90 | public: |
| 91 | |
| 92 | typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type; |
| 93 | |
| 94 | list_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c) : |
| 95 | base_(c) {} |
| 96 | |
| 97 | list_map_view & operator=(const list_map_view & v) |
| 98 | { |
| 99 | this->base() = v.base(); |
| 100 | return *this; |
| 101 | } |
| 102 | |
| 103 | BOOST_BIMAP_VIEW_ASSIGN_IMPLEMENTATION(base_) |
| 104 | |
| 105 | BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(base_) |
| 106 | |
| 107 | // Rearrange Operations |
| 108 | |
| 109 | void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position, |
| 110 | BOOST_DEDUCED_TYPENAME base_::iterator i) |
| 111 | { |
| 112 | this->base().relocate( |
| 113 | this->template functor< |
| 114 | BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), |
| 115 | this->template functor< |
| 116 | BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(i) |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position, |
| 121 | BOOST_DEDUCED_TYPENAME base_::iterator first, |
| 122 | BOOST_DEDUCED_TYPENAME base_::iterator last) |
| 123 | { |
| 124 | this->base().relocate( |
| 125 | this->template functor< |
| 126 | BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position), |
| 127 | this->template functor< |
| 128 | BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(first), |
| 129 | this->template functor< |
| 130 | BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(last) |
| 131 | ); |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | } // namespace views |
| 137 | |
| 138 | /*===========================================================================*/ |
| 139 | #define (MAP_VIEW,SIDE,TYPENAME) \ |
| 140 | typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \ |
| 141 | BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME)); |
| 142 | /*===========================================================================*/ |
| 143 | |
| 144 | /*===========================================================================*/ |
| 145 | #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \ |
| 146 | BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,reverse_iterator) \ |
| 147 | BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_reverse_iterator) \ |
| 148 | /*===========================================================================*/ |
| 149 | |
| 150 | namespace detail { |
| 151 | |
| 152 | template< class Tag, class BimapType > |
| 153 | struct < ::boost::bimaps::views::list_map_view<Tag,BimapType> > |
| 154 | { |
| 155 | private: typedef ::boost::bimaps::views::list_map_view<Tag,BimapType> ; |
| 156 | public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,left) |
| 157 | }; |
| 158 | |
| 159 | template< class Tag, class BimapType > |
| 160 | struct < ::boost::bimaps::views::list_map_view<Tag,BimapType> > |
| 161 | { |
| 162 | private: typedef ::boost::bimaps::views::list_map_view<Tag,BimapType> ; |
| 163 | public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,right) |
| 164 | }; |
| 165 | |
| 166 | } // namespace detail |
| 167 | |
| 168 | /*===========================================================================*/ |
| 169 | #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF |
| 170 | #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY |
| 171 | /*===========================================================================*/ |
| 172 | |
| 173 | } // namespace bimaps |
| 174 | } // namespace boost |
| 175 | |
| 176 | #endif // BOOST_BIMAP_VIEWS_LIST_MAP_VIEW_HPP |
| 177 | |
| 178 | |