list_map_view.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. /// \file views/list_map_view.hpp
  9. /// \brief View of a side of a bimap.
  10. #ifndef BOOST_BIMAP_VIEWS_LIST_MAP_VIEW_HPP
  11. #define BOOST_BIMAP_VIEWS_LIST_MAP_VIEW_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/container_adaptor/list_map_adaptor.hpp>
  17. #include <boost/bimap/relation/support/pair_by.hpp>
  18. #include <boost/bimap/support/iterator_type_by.hpp>
  19. #include <boost/bimap/detail/map_view_base.hpp>
  20. #include <boost/bimap/relation/support/data_extractor.hpp>
  21. #include <boost/bimap/relation/detail/to_mutable_relation_functor.hpp>
  22. namespace boost {
  23. namespace bimaps {
  24. namespace views {
  25. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  26. template< class Tag, class BimapType >
  27. struct list_map_view_base
  28. {
  29. typedef ::boost::bimaps::container_adaptor::list_map_adaptor
  30. <
  31. BOOST_DEDUCED_TYPENAME BimapType::core_type::
  32. BOOST_NESTED_TEMPLATE index<Tag>::type,
  33. ::boost::bimaps::detail:: map_view_iterator<Tag,BimapType>,
  34. ::boost::bimaps::detail:: const_map_view_iterator<Tag,BimapType>,
  35. ::boost::bimaps::detail:: reverse_map_view_iterator<Tag,BimapType>,
  36. ::boost::bimaps::detail::const_reverse_map_view_iterator<Tag,BimapType>,
  37. ::boost::bimaps::container_adaptor::support::iterator_facade_to_base
  38. <
  39. ::boost::bimaps::detail:: map_view_iterator<Tag,BimapType>,
  40. ::boost::bimaps::detail::const_map_view_iterator<Tag,BimapType>
  41. >,
  42. ::boost::mpl::na,
  43. ::boost::mpl::na,
  44. ::boost::bimaps::relation::detail::
  45. pair_to_relation_functor<Tag, BOOST_DEDUCED_TYPENAME BimapType::relation >,
  46. ::boost::bimaps::relation::support::
  47. get_pair_functor<Tag, BOOST_DEDUCED_TYPENAME BimapType::relation >,
  48. BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::data_extractor
  49. <
  50. Tag,
  51. BOOST_DEDUCED_TYPENAME BimapType::relation
  52. >::type
  53. > type;
  54. };
  55. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  56. /// \brief View of a side of a bimap.
  57. /**
  58. This class uses container_adaptor and iterator_adaptor to wrapped a index of the
  59. multi_index bimap core.
  60. See also const_list_map_view.
  61. **/
  62. template< class Tag, class BimapType >
  63. class list_map_view
  64. :
  65. public list_map_view_base<Tag,BimapType>::type,
  66. public ::boost::bimaps::detail::
  67. map_view_base< list_map_view<Tag,BimapType>,Tag,BimapType >
  68. {
  69. typedef BOOST_DEDUCED_TYPENAME list_map_view_base<Tag,BimapType>::type base_;
  70. BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(list_map_view,Tag,BimapType)
  71. public:
  72. typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type;
  73. list_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c) :
  74. base_(c) {}
  75. list_map_view & operator=(const list_map_view & v)
  76. {
  77. this->base() = v.base();
  78. return *this;
  79. }
  80. BOOST_BIMAP_VIEW_ASSIGN_IMPLEMENTATION(base_)
  81. BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(base_)
  82. // Rearrange Operations
  83. void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position,
  84. BOOST_DEDUCED_TYPENAME base_::iterator i)
  85. {
  86. this->base().relocate(
  87. this->template functor<
  88. BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position),
  89. this->template functor<
  90. BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(i)
  91. );
  92. }
  93. void relocate(BOOST_DEDUCED_TYPENAME base_::iterator position,
  94. BOOST_DEDUCED_TYPENAME base_::iterator first,
  95. BOOST_DEDUCED_TYPENAME base_::iterator last)
  96. {
  97. this->base().relocate(
  98. this->template functor<
  99. BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position),
  100. this->template functor<
  101. BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(first),
  102. this->template functor<
  103. BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(last)
  104. );
  105. }
  106. };
  107. } // namespace views
  108. /*===========================================================================*/
  109. #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,TYPENAME) \
  110. typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \
  111. BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME));
  112. /*===========================================================================*/
  113. /*===========================================================================*/
  114. #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \
  115. BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,reverse_iterator) \
  116. BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_reverse_iterator) \
  117. /*===========================================================================*/
  118. namespace detail {
  119. template< class Tag, class BimapType >
  120. struct left_map_view_extra_typedefs< ::boost::bimaps::views::list_map_view<Tag,BimapType> >
  121. {
  122. private: typedef ::boost::bimaps::views::list_map_view<Tag,BimapType> map_view_;
  123. public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,left)
  124. };
  125. template< class Tag, class BimapType >
  126. struct right_map_view_extra_typedefs< ::boost::bimaps::views::list_map_view<Tag,BimapType> >
  127. {
  128. private: typedef ::boost::bimaps::views::list_map_view<Tag,BimapType> map_view_;
  129. public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,right)
  130. };
  131. } // namespace detail
  132. /*===========================================================================*/
  133. #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF
  134. #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY
  135. /*===========================================================================*/
  136. } // namespace bimaps
  137. } // namespace boost
  138. #endif // BOOST_BIMAP_VIEWS_LIST_MAP_VIEW_HPP