Boost logo

Boost-Commit :

From: phil_at_[hidden]
Date: 2008-07-23 03:49:01


Author: pbouchard
Date: 2008-07-23 03:48:59 EDT (Wed, 23 Jul 2008)
New Revision: 47697
URL: http://svn.boost.org/trac/boost/changeset/47697

Log:
_M_node now lives on the heap and removed shifted_ptr_stl.
Text files modified:
   sandbox/shifted_ptr/bits/list.tcc | 4 +-
   sandbox/shifted_ptr/bits/stl_list.h | 24 +++++++++++++--------
   sandbox/shifted_ptr/boost/shifted_allocator.hpp | 44 ++++++---------------------------------
   sandbox/shifted_ptr/boost/shifted_ptr.hpp | 35 +++++++++++++++++++++++++++++++
   sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp | 6 +++-
   5 files changed, 63 insertions(+), 50 deletions(-)

Modified: sandbox/shifted_ptr/bits/list.tcc
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc (original)
+++ sandbox/shifted_ptr/bits/list.tcc 2008-07-23 03:48:59 EDT (Wed, 23 Jul 2008)
@@ -101,11 +101,11 @@
     {
       typedef _List_node<_Tp,_Alloc> _Node;
       typedef _List_node_base<_Alloc> _Node_base;
- _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(this->_M_impl._M_node._M_next));
+ _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*this->_M_impl._M_node._M_next));
       while (__cur != &this->_M_impl._M_node)
       {
         _Node* __tmp = __cur;
- __cur = static_cast<_Node*>(static_cast<_Node_base*>(__cur->_M_next));
+ __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*__cur->_M_next));
         std::_Destroy(&__tmp->_M_data);
         _M_put_node(__tmp);
       }

Modified: sandbox/shifted_ptr/bits/stl_list.h
==============================================================================
--- sandbox/shifted_ptr/bits/stl_list.h (original)
+++ sandbox/shifted_ptr/bits/stl_list.h 2008-07-23 03:48:59 EDT (Wed, 23 Jul 2008)
@@ -244,7 +244,7 @@
       _Self&
       operator++()
       {
- _M_node = _M_node->_M_next;
+ _M_node = &*_M_node->_M_next;
         return *this;
       }
 
@@ -323,11 +323,17 @@
       _Node_Alloc_type;
 
       struct _List_impl
- : public _Node_Alloc_type {
- _List_node_base<_Alloc> _M_node;
- _List_impl (const _Node_Alloc_type& __a)
- : _Node_Alloc_type(__a)
- { }
+ : public _Node_Alloc_type {
+ _List_base & _M_base;
+ _List_node_base<_Alloc> & _M_node;
+ _List_impl (const _Node_Alloc_type& __a, _List_base& __b)
+ : _Node_Alloc_type(__a), _M_base(__b), _M_node(* new (_M_base._M_get_node()) _List_node_base<_Alloc>())
+ { }
+ ~_List_impl ()
+ {
+ _M_node.~_List_node_base<_Alloc>();
+ _M_base._M_put_node(static_cast<_List_node<_Tp, _Alloc> *>(&_M_node));
+ }
       };
 
       _List_impl _M_impl;
@@ -348,7 +354,7 @@
       { return allocator_type(*static_cast<const _Node_Alloc_type*>(&this->_M_impl)); }
 
       _List_base(const allocator_type& __a)
- : _M_impl(__a)
+ : _M_impl(__a, *this)
       { _M_init(); }
 
       // This is what actually destroys the list.
@@ -623,7 +629,7 @@
        */
       iterator
       begin()
- { return iterator(this->_M_impl._M_node._M_next); }
+ { return iterator(&*this->_M_impl._M_node._M_next); }
 
       /**
        * Returns a read-only (constant) iterator that points to the
@@ -632,7 +638,7 @@
        */
       const_iterator
       begin() const
- { return const_iterator(this->_M_impl._M_node._M_next); }
+ { return const_iterator(&*this->_M_impl._M_node._M_next); }
 
       /**
        * Returns a read/write iterator that points one past the last

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-23 03:48:59 EDT (Wed, 23 Jul 2008)
@@ -36,36 +36,6 @@
 {
 
 
-template <typename T>
- class shifted_ptr_stl : public shifted_ptr<T>
- {
- typedef shifted_ptr<T> base;
-
- public:
- typedef T element_type;
-
-
- shifted_ptr_stl()
- {
- }
-
- //! FIXME
- 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.
 */
@@ -75,13 +45,13 @@
     class shifted_allocator
     {
     public:
- 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;
+ 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;
 
         template <typename U>
             struct rebind

Modified: sandbox/shifted_ptr/boost/shifted_ptr.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_ptr.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_ptr.hpp 2008-07-23 03:48:59 EDT (Wed, 23 Jul 2008)
@@ -240,6 +240,41 @@
                 return operator = <T>(p);
             }
 
+//! FIXME
+#if 1
+ template <typename V>
+ shifted_ptr(V * p)
+ {
+ shifted<element_type> * const q = (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p));
+
+ base::operator = (q);
+
+ if (! owned_base::pool_.is_from(this))
+ {
+ ps_ = new set();
+
+ init(q);
+ }
+ else
+ {
+ owned_base::pool_.top(this)->ptrs()->push(& pn_);
+ owned_base::pool_.top(this)->inits()->merge(* q->inits());
+ }
+ }
+
+ template <typename V>
+ shifted_ptr & operator = (V * p)
+ {
+ shifted<element_type> * const q = (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p));
+
+ release();
+ init(q);
+ base::operator = (q);
+
+ return * this;
+ }
+#endif
+
         void reset()
         {
             release();

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-23 03:48:59 EDT (Wed, 23 Jul 2008)
@@ -77,6 +77,7 @@
 };
 
 int main() {
+/*
     count = 0;
         {
             list l;
@@ -88,14 +89,14 @@
             }
         }
     std::cout << count << std::endl;
-
+*/
     count = 0;
     {
         shifted_ptr<vector> v = new shifted<vector>();
         v->elements.push_back(v);
     }
     std::cout << count << std::endl;
-
+/*
     {
         vector v;
         v.elements.push_back(new shifted<vector>());
@@ -116,4 +117,5 @@
         boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
     }
     std::cout << count << std::endl;
+*/
 }


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