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/bimap_core.hpp
10 /// \brief Bimap base definition.
12 #ifndef BOOST_BIMAP_DETAIL_BIMAP_CORE_HPP
13 #define BOOST_BIMAP_DETAIL_BIMAP_CORE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #include <boost/mpl/placeholders.hpp>
22 #include <boost/mpl/push_front.hpp>
23 #include <boost/mpl/if.hpp>
24 #include <boost/mpl/and.hpp>
25 #include <boost/mpl/not.hpp>
26 #include <boost/mpl/vector.hpp>
28 #include <boost/type_traits/add_const.hpp>
29 #include <boost/type_traits/is_same.hpp>
31 #include <boost/concept_check.hpp>
34 #include <boost/multi_index_container.hpp>
35 #include <boost/multi_index/member.hpp>
38 #include <boost/bimap/relation/mutant_relation.hpp>
39 #include <boost/bimap/relation/member_at.hpp>
40 #include <boost/bimap/relation/support/data_extractor.hpp>
41 #include <boost/bimap/tags/support/default_tagged.hpp>
42 #include <boost/bimap/tags/tagged.hpp>
43 #include <boost/bimap/detail/manage_bimap_key.hpp>
44 #include <boost/bimap/detail/manage_additional_parameters.hpp>
45 #include <boost/bimap/detail/map_view_iterator.hpp>
46 #include <boost/bimap/detail/set_view_iterator.hpp>
48 #include <boost/bimap/set_of.hpp>
49 #include <boost/bimap/unconstrained_set_of.hpp>
54 /// \brief Library details
58 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
60 template< class Type >
63 typedef BOOST_DEDUCED_TYPENAME Type::value_type type;
66 struct independent_index_tag {};
68 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
71 /// \brief Base for the bimap class.
79 template< class LeftSetType, class RightSetType, class AP1, class AP2, class AP3 >
82 // Manage bimap key instantiation
83 // --------------------------------------------------------------------
86 typedef BOOST_DEDUCED_TYPENAME manage_bimap_key
90 >::type left_set_type;
92 typedef BOOST_DEDUCED_TYPENAME manage_bimap_key
96 >::type right_set_type;
101 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::default_tagged
103 BOOST_DEDUCED_TYPENAME left_set_type::user_type,
104 ::boost::bimaps::relation::member_at::left
106 >::type left_tagged_type;
108 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::default_tagged
110 BOOST_DEDUCED_TYPENAME right_set_type::user_type,
111 ::boost::bimaps::relation::member_at::right
113 >::type right_tagged_type;
119 typedef BOOST_DEDUCED_TYPENAME left_tagged_type::tag left_tag;
120 typedef BOOST_DEDUCED_TYPENAME right_tagged_type::tag right_tag;
126 typedef BOOST_DEDUCED_TYPENAME left_set_type::value_type left_key_type;
127 typedef BOOST_DEDUCED_TYPENAME right_set_type::value_type right_key_type;
133 typedef right_key_type left_data_type;
134 typedef left_key_type right_data_type;
138 // Manage the additional parameters
139 // --------------------------------------------------------------------
142 typedef BOOST_DEDUCED_TYPENAME manage_additional_parameters<AP1,AP2,AP3>::type parameters;
144 /// \brief Relation type stored by the bimap.
145 // --------------------------------------------------------------------
148 typedef ::boost::bimaps::relation::mutant_relation
151 ::boost::bimaps::tags::tagged<
152 BOOST_DEDUCED_TYPENAME mpl::if_<
155 BOOST_DEDUCED_TYPENAME left_set_type::mutable_key,
156 BOOST_DEDUCED_TYPENAME parameters::set_type_of_relation::left_mutable_key
163 BOOST_DEDUCED_TYPENAME ::boost::add_const< left_key_type >::type
170 ::boost::bimaps::tags::tagged<
171 BOOST_DEDUCED_TYPENAME mpl::if_<
174 BOOST_DEDUCED_TYPENAME right_set_type::mutable_key,
175 BOOST_DEDUCED_TYPENAME parameters::set_type_of_relation::right_mutable_key
182 BOOST_DEDUCED_TYPENAME ::boost::add_const< right_key_type >::type
189 // It is ::boost::mpl::na if no info_hook was included
190 BOOST_DEDUCED_TYPENAME parameters::additional_info,
192 // Force mutable keys
199 typedef BOOST_DEDUCED_TYPENAME relation::left_pair left_value_type;
200 typedef BOOST_DEDUCED_TYPENAME relation::right_pair right_value_type;
204 // Bind the member of the relation, so multi_index can manage them
205 // --------------------------------------------------------------------
208 typedef BOOST_DEDUCED_TYPENAME relation::storage_base relation_storage_base;
210 typedef BOOST_MULTI_INDEX_MEMBER(relation_storage_base, left_key_type, left)
211 left_member_extractor;
213 typedef BOOST_MULTI_INDEX_MEMBER(relation_storage_base,right_key_type,right)
214 right_member_extractor;
216 // The core indices are somewhat complicated to calculate, because they
217 // can be zero, one, two or three indices, depending on the use of
218 // {side}_based set type of relations and unconstrained_set_of and
219 // unconstrained_set_of_relation specifications.
221 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
222 ::boost::bimaps::detail::is_unconstrained_set_of< left_set_type >,
230 BOOST_DEDUCED_TYPENAME left_set_type::
231 BOOST_NESTED_TEMPLATE index_bind
233 left_member_extractor,
239 >::type left_core_indices;
241 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
242 ::boost::bimaps::detail::is_unconstrained_set_of< right_set_type >,
248 BOOST_DEDUCED_TYPENAME mpl::push_front
252 BOOST_DEDUCED_TYPENAME right_set_type::
253 BOOST_NESTED_TEMPLATE index_bind
255 right_member_extractor,
262 >::type basic_core_indices;
264 // If it is based either on the left or on the right, then only the side
265 // indices are needed. But the set type of the relation can be completely
266 // diferent from the one used for the sides in wich case we have to add yet
267 // another index to the core.
270 // If all the set types are unsconstrained there must be readable compile
273 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
275 is_same< BOOST_DEDUCED_TYPENAME parameters::set_type_of_relation, left_based >,
277 ::boost::bimaps::tags::tagged< left_set_type, left_tag >,
279 /* else */ BOOST_DEDUCED_TYPENAME mpl::if_<
280 is_same< BOOST_DEDUCED_TYPENAME parameters::set_type_of_relation, right_based >,
282 ::boost::bimaps::tags::tagged< right_set_type, right_tag >,
288 BOOST_DEDUCED_TYPENAME parameters::
289 set_type_of_relation::BOOST_NESTED_TEMPLATE bind_to
294 independent_index_tag
298 >::type tagged_set_of_relation_type;
302 typedef BOOST_DEDUCED_TYPENAME tagged_set_of_relation_type::tag
305 typedef BOOST_DEDUCED_TYPENAME tagged_set_of_relation_type::value_type
306 relation_set_type_of;
309 // This is a necesary extra level of indirection to allow unconstrained
310 // sets to be plug in the design. The bimap constructors use this logic
313 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
314 ::boost::bimaps::detail::is_unconstrained_set_of< left_set_type >,
316 BOOST_DEDUCED_TYPENAME mpl::if_<
317 ::boost::bimaps::detail::is_unconstrained_set_of< right_set_type >,
319 independent_index_tag,
326 >::type logic_left_tag;
328 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
329 ::boost::bimaps::detail::is_unconstrained_set_of< right_set_type >,
331 BOOST_DEDUCED_TYPENAME mpl::if_<
332 ::boost::bimaps::detail::is_unconstrained_set_of< left_set_type >,
334 independent_index_tag,
341 >::type logic_right_tag;
343 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
344 is_same< relation_set_tag, independent_index_tag >,
346 BOOST_DEDUCED_TYPENAME mpl::if_<
347 ::boost::bimaps::detail::
348 is_unconstrained_set_of< relation_set_type_of >,
351 independent_index_tag
355 BOOST_DEDUCED_TYPENAME mpl::if_<
356 is_same< BOOST_DEDUCED_TYPENAME parameters::set_type_of_relation, left_based >,
363 >::type logic_relation_set_tag;
367 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
368 mpl::and_< is_same< relation_set_tag, independent_index_tag >,
370 ::boost::bimaps::detail::
371 is_unconstrained_set_of< relation_set_type_of >
375 BOOST_DEDUCED_TYPENAME mpl::push_front
379 BOOST_DEDUCED_TYPENAME relation_set_type_of::
380 BOOST_NESTED_TEMPLATE index_bind
382 ::boost::bimaps::relation::support::both_keys_extractor<relation>,
383 independent_index_tag
394 >::type complete_core_indices;
396 struct core_indices : public complete_core_indices {};
398 // Define the core using compute_index_type to translate the
399 // set type to an multi-index specification
400 // --------------------------------------------------------------------
403 typedef multi_index::multi_index_container
407 BOOST_DEDUCED_TYPENAME parameters::allocator::
408 BOOST_NESTED_TEMPLATE rebind<relation>::other
413 // --------------------------------------------------------------------
416 typedef BOOST_DEDUCED_TYPENAME ::boost::multi_index::
417 index<core_type, logic_left_tag>::type left_index;
419 typedef BOOST_DEDUCED_TYPENAME ::boost::multi_index::
420 index<core_type,logic_right_tag>::type right_index;
422 typedef BOOST_DEDUCED_TYPENAME left_index::iterator left_core_iterator;
423 typedef BOOST_DEDUCED_TYPENAME left_index::const_iterator left_core_const_iterator;
425 typedef BOOST_DEDUCED_TYPENAME right_index::iterator right_core_iterator;
426 typedef BOOST_DEDUCED_TYPENAME right_index::const_iterator right_core_const_iterator;
428 // Map by {side} iterator metadata
429 // --------------------------------------------------------------------
434 typedef ::boost::bimaps::detail::map_view_iterator
442 typedef ::boost::bimaps::detail::map_view_iterator
454 typedef ::boost::bimaps::detail::const_map_view_iterator
458 left_core_const_iterator
460 > left_const_iterator;
462 typedef ::boost::bimaps::detail::const_map_view_iterator
466 right_core_const_iterator
468 > right_const_iterator;
474 typedef BOOST_DEDUCED_TYPENAME ::boost::multi_index::index
476 core_type, logic_relation_set_tag
478 >::type relation_set_core_index;
480 typedef BOOST_DEDUCED_TYPENAME relation_set_type_of::
481 BOOST_NESTED_TEMPLATE set_view_bind
483 relation_set_core_index
485 >::type relation_set;
489 typedef bimap_core bimap_core_;
492 // Two auxiliar metafunctions to compute the map view types
493 // The map view type can not be computed inside the bimap core because a
494 // they need the bimap core to be parsed first.
496 template< class BimapBaseType >
497 struct left_map_view_type
499 typedef BOOST_DEDUCED_TYPENAME BimapBaseType::left_set_type left_set_type;
500 typedef BOOST_DEDUCED_TYPENAME
501 left_set_type::BOOST_NESTED_TEMPLATE map_view_bind<
502 BOOST_DEDUCED_TYPENAME BimapBaseType::left_tag, BimapBaseType
506 template< class BimapBaseType >
507 struct right_map_view_type
509 typedef BOOST_DEDUCED_TYPENAME BimapBaseType::right_set_type right_set_type;
510 typedef BOOST_DEDUCED_TYPENAME
511 right_set_type::BOOST_NESTED_TEMPLATE map_view_bind<
512 BOOST_DEDUCED_TYPENAME BimapBaseType::right_tag, BimapBaseType
516 } // namespace detail
517 } // namespace bimaps
520 #endif // BOOST_BIMAP_DETAIL_BIMAP_CORE_HPP