epoc32/include/stdapis/boost/ptr_container/detail/scoped_deleter.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/ptr_container/detail/scoped_deleter.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,115 @@
     1.4 +//
     1.5 +// Boost.Pointer Container
     1.6 +//
     1.7 +//  Copyright Thorsten Ottosen 2003-2005. Use, modification and
     1.8 +//  distribution is subject to the Boost Software License, Version
     1.9 +//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.10 +//  http://www.boost.org/LICENSE_1_0.txt)
    1.11 +//
    1.12 +// For more information, see http://www.boost.org/libs/ptr_container/
    1.13 +//
    1.14 +
    1.15 +#ifndef BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
    1.16 +#define BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
    1.17 +
    1.18 +#if defined(_MSC_VER) && (_MSC_VER >= 1200)
    1.19 +# pragma once
    1.20 +#endif
    1.21 +
    1.22 +#include <iterator>
    1.23 +#include <cstddef>
    1.24 +#include <boost/scoped_array.hpp>
    1.25 +
    1.26 +namespace boost
    1.27 +{
    1.28 +
    1.29 +    namespace ptr_container_detail
    1.30 +    {
    1.31 +        template< class T, class CloneAllocator >
    1.32 +        class scoped_deleter
    1.33 +        {
    1.34 +            typedef std::size_t size_type;
    1.35 +            scoped_array<T*>  ptrs_;
    1.36 +            size_type         stored_; 
    1.37 +            bool              released_;
    1.38 +            
    1.39 +        public:
    1.40 +            scoped_deleter( size_type size ) : 
    1.41 +                ptrs_( new T*[size] ), stored_( 0 ), 
    1.42 +                released_( false )
    1.43 +            {
    1.44 +                BOOST_ASSERT( size > 0 );
    1.45 +            }
    1.46 +
    1.47 +
    1.48 +            
    1.49 +            scoped_deleter( size_type n, const T& x ) // strong
    1.50 +                : ptrs_( new T*[n] ), stored_(0),
    1.51 +                  released_( false )
    1.52 +            {
    1.53 +                for( size_type i = 0; i != n; i++ )
    1.54 +                    add( CloneAllocator::allocate_clone( &x ) );
    1.55 +                BOOST_ASSERT( stored_ > 0 );
    1.56 +            }
    1.57 +
    1.58 +
    1.59 +            
    1.60 +            template< class InputIterator >
    1.61 +            scoped_deleter ( InputIterator first, InputIterator last  ) // strong
    1.62 +                : ptrs_( new T*[ std::distance(first,last) ] ),
    1.63 +                  stored_(0),
    1.64 +                  released_( false )
    1.65 +            {
    1.66 +                for( ; first != last; ++first )
    1.67 +                    add( CloneAllocator::allocate_clone_from_iterator( first ) );
    1.68 +                BOOST_ASSERT( stored_ > 0 );
    1.69 +            }
    1.70 +
    1.71 +            
    1.72 +            
    1.73 +            ~scoped_deleter()
    1.74 +            {
    1.75 +                if ( !released_ )
    1.76 +                {
    1.77 +                    for( size_type i = 0u; i != stored_; ++i )
    1.78 +                        CloneAllocator::deallocate_clone( ptrs_[i] ); 
    1.79 +                }
    1.80 +            }
    1.81 +            
    1.82 +            
    1.83 +            
    1.84 +            void add( T* t )
    1.85 +            {
    1.86 +                BOOST_ASSERT( ptrs_.get() != 0 );
    1.87 +                ptrs_[stored_] = t;
    1.88 +                ++stored_;
    1.89 +            }
    1.90 +            
    1.91 +            
    1.92 +            
    1.93 +            void release()
    1.94 +            {
    1.95 +                released_ = true;
    1.96 +            }
    1.97 +            
    1.98 +            
    1.99 +            
   1.100 +            T** begin()
   1.101 +            {
   1.102 +                BOOST_ASSERT( ptrs_.get() != 0 );
   1.103 +                return &ptrs_[0];
   1.104 +            }
   1.105 +            
   1.106 +            
   1.107 +            
   1.108 +            T** end()
   1.109 +            {
   1.110 +                BOOST_ASSERT( ptrs_.get() != 0 );
   1.111 +                return &ptrs_[stored_];
   1.112 +            }
   1.113 +            
   1.114 +        }; // class 'scoped_deleter'
   1.115 +    }
   1.116 +}
   1.117 +
   1.118 +#endif