Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54431 - in sandbox/monotonic/boost: . ptr_container ptr_container/detail
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 01:56:27


Author: cschladetsch
Date: 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
New Revision: 54431
URL: http://svn.boost.org/trac/boost/changeset/54431

Log:
added cloneable::deallocate

Text files modified:
   sandbox/monotonic/boost/cloneable.hpp | 12 ++++++++----
   sandbox/monotonic/boost/ptr_container/detail/reversible_ptr_container.hpp | 19 +++++++++++--------
   sandbox/monotonic/boost/ptr_container/detail/scoped_deleter.hpp | 21 +++++++++++----------
   sandbox/monotonic/boost/ptr_container/detail/static_move_ptr.hpp | 6 +++---
   sandbox/monotonic/boost/ptr_container/ptr_sequence_adapter.hpp | 2 +-
   5 files changed, 34 insertions(+), 26 deletions(-)

Modified: sandbox/monotonic/boost/cloneable.hpp
==============================================================================
--- sandbox/monotonic/boost/cloneable.hpp (original)
+++ sandbox/monotonic/boost/cloneable.hpp 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
@@ -19,6 +19,7 @@
                         virtual ~common_base() { }
 
                         virtual common_base *allocate(abstract_allocator &alloc) const = 0;
+ virtual void deallocate(common_base *, abstract_allocator &alloc) const = 0;
                         virtual common_base *create(abstract_allocator &alloc) const = 0;
                         virtual common_base *copy_construct(const common_base &original, abstract_allocator &alloc) const = 0;
                 };
@@ -50,6 +51,11 @@
                                 return ptr;
                         }
 
+ void deallocate(common_base *object, abstract_allocator &alloc) const
+ {
+ alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(object));
+ }
+
                         virtual base<Derived> *create(boost::abstract_allocator &alloc) const
                         {
                                 base<Derived> *ptr = allocate(alloc);
@@ -91,12 +97,10 @@
                                 return object.copy_construct(object, alloc);
                         }
 
- // this is not even needed?
                         template <class Base, class Alloc>
- static void deallocate_clone(Base &object, Alloc &alloc )
+ static void deallocate_clone(const Base *object, Alloc &alloc )
                         {
- typename Alloc::template rebind<U>::other my_alloc(alloc);
- my_alloc.deallocate(&object);
+ object->deallocate(const_cast<Base *>(object), alloc);
                         }
                 };
 

Modified: sandbox/monotonic/boost/ptr_container/detail/reversible_ptr_container.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/detail/reversible_ptr_container.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/detail/reversible_ptr_container.hpp 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
@@ -48,13 +48,15 @@
 
 namespace ptr_container_detail
 {
- template< class CloneAllocator >
+ template< class CloneAllocator, class Alloc >
     struct clone_deleter
     {
+ Alloc &alloc;
+ clone_deleter(Alloc &a) : alloc(a) { }
         template< class T >
         void operator()( const T* p ) const
         {
- CloneAllocator::deallocate_clone( p );
+ CloneAllocator::deallocate_clone( p, alloc );
         }
     };
 
@@ -142,7 +144,8 @@
                                 return res;
                         }
 
- static void deallocate_clone( const Ty_* x )
+ template <class Alloc>
+ static void deallocate_clone( const Ty_* x, Alloc &alloc )
             {
                 if( allow_null_values )
                 {
@@ -150,7 +153,7 @@
                         return;
                 }
 
- CloneAllocator::deallocate_clone( x );
+ CloneAllocator::deallocate_clone( x, alloc );
             }
         };
 
@@ -161,7 +164,7 @@
 #else
         typedef null_clone_allocator<allow_null> null_cloner_type;
 #endif
- typedef clone_deleter<null_cloner_type> Deleter;
+ typedef clone_deleter<null_cloner_type, typename Config::allocator_type> Deleter;
 
         Cont c_;
 
@@ -196,7 +199,7 @@
             
     protected:
             
- typedef ptr_container_detail::scoped_deleter<Ty_,null_cloner_type>
+ typedef ptr_container_detail::scoped_deleter<Ty_,null_cloner_type, allocator_type>
                                    scoped_deleter;
         typedef BOOST_DEDUCED_TYPENAME Cont::iterator
                                    ptr_iterator;
