epoc32/include/stdapis/boost/ptr_container/detail/associative_ptr_container.hpp
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 //
     2 // Boost.Pointer Container
     3 //
     4 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
     5 //  distribution is subject to the Boost Software License, Version
     6 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
     7 //  http://www.boost.org/LICENSE_1_0.txt)
     8 //
     9 // For more information, see http://www.boost.org/libs/ptr_container/
    10 //
    11 
    12 
    13 #ifndef BOOST_PTR_CONTAINER_DETAIL_ASSOCIATIVE_PTR_CONTAINER_HPP
    14 #define BOOST_PTR_CONTAINER_DETAIL_ASSOCIATIVE_PTR_CONTAINER_HPP
    15 
    16 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
    17 # pragma once
    18 #endif
    19 
    20 #include <boost/ptr_container/detail/reversible_ptr_container.hpp>
    21 
    22 namespace boost
    23 {
    24 
    25 namespace ptr_container_detail
    26 {
    27     template
    28     <
    29         class Config,
    30         class CloneAllocator
    31     >
    32     class associative_ptr_container :
    33         public reversible_ptr_container<Config,CloneAllocator>
    34     {
    35         typedef reversible_ptr_container<Config,CloneAllocator>
    36                                 base_type;
    37 
    38         typedef BOOST_DEDUCED_TYPENAME base_type::scoped_deleter
    39                                 scoped_deleter;
    40 
    41     public: // typedefs
    42         typedef BOOST_DEDUCED_TYPENAME Config::key_type
    43                                 key_type;
    44         typedef BOOST_DEDUCED_TYPENAME Config::key_compare
    45                                 key_compare;
    46         typedef BOOST_DEDUCED_TYPENAME Config::value_compare
    47                                 value_compare;
    48         typedef BOOST_DEDUCED_TYPENAME Config::iterator
    49                                 iterator;
    50         typedef BOOST_DEDUCED_TYPENAME Config::const_iterator
    51                                 const_iterator;
    52         typedef BOOST_DEDUCED_TYPENAME base_type::size_type
    53                                 size_type;
    54 
    55     public: // foundation
    56 
    57        template< class Compare, class Allocator >
    58        associative_ptr_container( const Compare& comp,
    59                                     const Allocator& a )
    60          : base_type( comp, a )
    61        { }
    62 
    63        template< class InputIterator, class Compare, class Allocator >
    64        associative_ptr_container( InputIterator first, InputIterator last,
    65                                     const Compare& comp,
    66                                     const Allocator& a )
    67          : base_type( first, last, comp, a )
    68        { }
    69 
    70        template< class PtrContainer >
    71        associative_ptr_container( std::auto_ptr<PtrContainer> r )
    72          : base_type( r, key_compare() )
    73        { }
    74 
    75        template< class PtrContainer >
    76        void operator=( std::auto_ptr<PtrContainer> r )
    77        {
    78            base_type::operator=( r );
    79        }
    80 
    81     public: // associative container interface
    82         key_compare key_comp() const
    83         {
    84             return this->c_private().key_comp();
    85         }
    86 
    87         value_compare value_comp() const
    88         {
    89             return this->c_private().value_comp();
    90         }
    91 
    92         iterator erase( iterator before ) // nothrow
    93         {
    94             BOOST_ASSERT( !this->empty() );
    95             BOOST_ASSERT( before != this->end() );
    96 
    97             this->remove( before );                      // nothrow
    98             iterator res( before );                      // nothrow
    99             ++res;                                       // nothrow
   100             this->c_private().erase( before.base() );    // nothrow
   101             return res;                                  // nothrow
   102         }
   103 
   104         size_type erase( const key_type& x ) // nothrow
   105         {
   106             iterator i( this->c_private().find( x ) );  // nothrow
   107             if( i == this->end() )                      // nothrow
   108                 return 0u;                              // nothrow
   109             this->remove( i );                          // nothrow
   110             return this->c_private().erase( x );        // nothrow
   111         }
   112 
   113         iterator erase( iterator first,
   114                         iterator last ) // nothrow
   115         {
   116             iterator res( last );                                // nothrow
   117             if( res != this->end() )
   118                 ++res;                                           // nothrow
   119 
   120             this->remove( first, last );                         // nothrow
   121             this->c_private().erase( first.base(), last.base() );// nothrow
   122             return res;                                          // nothrow
   123         }
   124 
   125     protected:
   126 
   127         template< class AssociatePtrCont >
   128         void multi_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator object,
   129                              AssociatePtrCont& from ) // strong
   130         {
   131             BOOST_ASSERT( (void*)&from != (void*)this );
   132             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
   133 
   134             this->c_private().insert( *object.base() );     // strong
   135             from.c_private().erase( object.base() );        // nothrow
   136         }
   137 
   138         template< class AssociatePtrCont >
   139         size_type multi_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator first,
   140                                   BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator last,
   141                                   AssociatePtrCont& from ) // basic
   142         {
   143             BOOST_ASSERT( (void*)&from != (void*)this );
   144             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
   145 
   146             size_type res = 0;
   147             for( ; first != last; )
   148             {
   149                 BOOST_ASSERT( first != from.end() );
   150                 this->c_private().insert( *first.base() );     // strong
   151                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator 
   152                     to_delete( first );
   153                 ++first;
   154                 from.c_private().erase( to_delete.base() );    // nothrow
   155                 ++res;
   156             }
   157 
   158             return res;
   159         }
   160 
   161         template< class AssociatePtrCont >
   162         bool single_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator object,
   163                               AssociatePtrCont& from ) // strong
   164         {
   165             BOOST_ASSERT( (void*)&from != (void*)this );
   166             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
   167 
   168             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
   169                 this->c_private().insert( *object.base() );     // strong
   170             if( p.second )
   171                 from.c_private().erase( object.base() );        // nothrow
   172 
   173             return p.second;
   174         }
   175 
   176         template< class AssociatePtrCont >
   177         size_type single_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator first,
   178                                    BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator last,
   179                                    AssociatePtrCont& from ) // basic
   180         {
   181             BOOST_ASSERT( (void*)&from != (void*)this );
   182             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
   183 
   184             size_type res = 0;
   185             for( ; first != last; )
   186             {
   187                 BOOST_ASSERT( first != from.end() );
   188                 std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
   189                     this->c_private().insert( *first.base() );     // strong
   190                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator 
   191                     to_delete( first );
   192                 ++first;
   193                 if( p.second )
   194                 {
   195                     from.c_private().erase( to_delete.base() );   // nothrow
   196                     ++res;
   197                 }
   198             }
   199             return res;
   200         }
   201 
   202      }; // class 'associative_ptr_container'
   203     
   204 } // namespace 'ptr_container_detail'
   205     
   206 } // namespace 'boost'
   207 
   208 
   209 #endif