Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:35

0001 //
0002 // Boost.Pointer Container
0003 //
0004 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
0005 //  distribution is subject to the Boost Software License, Version
0006 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // For more information, see http://www.boost.org/libs/ptr_container/
0010 //
0011 
0012 #ifndef BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
0013 #define BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif
0018 
0019 #include <iterator>
0020 #include <cstddef>
0021 #include <boost/scoped_array.hpp>
0022 
0023 namespace boost
0024 {
0025 
0026     namespace ptr_container_detail
0027     {
0028         template< class Container >
0029         class scoped_deleter
0030         {
0031             typedef BOOST_DEDUCED_TYPENAME Container::size_type   size_type;
0032             typedef BOOST_DEDUCED_TYPENAME Container::object_type T;
0033 
0034             Container&        cont_;
0035             scoped_array<T*>  ptrs_;
0036             size_type         stored_;
0037             bool              released_;
0038 
0039         public:
0040             scoped_deleter( Container& cont, T** a, size_type size )
0041                 : cont_(cont),
0042                   ptrs_( a ),
0043                   stored_( size ),
0044                   released_( false )
0045             {
0046                 BOOST_ASSERT( a );
0047             }
0048 
0049             scoped_deleter( Container& cont, size_type size )
0050                 : cont_(cont),
0051                   ptrs_( new T*[size] ),
0052                   stored_( 0 ),
0053                   released_( false )
0054             {
0055                 BOOST_ASSERT( size > 0 );
0056             }
0057 
0058 
0059 
0060             scoped_deleter( Container& cont, size_type n, const T& x ) // strong
0061                 : cont_(cont),
0062                   ptrs_( new T*[n] ),
0063                   stored_(0),
0064                   released_( false )
0065             {
0066                 for( size_type i = 0; i != n; i++ )
0067                     add( cont_.null_policy_allocate_clone( &x ) );
0068                 BOOST_ASSERT( stored_ > 0 );
0069             }
0070 
0071 
0072 
0073             template< class InputIterator >
0074             scoped_deleter ( Container& cont, InputIterator first, InputIterator last  ) // strong
0075                 : cont_(cont),
0076                   ptrs_( new T*[ std::distance(first,last) ] ),
0077                   stored_(0),
0078                   released_( false )
0079             {
0080                 for( ; first != last; ++first )
0081                     add( cont_.null_policy_allocate_clone_from_iterator( first ) );
0082                 BOOST_ASSERT( stored_ > 0 );
0083             }
0084 
0085 
0086 
0087             ~scoped_deleter()
0088             {
0089                 if ( !released_ )
0090                 {
0091                     for( size_type i = 0u; i != stored_; ++i )
0092                         cont_.null_policy_deallocate_clone( ptrs_[i] );
0093                 }
0094             }
0095 
0096 
0097 
0098             void add( T* t )
0099             {
0100                 BOOST_ASSERT( ptrs_.get() != 0 );
0101                 ptrs_[stored_] = t;
0102                 ++stored_;
0103             }
0104 
0105 
0106 
0107             void release()
0108             {
0109                 released_ = true;
0110             }
0111 
0112 
0113 
0114             T** begin()
0115             {
0116                 BOOST_ASSERT( ptrs_.get() != 0 );
0117                 return &ptrs_[0];
0118             }
0119 
0120 
0121 
0122             T** end()
0123             {
0124                 BOOST_ASSERT( ptrs_.get() != 0 );
0125                 return &ptrs_[stored_];
0126             }
0127 
0128         }; // class 'scoped_deleter'
0129     }
0130 }
0131 
0132 #endif