@@ -289,12 +292,12 @@
 
         static Ty_* null_policy_allocate_clone( const Ty_* x )
         {
- return null_cloner_type::allocate_clone( x );
+ return null_cloner_type::allocate_clone( x, allocator_type() );
         }
 
         static void null_policy_deallocate_clone( const Ty_* x )
         {
- null_cloner_type::deallocate_clone( x );
+ null_cloner_type::deallocate_clone( x, allocator_type() );
         }
 
     private:

Modified: sandbox/monotonic/boost/ptr_container/detail/scoped_deleter.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/detail/scoped_deleter.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/detail/scoped_deleter.hpp 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
@@ -25,33 +25,34 @@
 
     namespace ptr_container_detail
     {
- template< class T, class CloneAllocator >
+ template< class T, class CloneAllocator, class Alloc >
         class scoped_deleter
         {
             typedef std::size_t size_type;
             scoped_array<T*> ptrs_;
             size_type stored_;
             bool released_;
+ Alloc &alloc;
             
         public:
- scoped_deleter( T** a, size_type size )
- : ptrs_( a ), stored_( size ), released_( false )
+ scoped_deleter( T** a, size_type size, Alloc &al )
+ : ptrs_( a ), stored_( size ), released_( false ), alloc(al)
             {
                 BOOST_ASSERT( a );
             }
             
- scoped_deleter( size_type size )
+ scoped_deleter( size_type size, Alloc &a )
                 : ptrs_( new T*[size] ), stored_( 0 ),
- released_( false )
+ released_( false ), alloc(a)
             {
                 BOOST_ASSERT( size > 0 );
             }
 
 
             
- scoped_deleter( size_type n, const T& x ) // strong
+ scoped_deleter( size_type n, const T& x, Alloc &a )
                 : ptrs_( new T*[n] ), stored_(0),
- released_( false )
+ released_( false ), alloc(a)
             {
                 for( size_type i = 0; i != n; i++ )
                     add( CloneAllocator::allocate_clone( &x ) );
@@ -61,10 +62,10 @@
 
             
             template< class InputIterator, class Alloc >
- scoped_deleter ( InputIterator first, InputIterator last, Alloc &alloc ) // strong
+ scoped_deleter ( InputIterator first, InputIterator last, Alloc &a ) // strong
                 : ptrs_( new T*[ std::distance(first,last) ] ),
                   stored_(0),
- released_( false )
+ released_( false ), alloc(a)
             {
                 for( ; first != last; ++first )
                     add( CloneAllocator::allocate_clone_from_iterator( first, alloc ) );
@@ -78,7 +79,7 @@
                 if ( !released_ )
                 {
                     for( size_type i = 0u; i != stored_; ++i )
- CloneAllocator::deallocate_clone( ptrs_[i] );
+ CloneAllocator::deallocate_clone( ptrs_[i], alloc );
                 }
             }
             

Modified: sandbox/monotonic/boost/ptr_container/detail/static_move_ptr.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/detail/static_move_ptr.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/detail/static_move_ptr.hpp 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
@@ -75,9 +75,9 @@
                 src.ptr().release();
             }
     
- template<typename TT>
- explicit static_move_ptr(TT* tt)
- : impl_(tt, Deleter())
+ template<typename TT, class Alloc>
+ explicit static_move_ptr(TT* tt, Alloc &alloc)
+ : impl_(tt, Deleter(alloc))
         { }
 
         // Destructor

Modified: sandbox/monotonic/boost/ptr_container/ptr_sequence_adapter.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/ptr_sequence_adapter.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/ptr_sequence_adapter.hpp 2009-06-28 01:56:26 EDT (Sun, 28 Jun 2009)
@@ -245,7 +245,7 @@
         {
             this->enforce_null_policy( x, "Null pointer in 'push_back()'" );
 
- auto_type ptr( x ); // notrow
+ auto_type ptr( x, get_allocator() ); // notrow
             this->base().push_back( x ); // strong, commit
             ptr.release(); // nothrow
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk