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 detail/set_view_base.hpp
10 /// \brief Helper base for the construction of the bimap views types.
12 #ifndef BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
13 #define BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
19 #include <boost/config.hpp>
21 #include <boost/bimap/relation/member_at.hpp>
22 #include <boost/bimap/relation/support/data_extractor.hpp>
23 #include <boost/bimap/detail/modifier_adaptor.hpp>
24 #include <boost/bimap/detail/set_view_iterator.hpp>
25 #include <boost/bimap/relation/support/get_pair_functor.hpp>
26 #include <boost/bimap/relation/detail/to_mutable_relation_functor.hpp>
27 #include <boost/bimap/relation/mutant_relation.hpp>
28 #include <boost/bimap/container_adaptor/support/iterator_facade_converters.hpp>
34 template< class Key, class Value, class KeyToBase >
35 class set_view_key_to_base
38 const Key operator()( const Value & v ) const
40 return keyToBase( v );
46 template< class MutantRelationStorage, class KeyToBase >
47 class set_view_key_to_base<MutantRelationStorage,MutantRelationStorage,KeyToBase>
49 typedef BOOST_DEDUCED_TYPENAME MutantRelationStorage::non_mutable_storage non_mutable_storage;
51 const MutantRelationStorage & operator()( const non_mutable_storage & k ) const
53 return ::boost::bimaps::relation::detail::mutate<MutantRelationStorage>(k);
55 const MutantRelationStorage & operator()( const MutantRelationStorage & k ) const
62 // The next macro can be converted in a metafunctor to gain code robustness.
63 /*===========================================================================*/
64 #define BOOST_BIMAP_SET_VIEW_CONTAINER_ADAPTOR( \
65 CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER \
67 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR \
70 ::boost::bimaps::detail:: \
72 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator >, \
73 ::boost::bimaps::detail:: \
74 const_set_view_iterator< \
75 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator >, \
76 ::boost::bimaps::detail:: \
78 BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER >, \
79 ::boost::bimaps::detail:: \
80 const_set_view_iterator< \
81 BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >, \
82 ::boost::bimaps::container_adaptor::support::iterator_facade_to_base \
84 ::boost::bimaps::detail:: set_view_iterator< \
85 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>, \
86 ::boost::bimaps::detail::const_set_view_iterator< \
87 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator> \
92 ::boost::bimaps::relation::detail:: \
93 get_mutable_relation_functor< \
94 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
95 ::boost::bimaps::relation::support:: \
96 get_above_view_functor< \
97 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
98 ::boost::bimaps::detail::set_view_key_to_base< \
99 BOOST_DEDUCED_TYPENAME CORE_INDEX::key_type, \
100 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type, \
101 BOOST_DEDUCED_TYPENAME CORE_INDEX::key_from_value \
104 /*===========================================================================*/
107 /*===========================================================================*/
108 #define BOOST_BIMAP_SEQUENCED_SET_VIEW_CONTAINER_ADAPTOR( \
109 CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER \
111 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR \
114 ::boost::bimaps::detail:: \
116 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator >, \
117 ::boost::bimaps::detail:: \
118 const_set_view_iterator< \
119 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator >, \
120 ::boost::bimaps::detail:: \
122 BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER >, \
123 ::boost::bimaps::detail:: \
124 const_set_view_iterator< \
125 BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >, \
126 ::boost::bimaps::container_adaptor::support::iterator_facade_to_base \
128 ::boost::bimaps::detail:: set_view_iterator< \
129 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>, \
130 ::boost::bimaps::detail::const_set_view_iterator< \
131 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator> \
136 ::boost::bimaps::relation::detail:: \
137 get_mutable_relation_functor< \
138 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
139 ::boost::bimaps::relation::support:: \
140 get_above_view_functor< \
141 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type > \
143 /*===========================================================================*/
146 #if defined(BOOST_MSVC)
147 /*===========================================================================*/
148 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE) \
149 typedef ::boost::bimaps::detail::set_view_base< \
150 TYPE< INDEX_TYPE >, INDEX_TYPE > template_class_friend; \
151 friend class template_class_friend;
152 /*===========================================================================*/
154 /*===========================================================================*/
155 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE) \
156 friend class ::boost::bimaps::detail::set_view_base< \
157 TYPE< INDEX_TYPE >, INDEX_TYPE >;
158 /*===========================================================================*/
162 /// \brief Common base for set views.
164 template< class Derived, class Index >
167 typedef ::boost::bimaps::container_adaptor::support::
168 iterator_facade_to_base
170 ::boost::bimaps::detail::
171 set_view_iterator<BOOST_DEDUCED_TYPENAME Index:: iterator>,
172 ::boost::bimaps::detail::
173 const_set_view_iterator<BOOST_DEDUCED_TYPENAME Index::const_iterator>
177 typedef BOOST_DEDUCED_TYPENAME Index::value_type::left_value_type left_type_;
179 typedef BOOST_DEDUCED_TYPENAME Index::value_type::right_value_type right_type_;
181 typedef BOOST_DEDUCED_TYPENAME Index::value_type value_type_;
183 typedef ::boost::bimaps::detail::
184 set_view_iterator<BOOST_DEDUCED_TYPENAME Index::iterator> iterator_;
188 bool replace(iterator_ position,
189 const value_type_ & x)
191 return derived().base().replace(
192 derived().template functor<iterator_to_base_>()(position),x
196 template< class CompatibleLeftType >
197 bool replace_left(iterator_ position,
198 const CompatibleLeftType & l)
200 return derived().base().replace(
201 derived().template functor<iterator_to_base_>()(position),
202 ::boost::bimaps::relation::detail::copy_with_left_replaced(*position,l)
206 template< class CompatibleRightType >
207 bool replace_right(iterator_ position,
208 const CompatibleRightType & r)
210 return derived().base().replace(
211 derived().template functor<iterator_to_base_>()(position),
212 ::boost::bimaps::relation::detail::copy_with_right_replaced(*position,r)
216 /* This function may be provided in the future
218 template< class Modifier >
219 bool modify(iterator_ position,
222 return derived().base().modify(
224 derived().template functor<iterator_to_base_>()(position),
226 ::boost::bimaps::detail::relation_modifier_adaptor
229 BOOST_DEDUCED_TYPENAME Index::value_type,
230 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
233 ::boost::bimaps::relation::member_at::left,
234 BOOST_DEDUCED_TYPENAME Index::value_type
237 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
240 ::boost::bimaps::relation::member_at::right,
241 BOOST_DEDUCED_TYPENAME Index::value_type
250 template< class Modifier >
251 bool modify_left(iterator_ position, Modifier mod)
253 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
256 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
257 BOOST_DEDUCED_TYPENAME Index::value_type
259 >::type left_data_extractor_;
261 return derived().base().modify(
263 derived().template functor<iterator_to_base_>()(position),
265 // this may be replaced later by
266 // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
268 ::boost::bimaps::detail::unary_modifier_adaptor
271 BOOST_DEDUCED_TYPENAME Index::value_type,
278 template< class Modifier >
279 bool modify_right(iterator_ position, Modifier mod)
281 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
284 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
285 BOOST_DEDUCED_TYPENAME Index::value_type
287 >::type right_data_extractor_;
289 return derived().base().modify(
291 derived().template functor<iterator_to_base_>()(position),
293 // this may be replaced later by
294 // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
296 ::boost::bimaps::detail::unary_modifier_adaptor
299 BOOST_DEDUCED_TYPENAME Index::value_type,
300 right_data_extractor_
308 typedef set_view_base set_view_base_;
312 // Curiously Recurring Template interface.
316 return *static_cast<Derived*>(this);
319 Derived const& derived() const
321 return *static_cast<Derived const*>(this);
327 } // namespace detail
328 } // namespace bimaps
331 #endif // BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP