Boost logo

Boost-Commit :

From: phil_at_[hidden]
Date: 2008-07-21 07:27:25


Author: pbouchard
Date: 2008-07-21 07:27:25 EDT (Mon, 21 Jul 2008)
New Revision: 47655
URL: http://svn.boost.org/trac/boost/changeset/47655

Log:
Patched STL list for use with smart pointers
Added:
   sandbox/shifted_ptr/bits/
   sandbox/shifted_ptr/bits/bits.zip (contents, props changed)
Text files modified:
   sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp | 7 ++-
   sandbox/shifted_ptr/boost/shifted_allocator.hpp | 67 +++++++++++++++++++++++++++++++++------
   sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp | 4 +-
   3 files changed, 63 insertions(+), 15 deletions(-)

Added: sandbox/shifted_ptr/bits/bits.zip
==============================================================================
Binary file. No diff available.

Modified: sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp (original)
+++ sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp 2008-07-21 07:27:25 EDT (Mon, 21 Jul 2008)
@@ -81,6 +81,9 @@
     /**
         @brief
         This function returns the most recent allocation block that contains p.
+
+ @note
+ Every block allocated after p is discarded.
     */
     
     owned_base * top(void * p)
@@ -220,12 +223,12 @@
         
         void * operator new (size_t s)
         {
- return pool_.allocate(s);
+ return (char *) pool_.allocate(s) + sizeof(owned_base);
         }
         
         void operator delete (void * p)
         {
- pool_.deallocate(p, sizeof(shifted));
+ pool_.deallocate((char *) p - sizeof(owned_base), sizeof(shifted));
         }
     };
 

Modified: sandbox/shifted_ptr/boost/shifted_allocator.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_allocator.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_allocator.hpp 2008-07-21 07:27:25 EDT (Mon, 21 Jul 2008)
@@ -29,6 +29,43 @@
 namespace boost
 {
 
+namespace detail
+{
+
+namespace sh
+{
+
+
+template <typename T>
+ class shifted_ptr_stl : public shifted_ptr<T>
+ {
+ typedef shifted_ptr<T> base;
+
+ public:
+ typedef T element_type;
+
+
+ shifted_ptr_stl()
+ {
+ }
+
+ //! TODO
+ shifted_ptr_stl(T * p) : base((shifted<element_type> *) (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p)))
+ {
+ }
+
+ operator T * ()
+ {
+ return base::get();
+ }
+
+ operator T const * () const
+ {
+ return base::get();
+ }
+ };
+
+
 /**
     STL compliant allocator.
 */
@@ -38,13 +75,13 @@
     class shifted_allocator
     {
     public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef shifted_ptr<T> pointer;
- typedef const shifted_ptr<T> const_pointer;
- typedef T & reference;
- typedef const T & const_reference;
- typedef T value_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef shifted_ptr_stl<T> pointer;
+ typedef const shifted_ptr_stl<T> const_pointer;
+ typedef T & reference;
+ typedef const T & const_reference;
+ typedef T value_type;
 
         template <typename U>
             struct rebind
@@ -61,14 +98,14 @@
         pointer address(reference x) const { return & x; }
         const_pointer address(const_reference x) const { return & x; }
 
- pointer allocate(size_type s, const void * = 0)
+ value_type * allocate(size_type s, const void * = 0)
         {
- return shifted<T>::operator new(s);
+ return (value_type *) shifted<T>::operator new(s);
         }
 
- void deallocate(pointer p, size_type)
+ void deallocate(value_type * p, size_type)
         {
- p.reset();
+ shifted<T>::operator delete(p);
         }
 
         //! FIXME
@@ -101,6 +138,14 @@
     }
 
 
+} // namespace sh
+
+} // namespace detail
+
+using detail::sh::shifted_allocator;
+using detail::sh::operator ==;
+using detail::sh::operator !=;
+
 } // namespace boost
 
 #endif // #ifndef BOOST_SHIFTED_ALLOCATOR_HPP_INCLUDED

Modified: sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp
==============================================================================
--- sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp (original)
+++ sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp 2008-07-21 07:27:25 EDT (Mon, 21 Jul 2008)
@@ -65,8 +65,8 @@
     vector() { ++count; }
     ~vector() { --count; }
     vector(const vector& other) : elements(other.elements) { ++count; }
- std::vector<shifted_ptr<vector> > elements;
- //std::list<shifted_ptr<vector>, shifted_allocator< shifted_ptr<vector> > > elements; //! FIXME
+ //std::vector<shifted_ptr<vector> > elements;
+ std::list<shifted_ptr<vector>, shifted_allocator< shifted_ptr<vector> > > elements; //! FIXME
 };
 
 struct create_type {


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