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
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
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>
33 template< class Key, class Value, class KeyToBase >
34 class set_view_key_to_base
37 const Key operator()( const Value & v ) const
39 return keyToBase( v );
45 template< class MutantRelationStorage, class KeyToBase >
46 class set_view_key_to_base<MutantRelationStorage,MutantRelationStorage,KeyToBase>
48 typedef BOOST_DEDUCED_TYPENAME MutantRelationStorage::non_mutable_storage non_mutable_storage;
50 const MutantRelationStorage & operator()( const non_mutable_storage & k ) const
52 return ::boost::bimaps::relation::detail::mutate<MutantRelationStorage>(k);
54 const MutantRelationStorage & operator()( const MutantRelationStorage & k ) const
61 // The next macro can be converted in a metafunctor to gain code robustness.
62 /*===========================================================================*/
63 #define BOOST_BIMAP_SET_VIEW_CONTAINER_ADAPTOR( \
64 CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER \
66 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR \
69 ::boost::bimaps::detail:: \
71 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator >, \
72 ::boost::bimaps::detail:: \
73 const_set_view_iterator< \
74 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator >, \
75 ::boost::bimaps::detail:: \
77 BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER >, \
78 ::boost::bimaps::detail:: \
79 const_set_view_iterator< \
80 BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >, \
81 ::boost::bimaps::container_adaptor::support::iterator_facade_to_base \
83 ::boost::bimaps::detail:: set_view_iterator< \
84 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>, \
85 ::boost::bimaps::detail::const_set_view_iterator< \
86 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator> \
91 ::boost::bimaps::relation::detail:: \
92 get_mutable_relation_functor< \
93 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
94 ::boost::bimaps::relation::support:: \
95 get_above_view_functor< \
96 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
97 ::boost::bimaps::detail::set_view_key_to_base< \
98 BOOST_DEDUCED_TYPENAME CORE_INDEX::key_type, \
99 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type, \
100 BOOST_DEDUCED_TYPENAME CORE_INDEX::key_from_value \
103 /*===========================================================================*/
106 /*===========================================================================*/
107 #define BOOST_BIMAP_SEQUENCED_SET_VIEW_CONTAINER_ADAPTOR( \
108 CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER \
110 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR \
113 ::boost::bimaps::detail:: \
115 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator >, \
116 ::boost::bimaps::detail:: \
117 const_set_view_iterator< \
118 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator >, \
119 ::boost::bimaps::detail:: \
121 BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER >, \
122 ::boost::bimaps::detail:: \
123 const_set_view_iterator< \
124 BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >, \
125 ::boost::bimaps::container_adaptor::support::iterator_facade_to_base \
127 ::boost::bimaps::detail:: set_view_iterator< \
128 BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>, \
129 ::boost::bimaps::detail::const_set_view_iterator< \
130 BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator> \
135 ::boost::bimaps::relation::detail:: \
136 get_mutable_relation_functor< \
137 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >, \
138 ::boost::bimaps::relation::support:: \
139 get_above_view_functor< \
140 BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type > \
142 /*===========================================================================*/
145 #if defined(BOOST_MSVC)
146 /*===========================================================================*/
147 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE) \
148 typedef ::boost::bimaps::detail::set_view_base< \
149 TYPE< INDEX_TYPE >, INDEX_TYPE > template_class_friend; \
150 friend class template_class_friend;
151 /*===========================================================================*/
153 /*===========================================================================*/
154 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE) \
155 friend class ::boost::bimaps::detail::set_view_base< \
156 TYPE< INDEX_TYPE >, INDEX_TYPE >;
157 /*===========================================================================*/
161 /// \brief Common base for set views.
163 template< class Derived, class Index >
166 typedef ::boost::bimaps::container_adaptor::support::
167 iterator_facade_to_base
169 ::boost::bimaps::detail::
170 set_view_iterator<BOOST_DEDUCED_TYPENAME Index:: iterator>,
171 ::boost::bimaps::detail::
172 const_set_view_iterator<BOOST_DEDUCED_TYPENAME Index::const_iterator>
176 typedef BOOST_DEDUCED_TYPENAME Index::value_type::left_value_type left_type_;
178 typedef BOOST_DEDUCED_TYPENAME Index::value_type::right_value_type right_type_;
180 typedef BOOST_DEDUCED_TYPENAME Index::value_type value_type_;
182 typedef ::boost::bimaps::detail::
183 set_view_iterator<BOOST_DEDUCED_TYPENAME Index::iterator> iterator_;
187 bool replace(iterator_ position,
188 const value_type_ & x)
190 return derived().base().replace(
191 derived().template functor<iterator_to_base_>()(position),x
195 template< class CompatibleLeftType >
196 bool replace_left(iterator_ position,
197 const CompatibleLeftType & l)
199 return derived().base().replace(
200 derived().template functor<iterator_to_base_>()(position),
201 value_type_(l,position->right)
205 template< class CompatibleRightType >
206 bool replace_right(iterator_ position,
207 const CompatibleRightType & r)
209 return derived().base().replace(
210 derived().template functor<iterator_to_base_>()(position),
211 value_type_(position->left,r)
215 /* This function may be provided in the future
217 template< class Modifier >
218 bool modify(iterator_ position,
221 return derived().base().modify(
223 derived().template functor<iterator_to_base_>()(position),
225 ::boost::bimaps::detail::relation_modifier_adaptor
228 BOOST_DEDUCED_TYPENAME Index::value_type,
229 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
232 ::boost::bimaps::relation::member_at::left,
233 BOOST_DEDUCED_TYPENAME Index::value_type
236 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
239 ::boost::bimaps::relation::member_at::right,
240 BOOST_DEDUCED_TYPENAME Index::value_type
249 template< class Modifier >
250 bool modify_left(iterator_ position, Modifier mod)
252 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
255 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
256 BOOST_DEDUCED_TYPENAME Index::value_type
258 >::type left_data_extractor_;
260 return derived().base().modify(
262 derived().template functor<iterator_to_base_>()(position),
264 // this may be replaced later by
265 // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
267 ::boost::bimaps::detail::unary_modifier_adaptor
270 BOOST_DEDUCED_TYPENAME Index::value_type,
277 template< class Modifier >
278 bool modify_right(iterator_ position, Modifier mod)
280 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
283 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
284 BOOST_DEDUCED_TYPENAME Index::value_type
286 >::type right_data_extractor_;
288 return derived().base().modify(
290 derived().template functor<iterator_to_base_>()(position),
292 // this may be replaced later by
293 // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
295 ::boost::bimaps::detail::unary_modifier_adaptor
298 BOOST_DEDUCED_TYPENAME Index::value_type,
299 right_data_extractor_
307 typedef set_view_base set_view_base_;
311 // Curiously Recurring Template interface.
315 return *static_cast<Derived*>(this);
318 Derived const& derived() const
320 return *static_cast<Derived const*>(this);
326 } // namespace detail
327 } // namespace bimaps
330 #endif // BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP