Add SCons configure checks
[senf.git] / boost_ext / boost / bimap / detail / set_view_base.hpp
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 detail/set_view_base.hpp
10 /// \brief Helper base for the construction of the bimap views types.
11
12 #ifndef BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
13 #define BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
14
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
16 #pragma once
17 #endif
18
19 #include <boost/config.hpp>
20
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
29 namespace boost {
30 namespace bimaps {
31 namespace detail {
32
33 template< class Key, class Value, class KeyToBase >
34 class set_view_key_to_base
35 {
36     public:
37     const Key operator()( const Value & v ) const
38     {
39         return keyToBase( v );
40     }
41     private:
42     KeyToBase keyToBase;
43 };
44
45 template< class MutantRelationStorage, class KeyToBase >
46 class set_view_key_to_base<MutantRelationStorage,MutantRelationStorage,KeyToBase>
47 {
48         typedef BOOST_DEDUCED_TYPENAME MutantRelationStorage::non_mutable_storage non_mutable_storage;
49     public:
50     const MutantRelationStorage & operator()( const non_mutable_storage & k ) const
51     {
52         return ::boost::bimaps::relation::detail::mutate<MutantRelationStorage>(k);
53     }
54     const MutantRelationStorage & operator()( const MutantRelationStorage & k ) const
55     {
56         return k;
57     }
58 };
59
60
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               \
65 )                                                                             \
66 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR                         \
67 <                                                                             \
68     CORE_INDEX,                                                               \
69     ::boost::bimaps::detail::                                                 \
70               set_view_iterator<                                              \
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::                                                 \
76               set_view_iterator<                                              \
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      \
82     <                                                                         \
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>                \
87                                                                               \
88     >,                                                                        \
89     ::boost::mpl::na,                                                         \
90     ::boost::mpl::na,                                                         \
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                     \
101     >                                                                         \
102 >
103 /*===========================================================================*/
104
105
106 /*===========================================================================*/
107 #define BOOST_BIMAP_SEQUENCED_SET_VIEW_CONTAINER_ADAPTOR(                     \
108     CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER               \
109 )                                                                             \
110 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR                         \
111 <                                                                             \
112     CORE_INDEX,                                                               \
113     ::boost::bimaps::detail::                                                 \
114               set_view_iterator<                                              \
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::                                                 \
120               set_view_iterator<                                              \
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      \
126     <                                                                         \
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>                \
131                                                                               \
132     >,                                                                        \
133     ::boost::mpl::na,                                                         \
134     ::boost::mpl::na,                                                         \
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 >                   \
141 >
142 /*===========================================================================*/
143
144
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 /*===========================================================================*/
152 #else
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 /*===========================================================================*/
158 #endif
159
160
161 /// \brief Common base for set views.
162
163 template< class Derived, class Index >
164 class set_view_base
165 {
166     typedef ::boost::bimaps::container_adaptor::support::
167     iterator_facade_to_base
168     <
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>
173
174     > iterator_to_base_;
175
176     typedef BOOST_DEDUCED_TYPENAME Index::value_type::left_value_type          left_type_;
177
178     typedef BOOST_DEDUCED_TYPENAME Index::value_type::right_value_type        right_type_;
179
180     typedef BOOST_DEDUCED_TYPENAME Index::value_type                          value_type_;
181
182     typedef ::boost::bimaps::detail::
183                     set_view_iterator<BOOST_DEDUCED_TYPENAME Index::iterator>   iterator_;
184
185     public:
186
187     bool replace(iterator_ position,
188                  const value_type_ & x)
189     {
190         return derived().base().replace(
191             derived().template functor<iterator_to_base_>()(position),x
192         );
193     }
194
195     template< class CompatibleLeftType >
196     bool replace_left(iterator_ position,
197                       const CompatibleLeftType & l)
198     {
199         return derived().base().replace(
200             derived().template functor<iterator_to_base_>()(position),
201             value_type_(l,position->right)
202         );
203     }
204
205     template< class CompatibleRightType >
206     bool replace_right(iterator_ position,
207                        const CompatibleRightType & r)
208     {
209         return derived().base().replace(
210             derived().template functor<iterator_to_base_>()(position),
211             value_type_(position->left,r)
212         );
213     }
214
215     /* This function may be provided in the future
216
217     template< class Modifier >
218     bool modify(iterator_ position,
219                 Modifier mod)
220     {
221         return derived().base().modify(
222
223             derived().template functor<iterator_to_base_>()(position),
224
225             ::boost::bimaps::detail::relation_modifier_adaptor
226             <
227                 Modifier,
228                 BOOST_DEDUCED_TYPENAME Index::value_type,
229                 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
230                 data_extractor
231                 <
232                     ::boost::bimaps::relation::member_at::left,
233                     BOOST_DEDUCED_TYPENAME Index::value_type
234
235                 >::type,
236                 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
237                 data_extractor
238                 <
239                     ::boost::bimaps::relation::member_at::right,
240                     BOOST_DEDUCED_TYPENAME Index::value_type
241
242                 >::type
243
244             >(mod)
245         );
246     }
247     */
248     /*
249     template< class Modifier >
250     bool modify_left(iterator_ position, Modifier mod)
251     {
252         typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
253         data_extractor
254         <
255             BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
256             BOOST_DEDUCED_TYPENAME Index::value_type
257
258         >::type left_data_extractor_;
259
260         return derived().base().modify(
261
262             derived().template functor<iterator_to_base_>()(position),
263
264             // this may be replaced later by
265             // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
266
267             ::boost::bimaps::detail::unary_modifier_adaptor
268             <
269                 Modifier,
270                 BOOST_DEDUCED_TYPENAME Index::value_type,
271                 left_data_extractor_
272
273             >(mod)
274         );
275     }
276
277     template< class Modifier >
278     bool modify_right(iterator_ position, Modifier mod)
279     {
280         typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
281         data_extractor
282         <
283             BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
284             BOOST_DEDUCED_TYPENAME Index::value_type
285
286         >::type right_data_extractor_;
287
288         return derived().base().modify(
289
290             derived().template functor<iterator_to_base_>()(position),
291
292             // this may be replaced later by
293             // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
294
295             ::boost::bimaps::detail::unary_modifier_adaptor
296             <
297                 Modifier,
298                 BOOST_DEDUCED_TYPENAME Index::value_type,
299                 right_data_extractor_
300
301             >(mod)
302         );
303     }
304     */
305     protected:
306
307     typedef set_view_base set_view_base_;
308
309     private:
310
311     // Curiously Recurring Template interface.
312
313     Derived& derived()
314     {
315         return *static_cast<Derived*>(this);
316     }
317
318     Derived const& derived() const
319     {
320         return *static_cast<Derived const*>(this);
321     }
322 };
323
324
325
326 } // namespace detail
327 } // namespace bimaps
328 } // namespace boost
329
330 #endif // BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP