Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:09

0001 // Boost.Bimap
0002 //
0003 // Copyright (c) 2006-2007 Matias Capeletto
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 /// \file detail/set_view_base.hpp
0010 /// \brief Helper base for the construction of the bimap views types.
0011 
0012 #ifndef BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
0013 #define BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #include <boost/bimap/relation/member_at.hpp>
0022 #include <boost/bimap/relation/support/data_extractor.hpp>
0023 #include <boost/bimap/detail/modifier_adaptor.hpp>
0024 #include <boost/bimap/detail/set_view_iterator.hpp>
0025 #include <boost/bimap/relation/support/get_pair_functor.hpp>
0026 #include <boost/bimap/relation/detail/to_mutable_relation_functor.hpp>
0027 #include <boost/bimap/relation/mutant_relation.hpp>
0028 #include <boost/bimap/container_adaptor/support/iterator_facade_converters.hpp>
0029 
0030 namespace boost {
0031 namespace bimaps {
0032 namespace detail {
0033 
0034 template< class Key, class Value, class KeyToBase >
0035 class set_view_key_to_base
0036 {
0037     public:
0038     const Key operator()( const Value & v ) const
0039     {
0040         return keyToBase( v );
0041     }
0042     private:
0043     KeyToBase keyToBase;
0044 };
0045 
0046 template< class MutantRelationStorage, class KeyToBase >
0047 class set_view_key_to_base<MutantRelationStorage,MutantRelationStorage,KeyToBase>
0048 {
0049     typedef BOOST_DEDUCED_TYPENAME MutantRelationStorage::non_mutable_storage non_mutable_storage;
0050     public:
0051     const MutantRelationStorage & operator()( const non_mutable_storage & k ) const
0052     {
0053         return ::boost::bimaps::relation::detail::mutate<MutantRelationStorage>(k);
0054     }
0055     const MutantRelationStorage & operator()( const MutantRelationStorage & k ) const
0056     {
0057         return k;
0058     }
0059 };
0060 
0061 
0062 // The next macro can be converted in a metafunctor to gain code robustness.
0063 /*===========================================================================*/
0064 #define BOOST_BIMAP_SET_VIEW_CONTAINER_ADAPTOR(                               \
0065     CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER               \
0066 )                                                                             \
0067 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR                         \
0068 <                                                                             \
0069     CORE_INDEX,                                                               \
0070     ::boost::bimaps::detail::                                                 \
0071               set_view_iterator<                                              \
0072                     BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator         >,    \
0073     ::boost::bimaps::detail::                                                 \
0074         const_set_view_iterator<                                              \
0075                     BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator   >,    \
0076     ::boost::bimaps::detail::                                                 \
0077               set_view_iterator<                                              \
0078                     BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER       >,    \
0079     ::boost::bimaps::detail::                                                 \
0080         const_set_view_iterator<                                              \
0081                     BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >,    \
0082     ::boost::bimaps::container_adaptor::support::iterator_facade_to_base      \
0083     <                                                                         \
0084         ::boost::bimaps::detail::      set_view_iterator<                     \
0085             BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>,                     \
0086         ::boost::bimaps::detail::const_set_view_iterator<                     \
0087             BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator>                \
0088                                                                               \
0089     >,                                                                        \
0090     ::boost::mpl::na,                                                         \
0091     ::boost::mpl::na,                                                         \
0092     ::boost::bimaps::relation::detail::                                       \
0093         get_mutable_relation_functor<                                         \
0094             BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >,                  \
0095     ::boost::bimaps::relation::support::                                      \
0096         get_above_view_functor<                                               \
0097             BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >,                  \
0098     ::boost::bimaps::detail::set_view_key_to_base<                            \
0099         BOOST_DEDUCED_TYPENAME CORE_INDEX::key_type,                          \
0100         BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type,                        \
0101         BOOST_DEDUCED_TYPENAME CORE_INDEX::key_from_value                     \
0102     >                                                                         \
0103 >
0104 /*===========================================================================*/
0105 
0106 
0107 /*===========================================================================*/
0108 #define BOOST_BIMAP_SEQUENCED_SET_VIEW_CONTAINER_ADAPTOR(                     \
0109     CONTAINER_ADAPTOR, CORE_INDEX, OTHER_ITER, CONST_OTHER_ITER               \
0110 )                                                                             \
0111 ::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR                         \
0112 <                                                                             \
0113     CORE_INDEX,                                                               \
0114     ::boost::bimaps::detail::                                                 \
0115               set_view_iterator<                                              \
0116                     BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator         >,    \
0117     ::boost::bimaps::detail::                                                 \
0118         const_set_view_iterator<                                              \
0119                     BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator   >,    \
0120     ::boost::bimaps::detail::                                                 \
0121               set_view_iterator<                                              \
0122                     BOOST_DEDUCED_TYPENAME CORE_INDEX::OTHER_ITER       >,    \
0123     ::boost::bimaps::detail::                                                 \
0124         const_set_view_iterator<                                              \
0125                     BOOST_DEDUCED_TYPENAME CORE_INDEX::CONST_OTHER_ITER >,    \
0126     ::boost::bimaps::container_adaptor::support::iterator_facade_to_base      \
0127     <                                                                         \
0128         ::boost::bimaps::detail::      set_view_iterator<                     \
0129             BOOST_DEDUCED_TYPENAME CORE_INDEX::iterator>,                     \
0130         ::boost::bimaps::detail::const_set_view_iterator<                     \
0131             BOOST_DEDUCED_TYPENAME CORE_INDEX::const_iterator>                \
0132                                                                               \
0133     >,                                                                        \
0134     ::boost::mpl::na,                                                         \
0135     ::boost::mpl::na,                                                         \
0136     ::boost::bimaps::relation::detail::                                       \
0137         get_mutable_relation_functor<                                         \
0138             BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >,                  \
0139     ::boost::bimaps::relation::support::                                      \
0140         get_above_view_functor<                                               \
0141             BOOST_DEDUCED_TYPENAME CORE_INDEX::value_type >                   \
0142 >
0143 /*===========================================================================*/
0144 
0145 
0146 #if defined(BOOST_MSVC)
0147 /*===========================================================================*/
0148 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE)                     \
0149     typedef ::boost::bimaps::detail::set_view_base<                           \
0150         TYPE< INDEX_TYPE >, INDEX_TYPE > template_class_friend;               \
0151     friend class template_class_friend;
0152 /*===========================================================================*/
0153 #else
0154 /*===========================================================================*/
0155 #define BOOST_BIMAP_SET_VIEW_BASE_FRIEND(TYPE,INDEX_TYPE)                     \
0156     friend class ::boost::bimaps::detail::set_view_base<                      \
0157         TYPE< INDEX_TYPE >, INDEX_TYPE >;
0158 /*===========================================================================*/
0159 #endif
0160 
0161 
0162 /// \brief Common base for set views.
0163 
0164 template< class Derived, class Index >
0165 class set_view_base
0166 {
0167     typedef ::boost::bimaps::container_adaptor::support::
0168     iterator_facade_to_base
0169     <
0170         ::boost::bimaps::detail::
0171                   set_view_iterator<BOOST_DEDUCED_TYPENAME Index::      iterator>,
0172         ::boost::bimaps::detail::
0173             const_set_view_iterator<BOOST_DEDUCED_TYPENAME Index::const_iterator>
0174 
0175     > iterator_to_base_;
0176 
0177     typedef BOOST_DEDUCED_TYPENAME Index::value_type::left_value_type          left_type_;
0178 
0179     typedef BOOST_DEDUCED_TYPENAME Index::value_type::right_value_type        right_type_;
0180 
0181     typedef BOOST_DEDUCED_TYPENAME Index::value_type                          value_type_;
0182 
0183     typedef ::boost::bimaps::detail::
0184                     set_view_iterator<BOOST_DEDUCED_TYPENAME Index::iterator>   iterator_;
0185 
0186     public:
0187 
0188     bool replace(iterator_ position,
0189                  const value_type_ & x)
0190     {
0191         return derived().base().replace(
0192             derived().template functor<iterator_to_base_>()(position),x
0193         );
0194     }
0195 
0196     template< class CompatibleLeftType >
0197     bool replace_left(iterator_ position,
0198                       const CompatibleLeftType & l)
0199     {
0200         return derived().base().replace(
0201             derived().template functor<iterator_to_base_>()(position),
0202             ::boost::bimaps::relation::detail::copy_with_left_replaced(*position,l)
0203         );
0204     }
0205 
0206     template< class CompatibleRightType >
0207     bool replace_right(iterator_ position,
0208                        const CompatibleRightType & r)
0209     {
0210         return derived().base().replace(
0211             derived().template functor<iterator_to_base_>()(position),
0212             ::boost::bimaps::relation::detail::copy_with_right_replaced(*position,r)
0213         );
0214     }
0215 
0216     /* This function may be provided in the future
0217 
0218     template< class Modifier >
0219     bool modify(iterator_ position,
0220                 Modifier mod)
0221     {
0222         return derived().base().modify(
0223 
0224             derived().template functor<iterator_to_base_>()(position),
0225 
0226             ::boost::bimaps::detail::relation_modifier_adaptor
0227             <
0228                 Modifier,
0229                 BOOST_DEDUCED_TYPENAME Index::value_type,
0230                 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0231                 data_extractor
0232                 <
0233                     ::boost::bimaps::relation::member_at::left,
0234                     BOOST_DEDUCED_TYPENAME Index::value_type
0235 
0236                 >::type,
0237                 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0238                 data_extractor
0239                 <
0240                     ::boost::bimaps::relation::member_at::right,
0241                     BOOST_DEDUCED_TYPENAME Index::value_type
0242 
0243                 >::type
0244 
0245             >(mod)
0246         );
0247     }
0248     */
0249     /*
0250     template< class Modifier >
0251     bool modify_left(iterator_ position, Modifier mod)
0252     {
0253         typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0254         data_extractor
0255         <
0256             BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
0257             BOOST_DEDUCED_TYPENAME Index::value_type
0258 
0259         >::type left_data_extractor_;
0260 
0261         return derived().base().modify(
0262 
0263             derived().template functor<iterator_to_base_>()(position),
0264 
0265             // this may be replaced later by
0266             // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
0267 
0268             ::boost::bimaps::detail::unary_modifier_adaptor
0269             <
0270                 Modifier,
0271                 BOOST_DEDUCED_TYPENAME Index::value_type,
0272                 left_data_extractor_
0273 
0274             >(mod)
0275         );
0276     }
0277 
0278     template< class Modifier >
0279     bool modify_right(iterator_ position, Modifier mod)
0280     {
0281         typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0282         data_extractor
0283         <
0284             BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::member_at::right,
0285             BOOST_DEDUCED_TYPENAME Index::value_type
0286 
0287         >::type right_data_extractor_;
0288 
0289         return derived().base().modify(
0290 
0291             derived().template functor<iterator_to_base_>()(position),
0292 
0293             // this may be replaced later by
0294             // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )
0295 
0296             ::boost::bimaps::detail::unary_modifier_adaptor
0297             <
0298                 Modifier,
0299                 BOOST_DEDUCED_TYPENAME Index::value_type,
0300                 right_data_extractor_
0301 
0302             >(mod)
0303         );
0304     }
0305     */
0306     protected:
0307 
0308     typedef set_view_base set_view_base_;
0309 
0310     private:
0311 
0312     // Curiously Recurring Template interface.
0313 
0314     Derived& derived()
0315     {
0316         return *static_cast<Derived*>(this);
0317     }
0318 
0319     Derived const& derived() const
0320     {
0321         return *static_cast<Derived const*>(this);
0322     }
0323 };
0324 
0325 
0326 
0327 } // namespace detail
0328 } // namespace bimaps
0329 } // namespace boost
0330 
0331 #endif // BOOST_BIMAP_DETAIL_SET_VIEW_BASE_HPP