Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:37

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 container_adaptor/associative_container_adaptor.hpp
0010 /// \brief Container adaptor to build a type that is compliant to the concept of an associative container.
0011 
0012 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP
0013 #define BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #include <utility>
0022 
0023 #include <boost/mpl/vector.hpp>
0024 #include <boost/mpl/if.hpp>
0025 #include <boost/mpl/aux_/na.hpp>
0026 #include <boost/bimap/container_adaptor/detail/identity_converters.hpp>
0027 #include <boost/bimap/container_adaptor/container_adaptor.hpp>
0028 #include <boost/call_traits.hpp>
0029 
0030 namespace boost {
0031 namespace bimaps {
0032 namespace container_adaptor {
0033 
0034 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
0035 
0036 template
0037 <
0038     class Base, class Iterator, class ConstIterator, class KeyType,
0039     class IteratorToBaseConverter, class IteratorFromBaseConverter,
0040     class ValueToBaseConverter, class ValueFromBaseConverter, class KeyToBaseConverter,
0041     class FunctorsFromDerivedClasses
0042 >
0043 struct associative_container_adaptor_base
0044 {
0045     typedef container_adaptor
0046     <
0047         Base,
0048 
0049         Iterator, ConstIterator,
0050 
0051         IteratorToBaseConverter, IteratorFromBaseConverter,
0052         ValueToBaseConverter   , ValueFromBaseConverter,
0053 
0054         BOOST_DEDUCED_TYPENAME mpl::push_front<
0055 
0056             FunctorsFromDerivedClasses,
0057 
0058             BOOST_DEDUCED_TYPENAME mpl::if_< ::boost::mpl::is_na<KeyToBaseConverter>,
0059             // {
0060                     detail::key_to_base_identity
0061                     <
0062                         BOOST_DEDUCED_TYPENAME Base::key_type, KeyType
0063                     >,
0064             // }
0065             // else
0066             // {
0067                     KeyToBaseConverter
0068             // }
0069 
0070             >::type
0071 
0072         >::type
0073 
0074     > type;
0075 };
0076 
0077 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
0078 
0079 
0080 /// \brief Container adaptor to build a type that is compliant to the concept of an associative container.
0081 
0082 template
0083 <
0084     class Base,
0085 
0086     class Iterator,
0087     class ConstIterator,
0088 
0089     class KeyType,
0090 
0091     class IteratorToBaseConverter   = ::boost::mpl::na,
0092     class IteratorFromBaseConverter = ::boost::mpl::na,
0093     class ValueToBaseConverter      = ::boost::mpl::na,
0094     class ValueFromBaseConverter    = ::boost::mpl::na,
0095     class KeyToBaseConverter        = ::boost::mpl::na,
0096 
0097     class FunctorsFromDerivedClasses = mpl::vector<>
0098 >
0099 class associative_container_adaptor :
0100 
0101     public associative_container_adaptor_base
0102     <
0103         Base, Iterator, ConstIterator, KeyType,
0104         IteratorToBaseConverter, IteratorFromBaseConverter,
0105         ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter,
0106         FunctorsFromDerivedClasses
0107 
0108     >::type
0109 {
0110 
0111     // MetaData -------------------------------------------------------------
0112 
0113     typedef typename associative_container_adaptor_base
0114     <
0115         Base, Iterator, ConstIterator, KeyType,
0116         IteratorToBaseConverter, IteratorFromBaseConverter,
0117         ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter,
0118         FunctorsFromDerivedClasses
0119 
0120     >::type base_;
0121 
0122     public:
0123 
0124     typedef KeyType key_type;
0125 
0126     protected:
0127 
0128     typedef BOOST_DEDUCED_TYPENAME mpl::if_< ::boost::mpl::is_na<KeyToBaseConverter>,
0129     // {
0130             detail::key_to_base_identity
0131             <
0132                 BOOST_DEDUCED_TYPENAME Base::key_type, KeyType
0133             >,
0134     // }
0135     // else
0136     // {
0137             KeyToBaseConverter
0138     // }
0139 
0140     >::type key_to_base;
0141 
0142     public:
0143 
0144     explicit associative_container_adaptor(Base & c)
0145         : base_(c) {}
0146 
0147     protected:
0148 
0149 
0150     typedef associative_container_adaptor associative_container_adaptor_;
0151 
0152     // Interface --------------------------------------------------------------
0153 
0154     public:
0155 
0156     template< class CompatibleKey >
0157     BOOST_DEDUCED_TYPENAME base_::size_type erase(const CompatibleKey & k)
0158     {
0159         return this->base().erase
0160         (
0161             this->template functor<key_to_base>()(k)
0162         );
0163     }
0164 
0165     // As we redefine erase, the other overloads need to be manually routed
0166 
0167     BOOST_DEDUCED_TYPENAME base_::iterator erase(
0168         BOOST_DEDUCED_TYPENAME base_::iterator pos)
0169     {
0170         return base_::container_adaptor_::erase(pos);
0171     }
0172 
0173     BOOST_DEDUCED_TYPENAME base_::iterator erase(
0174         BOOST_DEDUCED_TYPENAME base_::iterator first,
0175         BOOST_DEDUCED_TYPENAME base_::iterator last)
0176     {
0177         return base_::container_adaptor_::erase(first,last);
0178     }
0179 
0180     template< class CompatibleKey >
0181     BOOST_DEDUCED_TYPENAME base_::size_type count(const CompatibleKey & k) const
0182     {
0183         return this->base().count(
0184             this->template functor<key_to_base>()(k)
0185         );
0186     }
0187 
0188     template< class CompatibleKey >
0189     BOOST_DEDUCED_TYPENAME base_::iterator find(const CompatibleKey & k)
0190     {
0191         return this->template functor<typename base_::iterator_from_base>()
0192         (
0193             this->base().find(
0194                 this->template functor<key_to_base>()(k)
0195             )
0196         );
0197     }
0198 
0199     template< class CompatibleKey >
0200     BOOST_DEDUCED_TYPENAME base_::const_iterator
0201         find(const CompatibleKey & k) const
0202     {
0203         return this->template functor<
0204             BOOST_DEDUCED_TYPENAME base_::iterator_from_base>()
0205         (
0206             this->base().find(
0207                 this->template functor<key_to_base>()(k)
0208             )
0209         );
0210     }
0211 
0212     template< class CompatibleKey >
0213     std::pair
0214     <
0215         BOOST_DEDUCED_TYPENAME base_::iterator,
0216         BOOST_DEDUCED_TYPENAME base_::iterator
0217     >
0218         equal_range(const CompatibleKey & k)
0219     {
0220         std::pair<
0221 
0222             BOOST_DEDUCED_TYPENAME Base::iterator,
0223             BOOST_DEDUCED_TYPENAME Base::iterator
0224 
0225         > r( this->base().equal_range(
0226                 this->template functor<key_to_base>()(k)
0227             )
0228         );
0229 
0230         return std::pair
0231         <
0232             BOOST_DEDUCED_TYPENAME base_::iterator,
0233             BOOST_DEDUCED_TYPENAME base_::iterator
0234         >(
0235             this->template functor<
0236                 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
0237             >()                                         ( r.first ),
0238             this->template functor<
0239                 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
0240             >()                                         ( r.second )
0241         );
0242     }
0243 
0244     template< class CompatibleKey >
0245     std::pair
0246     <
0247         BOOST_DEDUCED_TYPENAME base_::const_iterator,
0248         BOOST_DEDUCED_TYPENAME base_::const_iterator
0249     >
0250         equal_range(const CompatibleKey & k) const
0251     {
0252         std::pair<
0253 
0254             BOOST_DEDUCED_TYPENAME Base::const_iterator,
0255             BOOST_DEDUCED_TYPENAME Base::const_iterator
0256 
0257         > r( this->base().equal_range(
0258                 this->template functor<key_to_base>()(k)
0259             )
0260         );
0261 
0262         return std::pair
0263         <
0264             BOOST_DEDUCED_TYPENAME base_::const_iterator,
0265             BOOST_DEDUCED_TYPENAME base_::const_iterator
0266         >(
0267             this->template functor<
0268                 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
0269             >()                                         ( r.first ),
0270             this->template functor<
0271                 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
0272             >()                                         ( r.second )
0273         );
0274     }
0275 
0276 };
0277 
0278 
0279 } // namespace container_adaptor
0280 } // namespace bimaps
0281 } // namespace boost
0282 
0283 
0284 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP
0285 
0286 
0287