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)
10 /// \brief Includes the basic bimap container
14 \image html http://matias.capeletto.googlepages.com/boost.bimap.reference.logo.png
18 This is the complete reference of Boost.Bimap.
20 After getting a good understanding of the library from a user perspective
21 the next step will be:
23 - Understand the tagged idiom. (boost::bimaps::tags)
24 - Understand the internals of the relation class (boost::bimaps::relation)
25 - Read the container_adaptor toolbox docs (boost::bimaps::container_adaptor)
26 - Understand the internals of the bimap class. (boost::bimaps, boost::bimaps::views
27 and boost::bimaps::detail)
32 /** \defgroup mutant_group mutant idiom
33 \brief A safe wrapper around reinterpret_cast
36 /** \defgroup relation_group relation
40 /** \defgroup tags_group tagged idiom
41 \brief The tagged idiom
45 #ifndef BOOST_BIMAP_BIMAP_HPP
46 #define BOOST_BIMAP_BIMAP_HPP
48 #if defined(_MSC_VER) && (_MSC_VER>=1200)
52 #include <boost/config.hpp>
53 #include <boost/bimap/detail/user_interface_config.hpp>
54 #include <boost/mpl/aux_/na.hpp>
56 #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
57 #include <boost/serialization/nvp.hpp>
58 #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
61 #include <boost/bimap/detail/bimap_core.hpp>
62 #include <boost/bimap/detail/map_view_base.hpp>
63 #include <boost/bimap/detail/modifier_adaptor.hpp>
64 #include <boost/bimap/relation/support/data_extractor.hpp>
65 #include <boost/bimap/relation/support/member_with_tag.hpp>
67 #include <boost/bimap/support/map_type_by.hpp>
68 #include <boost/bimap/support/map_by.hpp>
69 #include <boost/bimap/support/iterator_type_by.hpp>
71 /// \brief The namespace where all the boost libraries lives.
75 /// \brief Boost.Bimap library namespace
77 All the entities in the library are defined in this namespace.
81 /// \brief The bimap class is the entry point to the library.
83 This class manages the instantiation of the desired bimap type.
84 As there are several types of bidirectional maps that can be
85 created using it. the main job of it is to find the desired
86 type. This is done using metaprogramming to obtain the relation
87 type that will be stored, the map_view type of each side and
88 the set_view type of the general relationship. The instantiation
89 is kept simple using an extended standard set theory, where a
90 bidirectional map type is defined by the set types it relates.
91 For example, a bidirectional map that has multimap semantics
92 viewed from both sides is defined by specifying that the two
93 keys sets are of \c multiset_of<Key> type.
94 This allows the bimap class to support seamingless N-N, 1-N,
95 ordered/unordered and even vector-list types of mapping.
96 The three last parameters are used to specify the set type of
97 the relation, an inplace hooked data class and the allocator
98 type. As a help to the bimap user, these parameters support
99 default types but use a special idiom that allow them to be
100 specified without interleaving the usual use_default keyword.
101 The possible bimap instantiation are enumerated here:
102 \c {Side}KeyType can be directly a type, this is default to
103 \c set_of<{Side}KeyType>, or can be a \c {SetType}_of<Type>
104 specification. Additionally this two parameters can be tagged
105 to specify others tags instead of the usual \c member_at::{Side}
113 LeftCollectionType, RightCollectionType
115 [ , SetTypeOfRelation ] // Default to left_based
116 [ , info_hook< Info > ] // Default to no info
117 [ , Allocator ] // Default to std::allocator<>
128 class KeyTypeA
, class KeyTypeB
,
129 class AP1
= ::boost::mpl::na
,
130 class AP2
= ::boost::mpl::na
,
131 class AP3
= ::boost::mpl::na
135 // Bimap Core, use mpl magic to find the desired bimap type
137 public ::boost::bimaps::detail::bimap_core
<KeyTypeA
,KeyTypeB
,AP1
,AP2
,AP3
>,
139 // You can use bimap as a collection of relations
141 public ::boost::bimaps::detail::bimap_core
<KeyTypeA
,KeyTypeB
,AP1
,AP2
,AP3
>
144 // Include extra typedefs (i.e. left_local_iterator for unordered_map)
146 public ::boost::bimaps::detail:: left_map_view_extra_typedefs
<
147 BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::left_map_view_type
<
148 ::boost::bimaps::detail::bimap_core
<KeyTypeA
,KeyTypeB
,AP1
,AP2
,AP3
>
151 public ::boost::bimaps::detail::right_map_view_extra_typedefs
<
152 BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::right_map_view_type
<
153 ::boost::bimaps::detail::bimap_core
<KeyTypeA
,KeyTypeB
,AP1
,AP2
,AP3
>
157 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
158 bimap_core
<KeyTypeA
,KeyTypeB
,AP1
,AP2
,AP3
> base_
;
160 BOOST_DEDUCED_TYPENAME
base_::core_type core
;
164 // metadata --------------------------------------------------------
167 // The rest is computed in the core, because it is quite difficult to
168 // expose a nice interface with so many metaprogramming stuff.
169 // Here it is the complete metadat list.
171 // Map by {side} metadata
173 typedef -unspecified- {side}_tag;
174 typedef -unspecified- {side}_data_type;
175 typedef -unspecified- {side}_value_type;
176 typedef -unspecified- {side}_key_type;
177 typedef -unspecified- {side}_iterator;
178 typedef -unspecified- {side}_const_iterator;
180 ------------------------------------------------------------------*/
182 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
183 left_map_view_type
<base_
>::type left_map
;
184 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
185 right_map_view_type
<base_
>::type right_map
;
187 typedef BOOST_DEDUCED_TYPENAME
188 left_map::reference left_reference
;
189 typedef BOOST_DEDUCED_TYPENAME
190 left_map::const_reference left_const_reference
;
192 typedef BOOST_DEDUCED_TYPENAME
193 right_map::reference right_reference
;
194 typedef BOOST_DEDUCED_TYPENAME
195 right_map::const_reference right_const_reference
;
197 typedef BOOST_DEDUCED_TYPENAME
base_::relation::info_type info_type
;
208 ::boost::multi_index::get
<
209 BOOST_DEDUCED_TYPENAME
base_::logic_relation_set_tag
213 ::boost::multi_index::get
<
214 BOOST_DEDUCED_TYPENAME
base_::logic_left_tag
218 ::boost::multi_index::get
<
219 BOOST_DEDUCED_TYPENAME
base_::logic_right_tag
225 template< class InputIterator
>
226 bimap(InputIterator first
,InputIterator last
) :
229 ::boost::multi_index::get
<
230 BOOST_DEDUCED_TYPENAME
base_::logic_relation_set_tag
237 ::boost::multi_index::get
<
238 BOOST_DEDUCED_TYPENAME
base_::logic_left_tag
242 ::boost::multi_index::get
<
243 BOOST_DEDUCED_TYPENAME
base_::logic_right_tag
249 bimap(const bimap
& x
) :
252 ::boost::multi_index::get
<
253 BOOST_DEDUCED_TYPENAME
base_::logic_relation_set_tag
260 ::boost::multi_index::get
<
261 BOOST_DEDUCED_TYPENAME
base_::logic_left_tag
265 ::boost::multi_index::get
<
266 BOOST_DEDUCED_TYPENAME
base_::logic_right_tag
272 bimap
& operator=(const bimap
& x
)
278 // Projection of iterators
280 template< class IteratorType
>
281 BOOST_DEDUCED_TYPENAME
base_::left_iterator
282 project_left(IteratorType iter
)
284 return core
.template project
<
285 BOOST_DEDUCED_TYPENAME
base_::logic_left_tag
>(iter
.base());
288 template< class IteratorType
>
289 BOOST_DEDUCED_TYPENAME
base_::left_const_iterator
290 project_left(IteratorType iter
) const
292 return core
.template project
<
293 BOOST_DEDUCED_TYPENAME
base_::logic_left_tag
>(iter
.base());
296 template< class IteratorType
>
297 BOOST_DEDUCED_TYPENAME
base_::right_iterator
298 project_right(IteratorType iter
)
300 return core
.template project
<
301 BOOST_DEDUCED_TYPENAME
base_::logic_right_tag
>(iter
.base());
304 template< class IteratorType
>
305 BOOST_DEDUCED_TYPENAME
base_::right_const_iterator
306 project_right(IteratorType iter
) const
308 return core
.template project
<
309 BOOST_DEDUCED_TYPENAME
base_::logic_right_tag
>(iter
.base());
312 template< class IteratorType
>
313 BOOST_DEDUCED_TYPENAME
base_::relation_set::iterator
314 project_up(IteratorType iter
)
316 return core
.template project
<
317 BOOST_DEDUCED_TYPENAME
base_::logic_relation_set_tag
>(iter
.base());
320 template< class IteratorType
>
321 BOOST_DEDUCED_TYPENAME
base_::relation_set::const_iterator
322 project_up(IteratorType iter
) const
324 return core
.template project
<
325 BOOST_DEDUCED_TYPENAME
base_::logic_relation_set_tag
>(iter
.base());
330 template< class Tag
, class IteratorType
>
331 BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::
332 iterator_type_by
<Tag
,bimap
>::type
333 project(IteratorType iter
334 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag
))
336 return core
.template project
<Tag
>(iter
.base());
339 template< class Tag
, class IteratorType
>
340 BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::
341 const_iterator_type_by
<Tag
,bimap
>::type
342 project(IteratorType iter
343 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag
)) const
345 return core
.template project
<Tag
>(iter
.base());
348 template< class Tag
>
350 public ::boost::bimaps::support::map_type_by
<Tag
,bimap
>::type
352 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::
353 map_type_by
<Tag
,bimap
>::type type
;
358 template< class Tag
>
359 BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::
360 map_type_by
<Tag
,bimap
>::type
&
361 by(BOOST_EXPLICIT_TEMPLATE_TYPE(Tag
))
363 return ::boost::bimaps::support::map_by
<Tag
>(*this);
366 template< class Tag
>
367 const BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::
368 map_type_by
<Tag
,bimap
>::type
&
369 by(BOOST_EXPLICIT_TEMPLATE_TYPE(Tag
)) const
371 return ::boost::bimaps::support::map_by
<Tag
>(*this);
375 #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
377 // Serialization support
381 friend class boost::serialization::access
;
383 template<class Archive
>
384 void serialize(Archive
& ar
, const unsigned int version
)
386 ar
& serialization::make_nvp("mi_core",core
);
389 #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
392 } // namespace bimaps
396 /** \namespace boost::bimaps::support
397 \brief Metafunctions to help working with bimaps.
400 /** \namespace boost::bimaps::views
404 /** \namespace boost::bimaps::views::detail
405 \brief Bimap views details.
410 // Include basic tools for user commodity
412 #include <boost/bimap/tags/tagged.hpp>
413 #include <boost/bimap/relation/member_at.hpp>
414 #include <boost/multi_index/detail/unbounded.hpp>
416 // Bring the most used namespaces directly to the user main namespace
420 using ::boost::bimaps::tags::tagged
;
422 namespace member_at
= ::boost::bimaps::relation::member_at
;
424 using ::boost::multi_index::unbounded
;
426 } // namespace bimaps
430 #endif // BOOST_BIMAP_BIMAP_HPP