Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71529 - in sandbox: mm_ptr mutual_ptr mutual_ptr/boost mutual_ptr/boost/detail mutual_ptr/libs/smart_ptr/doc mutual_ptr/libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2011-04-26 21:01:37


Author: pbouchard
Date: 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
New Revision: 71529
URL: http://svn.boost.org/trac/boost/changeset/71529

Log:
* Renamed MM Pointer to Mutual Pointer
Added:
   sandbox/mutual_ptr/
      - copied from r71458, /sandbox/mm_ptr/
   sandbox/mutual_ptr/boost/detail/intrusive_list.hpp
      - copied unchanged from r71487, /sandbox/mm_ptr/boost/detail/intrusive_list.hpp
   sandbox/mutual_ptr/boost/detail/intrusive_stack.hpp
      - copied unchanged from r71487, /sandbox/mm_ptr/boost/detail/intrusive_stack.hpp
   sandbox/mutual_ptr/boost/detail/mutual_base.hpp (contents, props changed)
   sandbox/mutual_ptr/boost/detail/mutual_ptr_base.hpp (contents, props changed)
   sandbox/mutual_ptr/boost/detail/roofof.hpp
      - copied unchanged from r71487, /sandbox/mm_ptr/boost/detail/roofof.hpp
   sandbox/mutual_ptr/boost/mutual_allocator.hpp (contents, props changed)
   sandbox/mutual_ptr/boost/mutual_ptr.hpp (contents, props changed)
   sandbox/mutual_ptr/libs/smart_ptr/doc/Doxyfile
      - copied, changed from r71462, /sandbox/mm_ptr/libs/smart_ptr/doc/Doxyfile
   sandbox/mutual_ptr/libs/smart_ptr/doc/MutualPointer.ppt (contents, props changed)
   sandbox/mutual_ptr/libs/smart_ptr/doc/rationale.html
      - copied, changed from r71464, /sandbox/mm_ptr/libs/smart_ptr/doc/rationale.html
   sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html
      - copied, changed from r71464, /sandbox/mm_ptr/libs/smart_ptr/doc/tutorial.html
   sandbox/mutual_ptr/libs/smart_ptr/example/Makefile
      - copied, changed from r71488, /sandbox/mm_ptr/libs/smart_ptr/example/Makefile
   sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test1.cpp (contents, props changed)
   sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test2.cpp (contents, props changed)
   sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test3.cpp (contents, props changed)
Removed:
   sandbox/mm_ptr/
   sandbox/mutual_ptr/boost/detail/mm_ptr_base.hpp
   sandbox/mutual_ptr/boost/detail/sh_owned_base.hpp
   sandbox/mutual_ptr/boost/detail/sh_owned_base_gcc_x86.hpp
   sandbox/mutual_ptr/boost/detail/sh_owned_base_nt.hpp
   sandbox/mutual_ptr/boost/detail/sh_owned_impl.h
   sandbox/mutual_ptr/boost/detail/sh_utility.h
   sandbox/mutual_ptr/boost/mm_allocator.hpp
   sandbox/mutual_ptr/boost/mm_ptr.hpp
   sandbox/mutual_ptr/libs/smart_ptr/doc/MMPointer.ppt
   sandbox/mutual_ptr/libs/smart_ptr/example/mm_ptr_test1.cpp
   sandbox/mutual_ptr/libs/smart_ptr/example/mm_ptr_test2.cpp
   sandbox/mutual_ptr/libs/smart_ptr/example/mm_ptr_test3.cpp
Binary files modified:
   sandbox/mutual_ptr/libs/smart_ptr/doc/Cyclicism1.png
   sandbox/mutual_ptr/libs/smart_ptr/doc/Cyclicism2.png
   sandbox/mutual_ptr/libs/smart_ptr/doc/Introduction.png
   sandbox/mutual_ptr/libs/smart_ptr/doc/Union1.png
   sandbox/mutual_ptr/libs/smart_ptr/doc/Union2.png
Text files modified:
   sandbox/mutual_ptr/libs/smart_ptr/doc/Doxyfile | 2 +-
   sandbox/mutual_ptr/libs/smart_ptr/doc/index.html | 2 +-
   sandbox/mutual_ptr/libs/smart_ptr/doc/overview.html | 6 +++---
   sandbox/mutual_ptr/libs/smart_ptr/doc/rationale.html | 10 +++++-----
   sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html | 18 +++++++++---------
   sandbox/mutual_ptr/libs/smart_ptr/example/Makefile | 10 +++++-----
   6 files changed, 24 insertions(+), 24 deletions(-)

Deleted: /sandbox/mm_ptr/boost/detail/mm_ptr_base.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/detail/mm_ptr_base.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,356 +0,0 @@
-/**
- @file
- Boost mm_ptr_base.hpp header file.
-
- @note
- Copyright (c) 2003 - 2008 Phil Bouchard <phil_at_[hidden]>.
- Copyright (c) 2001 - 2007 Peter Dimov
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_SHIFTED_PTR_HPP
-#define BOOST_SHIFTED_PTR_HPP
-
-
-#include <boost/detail/sh_utility.h>
-#include <boost/detail/sh_owned_base.hpp>
-
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-
-/**
- Smart pointer optimized for speed and memory usage.
-
- This class represents a basic smart pointer interface.
-*/
-
-template <typename T>
- class mm_ptr_common
- {
- template <typename> friend class mm_ptr_common;
-
- // Borland 5.5.1 specific workaround
- typedef mm_ptr_common<T> this_type;
-
- protected:
- typedef T value_type;
- typedef mm<value_type> element_type;
-
- value_type * po_;
-
- public:
- mm_ptr_common() : po_(0)
- {
- }
-
- ~mm_ptr_common()
- {
- if (po_)
- {
- header()->release();
- }
- }
-
- template <typename V>
- mm_ptr_common(detail::sh::mm<V> * p) : po_(p->element())
- {
- }
-
- template <typename V>
- mm_ptr_common(mm_ptr_common<V> const & p) : po_(p.share())
- {
- }
-
- mm_ptr_common(mm_ptr_common<value_type> const & p) : po_(p.share())
- {
- }
-
- template <typename V>
- mm_ptr_common & operator = (detail::sh::mm<V> * p)
- {
- reset(p->element());
-
- return * this;
- }
-
- template <typename V>
- mm_ptr_common & operator = (mm_ptr_common<V> const & p)
- {
- if (p.po_ != po_)
- {
- reset(p.share());
- }
- return * this;
- }
-
- mm_ptr_common & operator = (mm_ptr_common<value_type> const & p)
- {
- return operator = <value_type>(p);
- }
-
- value_type * get() const
- {
- return po_;
- }
-
- value_type * share() const
- {
- if (po_)
- {
- header()->add_ref_copy();
- }
- return po_;
- }
-
- void reset(value_type * p = 0)
- {
- if (po_)
- {
- header()->release();
- }
- po_ = p;
- }
-
-#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
- operator bool () const
- {
- return po_ != 0;
- }
-#elif defined( _MANAGED )
- static void unspecified_bool( this_type*** )
- {
- }
-
- typedef void (*unspecified_bool_type)( this_type*** );
-
- operator unspecified_bool_type() const // never throws
- {
- return po_ == 0? 0: unspecified_bool;
- }
-#elif \
- ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
- ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
- ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
-
- typedef value_type * (this_type::*unspecified_bool_type)() const;
-
- operator unspecified_bool_type() const // never throws
- {
- return po_ == 0? 0: &this_type::get;
- }
-#else
- typedef value_type * this_type::*unspecified_bool_type;
-
- operator unspecified_bool_type() const // never throws
- {
- return po_ == 0? 0: &this_type::po_;
- }
-#endif
-
- // operator! is redundant, but some compilers need it
-
- bool operator! () const // never throws
- {
- return po_ == 0;
- }
-
- long use_count() const // never throws
- {
- return header()->use_count();
- }
-
- protected:
- detail::sh::owned_base * header() const
- {
- detail::sh::owned_base * p = (mm<value_type> *) (typename mm<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(po_));
- return p;
- }
- };
-
-
-template <typename T>
- class mm_ptr_base : public mm_ptr_common<T>
- {
- typedef mm_ptr_common<T> base;
- typedef typename base::value_type value_type;
-
- protected:
- using base::po_;
-
- public:
- mm_ptr_base() : base()
- {
- }
-
- template <typename V>
- mm_ptr_base(detail::sh::mm<V> * p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base(mm_ptr_base<V> const & p) : base(p)
- {
- }
-
- mm_ptr_base(mm_ptr_base<value_type> const & p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base & operator = (detail::sh::mm<V> * p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- template <typename V>
- mm_ptr_base & operator = (mm_ptr_base<V> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- mm_ptr_base & operator = (mm_ptr_base<value_type> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- value_type & operator * () const
- {
- return * po_;
- }
-
- value_type * operator -> () const
- {
- return po_;
- }
- };
-
-
-#if !defined(_MSC_VER)
-template <typename T, size_t N>
- class mm_ptr_base<T [N]> : public mm_ptr_common<T [N]>
- {
- typedef mm_ptr_common<T [N]> base;
- typedef typename base::value_type value_type;
-
- protected:
- using base::po_;
-
- public:
- mm_ptr_base() : base()
- {
- }
-
- template <typename V>
- mm_ptr_base(detail::sh::mm<V> * p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base(mm_ptr_base<V> const & p) : base(p)
- {
- }
-
- mm_ptr_base(mm_ptr_base<value_type> const & p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base & operator = (detail::sh::mm<V> * p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- template <typename V>
- mm_ptr_base & operator = (mm_ptr_base<V> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- mm_ptr_base & operator = (mm_ptr_base<value_type> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- T & operator [] (std::size_t n)
- {
- return ** (po_ + n);
- }
-
- T const & operator [] (std::size_t n) const
- {
- return ** (po_ + n);
- }
- };
-#endif
-
-
-template <>
- class mm_ptr_base<void> : public mm_ptr_common<void>
- {
- typedef mm_ptr_common<void> base;
- typedef base::value_type value_type;
-
- protected:
- using base::po_;
-
- public:
- mm_ptr_base() : base()
- {
- }
-
- template <typename V>
- mm_ptr_base(detail::sh::mm<V> * p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base(mm_ptr_base<V> const & p) : base(p)
- {
- }
-
- mm_ptr_base(mm_ptr_base<value_type> const & p) : base(p)
- {
- }
-
- template <typename V>
- mm_ptr_base & operator = (detail::sh::mm<V> * p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- template <typename V>
- mm_ptr_base & operator = (mm_ptr_base<V> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
-
- mm_ptr_base & operator = (mm_ptr_base<value_type> const & p)
- {
- return static_cast<mm_ptr_base &>(base::operator = (p));
- }
- };
-
-
-} // namespace sh
-
-} // namespace detail
-
-} // namespace boost
-
-
-#endif

Added: sandbox/mutual_ptr/boost/detail/mutual_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/boost/detail/mutual_base.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,331 @@
+/**
+ @file
+ Boost detail/sh_mutual_base_nt.hpp header file.
+
+ @note
+ Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
+
+ Distributed under the Boost Software License, Version 1.0.
+
+ See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+
+ See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
+*/
+
+
+#ifndef BOOST_DETAIL_MUTUAL_BASE_HPP_INCLUDED
+#define BOOST_DETAIL_MUTUAL_BASE_HPP_INCLUDED
+
+// MS compatible compilers support #pragma once
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <stack>
+#include <limits>
+
+#include <boost/thread.hpp>
+#include <boost/thread/tss.hpp>
+#include <boost/pool/pool.hpp>
+#include <boost/pool/pool_alloc.hpp>
+#include <boost/numeric/interval.hpp>
+#include <boost/type_traits/is_array.hpp>
+#include <boost/type_traits/remove_extent.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
+#include <boost/preprocessor/control/expr_if.hpp>
+#include <boost/preprocessor/arithmetic/inc.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/repeat_from_to.hpp>
+
+#include <boost/detail/intrusive_list.hpp>
+#include <boost/detail/intrusive_stack.hpp>
+#include <boost/detail/roofof.hpp>
+
+
+namespace boost
+{
+
+namespace detail
+{
+
+namespace sh
+{
+
+
+class mutual_header;
+class mutual_base;
+
+
+/**
+ Allocator wrapper tracking allocations.
+
+ Pool where all pointee objects are allocated and tracks memory blocks for later enlisting & marking the @c mutual_header the pointee object belongs to.
+*/
+
+struct pool : boost::pool<>
+{
+ typedef std::list< numeric::interval<long>, fast_pool_allocator< numeric::interval<long> > > pool_lii; /**< Syntax helper. */
+
+#ifndef BOOST_DISABLE_THREADS
+ thread_specific_ptr<pool_lii> plii_; /**< Thread specific list of memory boundaries. */
+#else
+ std::auto_ptr<pool_lii> plii_; /**< List of memory boundaries. */
+#endif
+
+
+ /**
+ Initialization of a pool instance.
+ */
+
+ pool() : boost::pool<>(1)
+ {
+ plii_.reset(new pool_lii());
+ }
+
+
+ /**
+ Tracks the memory boundaries where a pointer belongs to. Also gets rid of the boundaries that were allocated before the pointer was allocated.
+
+ @param p Pointer that is being tracked.
+ @return Pointer to the pointee object where @c p belongs to.
+ */
+
+ mutual_base * top(void * p)
+ {
+ pool_lii::reverse_iterator i;
+
+ for (i = plii_->rbegin(); i != plii_->rend(); i ++)
+ if (in((long)(p), * i))
+ break;
+
+ plii_->erase(i.base(), plii_->end());
+
+ return (mutual_base *)(plii_->rbegin()->lower());
+ }
+
+
+ /**
+ Pointee object allocator and stacking of the newly allocated memory boundary.
+
+ @param s Size of the memory block to allocate.
+ @return Address of the newly allocated block.
+ */
+
+ void * allocate(std::size_t s)
+ {
+ void * p = ordered_malloc(s);
+
+ plii_->push_back(numeric::interval<long>((long) p, long((char *)(p) + s)));
+
+ return p;
+ }
+
+
+ /**
+ Pointee object deallocator and removal of the boundaries that were allocated before the pointer was allocated.
+
+ @param p Address of the memory block to deallocate.
+ @param s Size of the memory block.
+ */
+
+ void deallocate(void * p, std::size_t s)
+ {
+ pool_lii::reverse_iterator i;
+
+ for (i = plii_->rbegin(); i != plii_->rend(); i ++)
+ if (in((long)(p), * i))
+ break;
+
+ plii_->erase(i.base(), plii_->end());
+ ordered_free(p, s);
+ }
+};
+
+
+/**
+ Root class of all pointee objects.
+*/
+
+class mutual_base : public sp_counted_base
+{
+public:
+ bool init_; /**< Flag marking initialization of the pointee object to its @c mutual_header . */
+
+ intrusive_stack ptrs_; /**< Stack of all @c mutual_ptr s on the heap that will later need to be initlialized to a specific @c mutual_header . */
+ intrusive_list inits_; /**< List of all pointee objects that will later need to be initlialized to a specific @c mutual_header .*/
+
+ intrusive_list::node mutual_tag_; /**< Tag used to enlist to @c mutual_header::elements_ . */
+ intrusive_list::node init_tag_; /**< Tag used to enlist to @c mutual_base::inits_ . */
+
+
+ mutual_base() : init_(false)
+ {
+ inits_.push_back(& init_tag_);
+ }
+
+ static pool pool_; /**< Pool where all pointee objects are allocated from. */
+
+protected:
+ virtual void dispose() {} /**< dumutualy */
+ virtual void * get_deleter( std::type_info const & ti ) { return 0; } /**< dumutualy */
+};
+
+
+pool mutual_base::pool_;
+
+
+#define TEMPLATE_DECL(z, n, text) BOOST_PP_COMMA_IF(n) typename T ## n
+#define ARGUMENT_DECL(z, n, text) BOOST_PP_COMMA_IF(n) T ## n const & t ## n
+#define PARAMETER_DECL(z, n, text) BOOST_PP_COMMA_IF(n) t ## n
+
+#define CONSTRUCT_OWNED(z, n, text) \
+ template <BOOST_PP_REPEAT(n, TEMPLATE_DECL, 0)> \
+ text(BOOST_PP_REPEAT(n, ARGUMENT_DECL, 0)) : elem_(BOOST_PP_REPEAT(n, PARAMETER_DECL, 0)) {}
+
+/**
+ Object wrapper.
+*/
+
+template <typename T>
+ class mutual : public mutual_base
+ {
+ typedef T data_type;
+
+ T elem_; /**< Pointee object. @note Needs alignas<long>. */
+
+ public:
+ class roofof;
+ friend class roofof;
+
+ mutual() : elem_()
+ {
+ }
+
+ BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_OWNED, mutual)
+
+
+ /**
+ @return Pointee object address.
+ */
+
+ data_type * element() { return & elem_; }
+ operator data_type & () { return * element(); }
+ operator data_type const & () const { return * element(); }
+
+ virtual ~mutual()
+ {
+ dispose();
+ }
+
+ public:
+ /**
+ Cast operator used by @c mutual_ptr_comutualon::header() .
+ */
+
+ class roofof
+ {
+ mutual * p_; /**< Address of the @c mutual the element belong to. */
+
+ public:
+ /**
+ Casts from a @c data_type to its parent @c mutual object.
+
+ @param p Address of a @c data_type member object to cast from.
+ */
+
+ roofof(data_type * p) : p_(sh::roofof((data_type mutual::*)(& mutual::elem_), p)) {}
+
+
+ /**
+ @return Address of the parent @c mutual object.
+ */
+
+ operator mutual * () const { return p_; }
+ };
+
+
+ /**
+ Allocates a new @c mutual using the pool.
+
+ @param s Size of the @c mutual .
+ @return Pointer of the new memory block.
+ */
+
+ void * operator new (size_t s)
+ {
+ return pool_.allocate(s);
+ }
+
+
+ /**
+ Deallocates a @c mutual from the pool.
+
+ @param p Address of the @c mutual to deallocate.
+ */
+
+ void operator delete (void * p)
+ {
+ pool_.deallocate(p, sizeof(mutual));
+ }
+ };
+
+
+template <>
+ class mutual<void> : public mutual_base
+ {
+ typedef void data_type;
+
+ long elem_; /**< Pointee placeholder. @note Aligned. */
+
+ mutual();
+
+ public:
+ class roofof;
+ friend class roofof;
+
+ data_type * element() { return & elem_; }
+
+ virtual ~mutual() {}
+ virtual void dispose() {}
+
+ virtual void * get_deleter( std::type_info const & ti ) {}
+
+ public:
+ /**
+ Cast operator used by @c mutual_ptr_comutualon::header() .
+ */
+
+ class roofof
+ {
+ mutual * p_; /**< Address of the @c mutual the element belong to. */
+
+ public:
+ /**
+ Casts from a @c data_type to its parent @c mutual object.
+
+ @param p Address of a @c data_type member object to cast from.
+ */
+
+ roofof(data_type * p) : p_(sh::roofof((long mutual::*)(& mutual::elem_), static_cast<long *>(p))) {}
+
+
+ /**
+ @return Address of the parent @c mutual object.
+ */
+
+ operator mutual * () const { return p_; }
+ };
+ };
+
+
+} // namespace sh
+
+} // namespace detail
+
+} // namespace boost
+
+
+#endif // #ifndef BOOST_DETAIL_SH_OWNED_BASE_NT_HPP_INCLUDED

Added: sandbox/mutual_ptr/boost/detail/mutual_ptr_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/boost/detail/mutual_ptr_base.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,356 @@
+/**
+ @file
+ Boost mutual_ptr_base.hpp header file.
+
+ @note
+ Copyright (c) 2003 - 2008 Phil Bouchard <phil_at_[hidden]>.
+ Copyright (c) 2001 - 2007 Peter Dimov
+
+ Distributed under the Boost Software License, Version 1.0.
+
+ See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+
+ See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
+*/
+
+
+#ifndef BOOST_DETAIL_MUTUAL_PTR_BASE_HPP
+#define BOOST_DETAIL_MUTUAL_PTR_BASE_HPP
+
+
+#include <boost/detail/roofof.hpp>
+#include <boost/detail/mutual_base.hpp>
+
+
+namespace boost
+{
+
+namespace detail
+{
+
+namespace sh
+{
+
+
+/**
+ Smart pointer optimized for speed and memory usage.
+
+ This class represents a basic smart pointer interface.
+*/
+
+template <typename T>
+ class mutual_ptr_comutualon
+ {
+ template <typename> friend class mutual_ptr_comutualon;
+
+ // Borland 5.5.1 specific workaround
+ typedef mutual_ptr_comutualon<T> this_type;
+
+ protected:
+ typedef T value_type;
+ typedef mutual<value_type> element_type;
+
+ value_type * po_;
+
+ public:
+ mutual_ptr_comutualon() : po_(0)
+ {
+ }
+
+ ~mutual_ptr_comutualon()
+ {
+ if (po_)
+ {
+ header()->release();
+ }
+ }
+
+ template <typename V>
+ mutual_ptr_comutualon(detail::sh::mutual<V> * p) : po_(p->element())
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_comutualon(mutual_ptr_comutualon<V> const & p) : po_(p.share())
+ {
+ }
+
+ mutual_ptr_comutualon(mutual_ptr_comutualon<value_type> const & p) : po_(p.share())
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_comutualon & operator = (detail::sh::mutual<V> * p)
+ {
+ reset(p->element());
+
+ return * this;
+ }
+
+ template <typename V>
+ mutual_ptr_comutualon & operator = (mutual_ptr_comutualon<V> const & p)
+ {
+ if (p.po_ != po_)
+ {
+ reset(p.share());
+ }
+ return * this;
+ }
+
+ mutual_ptr_comutualon & operator = (mutual_ptr_comutualon<value_type> const & p)
+ {
+ return operator = <value_type>(p);
+ }
+
+ value_type * get() const
+ {
+ return po_;
+ }
+
+ value_type * share() const
+ {
+ if (po_)
+ {
+ header()->add_ref_copy();
+ }
+ return po_;
+ }
+
+ void reset(value_type * p = 0)
+ {
+ if (po_)
+ {
+ header()->release();
+ }
+ po_ = p;
+ }
+
+#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
+ operator bool () const
+ {
+ return po_ != 0;
+ }
+#elif defined( _MANAGED )
+ static void unspecified_bool( this_type*** )
+ {
+ }
+
+ typedef void (*unspecified_bool_type)( this_type*** );
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: unspecified_bool;
+ }
+#elif \
+ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
+ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
+ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
+
+ typedef value_type * (this_type::*unspecified_bool_type)() const;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::get;
+ }
+#else
+ typedef value_type * this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::po_;
+ }
+#endif
+
+ // operator! is redundant, but some compilers need it
+
+ bool operator! () const // never throws
+ {
+ return po_ == 0;
+ }
+
+ long use_count() const // never throws
+ {
+ return header()->use_count();
+ }
+
+ protected:
+ detail::sh::mutual_base * header() const
+ {
+ detail::sh::mutual_base * p = (mutual<value_type> *) (typename mutual<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(po_));
+ return p;
+ }
+ };
+
+
+template <typename T>
+ class mutual_ptr_base : public mutual_ptr_comutualon<T>
+ {
+ typedef mutual_ptr_comutualon<T> base;
+ typedef typename base::value_type value_type;
+
+ protected:
+ using base::po_;
+
+ public:
+ mutual_ptr_base() : base()
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(detail::sh::mutual<V> * p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(mutual_ptr_base<V> const & p) : base(p)
+ {
+ }
+
+ mutual_ptr_base(mutual_ptr_base<value_type> const & p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (detail::sh::mutual<V> * p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (mutual_ptr_base<V> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ mutual_ptr_base & operator = (mutual_ptr_base<value_type> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ value_type & operator * () const
+ {
+ return * po_;
+ }
+
+ value_type * operator -> () const
+ {
+ return po_;
+ }
+ };
+
+
+#if !defined(_MSC_VER)
+template <typename T, size_t N>
+ class mutual_ptr_base<T [N]> : public mutual_ptr_comutualon<T [N]>
+ {
+ typedef mutual_ptr_comutualon<T [N]> base;
+ typedef typename base::value_type value_type;
+
+ protected:
+ using base::po_;
+
+ public:
+ mutual_ptr_base() : base()
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(detail::sh::mutual<V> * p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(mutual_ptr_base<V> const & p) : base(p)
+ {
+ }
+
+ mutual_ptr_base(mutual_ptr_base<value_type> const & p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (detail::sh::mutual<V> * p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (mutual_ptr_base<V> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ mutual_ptr_base & operator = (mutual_ptr_base<value_type> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ T & operator [] (std::size_t n)
+ {
+ return * (* po_ + n);
+ }
+
+ T const & operator [] (std::size_t n) const
+ {
+ return * (* po_ + n);
+ }
+ };
+#endif
+
+
+template <>
+ class mutual_ptr_base<void> : public mutual_ptr_comutualon<void>
+ {
+ typedef mutual_ptr_comutualon<void> base;
+ typedef base::value_type value_type;
+
+ protected:
+ using base::po_;
+
+ public:
+ mutual_ptr_base() : base()
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(detail::sh::mutual<V> * p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base(mutual_ptr_base<V> const & p) : base(p)
+ {
+ }
+
+ mutual_ptr_base(mutual_ptr_base<value_type> const & p) : base(p)
+ {
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (detail::sh::mutual<V> * p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ template <typename V>
+ mutual_ptr_base & operator = (mutual_ptr_base<V> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+
+ mutual_ptr_base & operator = (mutual_ptr_base<value_type> const & p)
+ {
+ return static_cast<mutual_ptr_base &>(base::operator = (p));
+ }
+ };
+
+
+} // namespace sh
+
+} // namespace detail
+
+} // namespace boost
+
+
+#endif

Deleted: /sandbox/mm_ptr/boost/detail/sh_owned_base.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/detail/sh_owned_base.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,88 +0,0 @@
-/**
- @file
- Boost sh_owned_base.hpp header file.
-
- @note
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_DETAIL_SP_OWNED_BASE_HPP_INCLUDED
-#define BOOST_DETAIL_SP_OWNED_BASE_HPP_INCLUDED
-
-// Me
-#define BOOST_SP_DISABLE_THREADS
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-//
-// detail/sh_owned_base.hpp
-//
-// Copyright 2008 Phil Bouchard
-//
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-
-#include <boost/config.hpp>
-
-#if defined( BOOST_SP_DISABLE_THREADS )
-
-# include <boost/detail/sh_owned_base_nt.hpp>
-
-#elif defined( BOOST_SP_USE_PTHREADS )
-
-# include <boost/detail/sh_owned_base_pt.hpp>
-
-#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
-
-# include <boost/detail/sh_owned_base_gcc_x86.hpp>
-
-//~ #elif defined( __MWERKS__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
-
-//~ # include <boost/detail/sh_owned_base_cw_x86.hpp>
-
-#elif defined( __GNUC__ ) && defined( __ia64__ ) && !defined( __INTEL_COMPILER )
-
-# include <boost/detail/sh_owned_base_gcc_ia64.hpp>
-
-#elif defined( __MWERKS__ ) && defined( __POWERPC__ )
-
-# include <boost/detail/sh_owned_base_cw_ppc.hpp>
-
-#elif defined( __GNUC__ ) && ( defined( __powerpc__ ) || defined( __ppc__ ) )
-
-# include <boost/detail/sh_owned_base_gcc_ppc.hpp>
-
-#elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
-
-# include <boost/detail/sh_owned_base_w32.hpp>
-
-#elif !defined( BOOST_HAS_THREADS )
-
-# include <boost/detail/sh_owned_base_nt.hpp>
-
-#elif defined( BOOST_HAS_PTHREADS )
-
-# include <boost/detail/sh_owned_base_pt.hpp>
-
-#else
-
-// Use #define BOOST_DISABLE_THREADS to avoid the error
-# error Unrecognized threading platform
-
-#endif
-
-#endif // #ifndef BOOST_DETAIL_SH_OWNED_BASE_HPP_INCLUDED

Deleted: /sandbox/mm_ptr/boost/detail/sh_owned_base_gcc_x86.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/detail/sh_owned_base_gcc_x86.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,159 +0,0 @@
-#ifndef BOOST_DETAIL_SH_OWNED_BASE_GCC_X86_HPP_INCLUDED
-#define BOOST_DETAIL_SH_OWNED_BASE_GCC_X86_HPP_INCLUDED
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-//
-// detail/sh_owned_base_gcc_x86.hpp - g++ on 486+ or AMD64
-//
-// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
-// Copyright 2004-2005 Peter Dimov
-//
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-//
-// Lock-free algorithm by Alexander Terekhov
-//
-// Thanks to Ben Hitchings for the #weak + (#shared != 0)
-// formulation
-//
-
-#include <boost/detail/sp_owned_base_gcc_x86.hpp>
-
-#include <typeinfo>
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-inline int atomic_exchange_and_add( int * pw, int dv )
-{
- // int r = *pw;
- // *pw += dv;
- // return r;
-
- int r;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "xadd %1, %0":
- "=m"( *pw ), "=r"( r ): // outputs (%0, %1)
- "m"( *pw ), "1"( dv ): // inputs (%2, %3 == %1)
- "memory", "cc" // clobbers
- );
-
- return r;
-}
-
-inline void atomic_increment( int * pw )
-{
- //atomic_exchange_and_add( pw, 1 );
-
- __asm__
- (
- "lock\n\t"
- "incl %0":
- "=m"( *pw ): // output (%0)
- "m"( *pw ): // input (%1)
- "cc" // clobbers
- );
-}
-
-inline int atomic_conditional_increment( int * pw )
-{
- // int rv = *pw;
- // if( rv != 0 ) ++*pw;
- // return rv;
-
- int rv, tmp;
-
- __asm__
- (
- "movl %0, %%eax\n\t"
- "0:\n\t"
- "test %%eax, %%eax\n\t"
- "je 1f\n\t"
- "movl %%eax, %2\n\t"
- "incl %2\n\t"
- "lock\n\t"
- "cmpxchgl %2, %0\n\t"
- "jne 0b\n\t"
- "1:":
- "=m"( *pw ), "=&a"( rv ), "=&r"( tmp ): // outputs (%0, %1, %2)
- "m"( *pw ): // input (%3)
- "cc" // clobbers
- );
-
- return rv;
-}
-
-class owned_base : public sp_counted_base
-{
-private:
-
- owned_base( owned_base const & );
- owned_base & operator= ( owned_base const & );
-
- long seg_count_; // #set
- owned_base * po_;
- owned_base ** ppo_;
-
-public:
-
- owned_base(): seg_count_( 1 ), po_( this ), ppo_( po_ )
- {
- }
-
- void add_own_copy()
- {
- atomic_increment( &(*ppo_)->seg_count_ );
- }
-
- bool add_own_lock() // true on success
- {
- return atomic_conditional_increment( &(*ppo_)->seg_count_ ) != 0;
- }
-
- void release() // nothrow
- {
- if( atomic_exchange_and_add( &(*ppo_)->seg_count_, -1 ) == 1 )
- {
- dispose();
- }
- }
-
- long seg_count() const // nothrow
- {
- return static_cast<int const volatile &>( (*ppo_)->seg_count_ );
- }
-
- owned_base * owner() const // nothrow
- {
- return (*ppo_);
- }
-
- void owner(owned_base * p) // nothrow
- {
- (*ppo_) = p;
- }
-};
-
-} // namespace sh
-
-} // namespace detail
-
-} // namespace boost
-
-#endif // #ifndef BOOST_DETAIL_SH_OWNED_BASE_GCC_X86_HPP_INCLUDED

Deleted: /sandbox/mm_ptr/boost/detail/sh_owned_base_nt.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/detail/sh_owned_base_nt.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,335 +0,0 @@
-/**
- @file
- Boost detail/sh_owned_base_nt.hpp header file.
-
- @note
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_DETAIL_SH_OWNED_BASE_NT_HPP_INCLUDED
-#define BOOST_DETAIL_SH_OWNED_BASE_NT_HPP_INCLUDED
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <stack>
-#include <limits>
-
-// Bypassing linkage by default
-#define BOOST_SH_DISABLE_THREADS
-
-#include <boost/thread.hpp>
-#include <boost/thread/tss.hpp>
-#include <boost/pool/pool.hpp>
-#include <boost/pool/pool_alloc.hpp>
-#include <boost/numeric/interval.hpp>
-#include <boost/type_traits/is_array.hpp>
-#include <boost/type_traits/remove_extent.hpp>
-#include <boost/type_traits/has_trivial_destructor.hpp>
-#include <boost/preprocessor/control/expr_if.hpp>
-#include <boost/preprocessor/arithmetic/inc.hpp>
-#include <boost/preprocessor/punctuation/comma_if.hpp>
-#include <boost/preprocessor/repetition/repeat.hpp>
-#include <boost/preprocessor/repetition/repeat_from_to.hpp>
-#include <boost/smart_ptr/detail/sp_counted_base.hpp>
-
-#include <boost/detail/intrusive_list.hpp>
-#include <boost/detail/intrusive_stack.hpp>
-#include <boost/detail/sh_utility.h>
-
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-
-class mm_header;
-class owned_base;
-
-
-/**
- Allocator wrapper tracking allocations.
-
- Pool where all pointee objects are allocated and tracks memory blocks for later enlisting & marking the @c mm_header the pointee object belongs to.
-*/
-
-struct pool : boost::pool<>
-{
- typedef std::list< numeric::interval<long>, fast_pool_allocator< numeric::interval<long> > > pool_lii; /**< Syntax helper. */
-
-#ifndef BOOST_SH_DISABLE_THREADS
- thread_specific_ptr<pool_lii> plii_; /**< Thread specific list of memory boundaries. */
-#else
- std::auto_ptr<pool_lii> plii_; /**< List of memory boundaries. */
-#endif
-
-
- /**
- Initialization of a pool instance.
- */
-
- pool() : boost::pool<>(1)
- {
- plii_.reset(new pool_lii());
- }
-
-
- /**
- Tracks the memory boundaries where a pointer belongs to. Also gets rid of the boundaries that were allocated before the pointer was allocated.
-
- @param p Pointer that is being tracked.
- @return Pointer to the pointee object where @c p belongs to.
- */
-
- owned_base * top(void * p)
- {
- pool_lii::reverse_iterator i;
-
- for (i = plii_->rbegin(); i != plii_->rend(); i ++)
- if (in((long)(p), * i))
- break;
-
- plii_->erase(i.base(), plii_->end());
-
- return (owned_base *)(plii_->rbegin()->lower());
- }
-
-
- /**
- Pointee object allocator and stacking of the newly allocated memory boundary.
-
- @param s Size of the memory block to allocate.
- @return Address of the newly allocated block.
- */
-
- void * allocate(std::size_t s)
- {
- void * p = ordered_malloc(s);
-
- plii_->push_back(numeric::interval<long>((long) p, long((char *)(p) + s)));
-
- return p;
- }
-
-
- /**
- Pointee object deallocator and removal of the boundaries that were allocated before the pointer was allocated.
-
- @param p Address of the memory block to deallocate.
- @param s Size of the memory block.
- */
-
- void deallocate(void * p, std::size_t s)
- {
- pool_lii::reverse_iterator i;
-
- for (i = plii_->rbegin(); i != plii_->rend(); i ++)
- if (in((long)(p), * i))
- break;
-
- plii_->erase(i.base(), plii_->end());
- ordered_free(p, s);
- }
-};
-
-
-/**
- Root class of all pointee objects.
-*/
-
-class owned_base : public sp_counted_base
-{
-public:
- bool init_; /**< Flag marking initialization of the pointee object to its @c mm_header . */
-
- intrusive_stack ptrs_; /**< Stack of all @c mm_ptr s on the heap that will later need to be initlialized to a specific @c mm_header . */
- intrusive_list inits_; /**< List of all pointee objects that will later need to be initlialized to a specific @c mm_header .*/
-
- intrusive_list::node mm_tag_; /**< Tag used to enlist to @c mm_header::elements_ . */
- intrusive_list::node init_tag_; /**< Tag used to enlist to @c owned_base::inits_ . */
-
-
- owned_base() : init_(false)
- {
- inits_.push_back(& init_tag_);
- }
-
- static pool pool_; /**< Pool where all pointee objects are allocated from. */
-
-protected:
- virtual void dispose() {} /**< dummy */
- virtual void * get_deleter( std::type_info const & ti ) { return 0; } /**< dummy */
-};
-
-
-pool owned_base::pool_;
-
-
-#define TEMPLATE_DECL(z, n, text) BOOST_PP_COMMA_IF(n) typename T ## n
-#define ARGUMENT_DECL(z, n, text) BOOST_PP_COMMA_IF(n) T ## n const & t ## n
-#define PARAMETER_DECL(z, n, text) BOOST_PP_COMMA_IF(n) t ## n
-
-#define CONSTRUCT_OWNED(z, n, text) \
- template <BOOST_PP_REPEAT(n, TEMPLATE_DECL, 0)> \
- text(BOOST_PP_REPEAT(n, ARGUMENT_DECL, 0)) : elem_(BOOST_PP_REPEAT(n, PARAMETER_DECL, 0)) {}
-
-/**
- Object wrapper.
-*/
-
-template <typename T>
- class mm : public owned_base
- {
- typedef T data_type;
-
- T elem_; /**< Pointee object. @note Needs alignas<long>. */
-
- public:
- class roofof;
- friend class roofof;
-
- mm() : elem_()
- {
- }
-
- BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_OWNED, mm)
-
-
- /**
- @return Pointee object address.
- */
-
- data_type * element() { return & elem_; }
- operator data_type & () { return * element(); }
- operator data_type const & () const { return * element(); }
-
- virtual ~mm()
- {
- dispose();
- }
-
- public:
- /**
- Cast operator used by @c mm_ptr_common::header() .
- */
-
- class roofof
- {
- mm * p_; /**< Address of the @c mm the element belong to. */
-
- public:
- /**
- Casts from a @c data_type to its parent @c mm object.
-
- @param p Address of a @c data_type member object to cast from.
- */
-
- roofof(data_type * p) : p_(sh::roofof((data_type mm::*)(& mm::elem_), p)) {}
-
-
- /**
- @return Address of the parent @c mm object.
- */
-
- operator mm * () const { return p_; }
- };
-
-
- /**
- Allocates a new @c mm using the pool.
-
- @param s Size of the @c mm .
- @return Pointer of the new memory block.
- */
-
- void * operator new (size_t s)
- {
- return pool_.allocate(s);
- }
-
-
- /**
- Deallocates a @c mm from the pool.
-
- @param p Address of the @c mm to deallocate.
- */
-
- void operator delete (void * p)
- {
- pool_.deallocate(p, sizeof(mm));
- }
- };
-
-
-template <>
- class mm<void> : public owned_base
- {
- typedef void data_type;
-
- long elem_; /**< Pointee placeholder. @note Aligned. */
-
- mm();
-
- public:
- class roofof;
- friend class roofof;
-
- data_type * element() { return & elem_; }
-
- virtual ~mm() {}
- virtual void dispose() {}
-
- virtual void * get_deleter( std::type_info const & ti ) {}
-
- public:
- /**
- Cast operator used by @c mm_ptr_common::header() .
- */
-
- class roofof
- {
- mm * p_; /**< Address of the @c mm the element belong to. */
-
- public:
- /**
- Casts from a @c data_type to its parent @c mm object.
-
- @param p Address of a @c data_type member object to cast from.
- */
-
- roofof(data_type * p) : p_(sh::roofof((long mm::*)(& mm::elem_), static_cast<long *>(p))) {}
-
-
- /**
- @return Address of the parent @c mm object.
- */
-
- operator mm * () const { return p_; }
- };
- };
-
-
-} // namespace sh
-
-} // namespace detail
-
-} // namespace boost
-
-
-#endif // #ifndef BOOST_DETAIL_SH_OWNED_BASE_NT_HPP_INCLUDED

Deleted: /sandbox/mm_ptr/boost/detail/sh_owned_impl.h
==============================================================================
--- /sandbox/mm_ptr/boost/detail/sh_owned_impl.h 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,231 +0,0 @@
-/**
- @file
- Boost sh_owned_impl.h header file.
-
- @note
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_DETAIL_SH_OWNED_IMPL_HPP_INCLUDED
-#define BOOST_DETAIL_SH_OWNED_IMPL_HPP_INCLUDED
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-//
-// detail/sh_owned_impl.hpp
-//
-// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
-// Copyright 2008 Philippe Bouchard
-//
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-
-#include <boost/config.hpp>
-
-#if defined(BOOST_SP_USE_STD_ALLOCATOR) && defined(BOOST_SP_USE_QUICK_ALLOCATOR)
-# error BOOST_SP_USE_STD_ALLOCATOR and BOOST_SP_USE_QUICK_ALLOCATOR are incompatible.
-#endif
-
-#include <boost/checked_delete.hpp>
-#include <boost/detail/sh_owned_base.hpp>
-
-#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
-#include <boost/detail/quick_allocator.hpp>
-#endif
-
-#if defined(BOOST_SP_USE_STD_ALLOCATOR)
-#include <memory> // std::allocator
-#endif
-
-#include <typeinfo> // std::type_info in get_deleter
-#include <cstddef> // std::size_t
-
-namespace boost
-{
-
-#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
-
-void sh_scalar_constructor_hook( void * px, std::size_t size, void * pn );
-void sh_scalar_destructor_hook( void * px, std::size_t size, void * pn );
-
-#endif
-
-namespace detail
-{
-
-namespace sh
-{
-
-template<class X> class owned_impl_p: public owned<X>
-{
-private:
-
- owned_impl_p( owned_impl_p const & );
- owned_impl_p & operator= ( owned_impl_p const & );
-
- typedef owned_impl_p<X> this_type;
-
-public:
-
- virtual void dispose() // nothrow
- {
-#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::scalar_destructor_hook( p_, sizeof(X), this );
-#endif
- }
-
- virtual void * get_deleter( std::type_info const & )
- {
- return 0;
- }
-
-#if defined(BOOST_SP_USE_STD_ALLOCATOR)
-
- void * operator new( std::size_t )
- {
- return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
- }
-
- void operator delete( void * p )
- {
- std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
- }
-
-#endif
-
-#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
-
- void * operator new( std::size_t )
- {
- return quick_allocator<this_type>::alloc();
- }
-
- void operator delete( void * p )
- {
- quick_allocator<this_type>::dealloc( p );
- }
-
-#endif
-};
-
-//
-// Borland's Codeguard trips up over the -Vx- option here:
-//
-#ifdef __CODEGUARD__
-# pragma option push -Vx-
-#endif
-
-template<class P, class D> class owned_impl_pd: public owned<X>
-{
-private:
-
- D d_; // copy constructor must not throw
-
- owned_impl_pd( owned_impl_pd const & );
- owned_impl_pd & operator= ( owned_impl_pd const & );
-
- typedef owned_impl_pd<P, D> this_type;
-
-public:
-
- // pre: d(p) must not throw
-
- owned_impl_pd( D d ): d_(d)
- {
- }
-
- virtual void dispose() // nothrow
- {
- d_( p_ );
- }
-
- virtual void * get_deleter( std::type_info const & ti )
- {
- return ti == typeid(D)? &d_: 0;
- }
-
-#if defined(BOOST_SP_USE_STD_ALLOCATOR)
-
- void * operator new( std::size_t )
- {
- return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
- }
-
- void operator delete( void * p )
- {
- std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
- }
-
-#endif
-
-#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
-
- void * operator new( std::size_t )
- {
- return quick_allocator<this_type>::alloc();
- }
-
- void operator delete( void * p )
- {
- quick_allocator<this_type>::dealloc( p );
- }
-
-#endif
-};
-
-template<class P, class D, class A> class owned_impl_pda: public owned<X>
-{
-private:
-
- D d_; // copy constructor must not throw
- A a_; // copy constructor must not throw
-
- owned_impl_pda( owned_impl_pda const & );
- owned_impl_pda & operator= ( owned_impl_pda const & );
-
- typedef owned_impl_pda<P, D, A> this_type;
-
-public:
-
- // pre: d( p ) must not throw
-
- owned_impl_pda( D d, A a ): d_( d ), a_( a )
- {
- }
-
- virtual void dispose() // nothrow
- {
- d_( p_ );
- }
-
- virtual void * get_deleter( std::type_info const & ti )
- {
- return ti == typeid( D )? &d_: 0;
- }
-};
-
-#ifdef __CODEGUARD__
-# pragma option pop
-#endif
-
-} // namespace sh
-
-} // namespace detail
-
-} // namespace boost
-
-#endif // #ifndef BOOST_DETAIL_SP_OWNED_IMPL_HPP_INCLUDED

Deleted: /sandbox/mm_ptr/boost/detail/sh_utility.h
==============================================================================
--- /sandbox/mm_ptr/boost/detail/sh_utility.h 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,100 +0,0 @@
-/**
- @file
- Boost sh_utility.h header file.
-
- @note
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_DETAIL_SH_UTILITY_H_INCLUDED
-#define BOOST_DETAIL_SH_UTILITY_H_INCLUDED
-
-
-#include <boost/type_traits/remove_const.hpp>
-#include <boost/type_traits/remove_volatile.hpp>
-#include <boost/type_traits/is_polymorphic.hpp>
-#include <boost/type_traits/type_with_alignment.hpp>
-
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-
-/**
- Block address helper.
-
- Returns the absolute address of a non-polymorphic object.
-
- @note
- Expects template value given by @sa is_polymorphic<>::value.
-*/
-
-template <bool>
- struct rootof
- {
- template <typename U>
- static void * get(U * a_p)
- {
- typedef typename remove_const<typename remove_volatile<U>::type>::type unqualified_type;
-
- return static_cast<void *>(const_cast<unqualified_type *>(a_p));
- }
- };
-
-
-/**
- Block address helper.
-
- Returns the absolute address of a polymorphic object.
-*/
-
-template <>
- struct rootof<true>
- {
- template <typename U>
- static void * get(U * a_p)
- {
- typedef typename remove_const<typename remove_volatile<U>::type>::type unqualified_type;
-
- return dynamic_cast<void *>(const_cast<unqualified_type *>(a_p));
- }
- };
-
-
-/**
- Class member upshift.
-
- Finds the address of a class given member credentials.
-*/
-
-template <typename T, typename U>
- T * roofof(U T::* q, U * p)
- {
- typedef typename remove_const<typename remove_volatile<U>::type>::type unqualified_type;
-
- return static_cast<T *>(static_cast<void *>(static_cast<char *>(static_cast<void *>(const_cast<unqualified_type *>(p))) - ptrdiff_t(static_cast<char *>(static_cast<void *>(const_cast<unqualified_type *>(& ((T *)(0)->* q)))) - (char *)(0))));
- }
-
-
-} // namespace sh
-
-} // namespace detail
-
-} // namespace boost
-
-
-#endif // #ifndef BOOST_DETAIL_SH_UTILITY_H_INCLUDED

Deleted: /sandbox/mm_ptr/boost/mm_allocator.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/mm_allocator.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,127 +0,0 @@
-/**
- @file
- Boost mm_allocator.hpp header file.
-
- @note
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-*/
-
-
-#ifndef BOOST_SHIFTED_ALLOCATOR_HPP_INCLUDED
-#define BOOST_SHIFTED_ALLOCATOR_HPP_INCLUDED
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <boost/mm_ptr.hpp>
-
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-
-/**
- STL compliant allocator.
-
- @note
- Default object contructor is called inside allocate() to save temporaries.
-*/
-
-template <typename T>
- class mm_allocator
- {
- typedef T element_type;
-
- public:
- typedef mm<T> value_type;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef T * pointer;
- typedef const T * const_pointer;
- typedef element_type & reference;
- typedef const element_type & const_reference;
-
- template <typename U>
- struct rebind
- {
- typedef mm_allocator<U> other;
- };
-
- mm_allocator() throw() {}
- mm_allocator(const mm_allocator &) throw() {}
- template <typename U>
- mm_allocator(const mm_allocator<U> &) throw() {}
-
- ~mm_allocator() throw() {}
- pointer address(reference x) const { return & x; }
- const_pointer address(const_reference x) const { return & x; }
-
- size_type max_size() const throw()
- {
- return size_t(-1) / sizeof(T);
- }
-
- pointer allocate(size_type s, const void * = 0)
- {
- //value_type * p = (value_type *) value_type::operator new(sizeof(value_type));
- value_type * p = new value_type();
-
- return p->element();
- }
-
- void construct(pointer p, const T & x)
- {
- //::new (p) owned_base;
- //::new (p->element()) T(x);
- }
-
- void destroy(pointer p)
- {
- p->reset();
- }
-
- void deallocate(pointer p, size_type)
- {
- }
- };
-
-template <typename T>
- inline bool operator == (const mm_allocator<T> &, const mm_allocator<T> &)
- {
- return true;
- }
-
-template <typename T>
- inline bool operator != (const mm_allocator<T> &, const mm_allocator<T> &)
- {
- return false;
- }
-
-
-} // namespace sh
-
-} // namespace detail
-
-using detail::sh::mm_allocator;
-using detail::sh::operator ==;
-using detail::sh::operator !=;
-
-} // namespace boost
-
-#endif // #ifndef BOOST_SHIFTED_ALLOCATOR_HPP_INCLUDED

Deleted: /sandbox/mm_ptr/boost/mm_ptr.hpp
==============================================================================
--- /sandbox/mm_ptr/boost/mm_ptr.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,442 +0,0 @@
-/**
- @file
- Boost mm_ptr.hpp header file.
-
- @author
- Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
-
- @note
- Distributed under the Boost Software License, Version 1.0.
-
- See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-
- See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
-
-
- Thanks to: Steven Watanabe <watanabesj_at_[hidden]>
-*/
-
-
-#ifndef BOOST_DETAIL_SH_RTCMM_H_INCLUDED
-#define BOOST_DETAIL_SH_RTCMM_H_INCLUDED
-
-
-#if defined(_MSC_VER)
-#pragma warning( push )
-#pragma warning( disable : 4355 )
-
-#include <new.h>
-#endif
-
-#include <iostream>
-#include <boost/pool/pool_alloc.hpp>
-#include <boost/type_traits/add_pointer.hpp>
-
-#include <boost/detail/intrusive_list.hpp>
-#include <boost/detail/intrusive_stack.hpp>
-#include <boost/detail/sh_utility.h>
-#include <boost/detail/mm_ptr_base.hpp>
-
-
-namespace boost
-{
-
-namespace detail
-{
-
-namespace sh
-{
-
-
-class owned_base;
-
-
-/**
- Set header.
-
- Proxy object used to count the number of pointers from the stack are referencing pointee objects belonging to the same @c mm_header .
-*/
-
-class mm_header
-{
- long count_; /**< Count of the number of pointers from the stack referencing the same @c mm_header .*/
- mutable mm_header * redir_; /**< Redirection in the case of an union multiple @c mm_header s.*/
-
- intrusive_list includes_; /**< List of all @c mm_header s of an union. */
- intrusive_list elements_; /**< List of all pointee objects belonging to a @c mm_header . */
-
- static fast_pool_allocator<mm_header> pool_; /**< Pool where all @c mm_header s are allocated. */
-
-public:
- bool destroy_; /**< Destruction sequence initiated. */
- intrusive_list::node tag_; /**< Tag used to enlist to @c mm_header::includes_ . */
-
-
- /**
- Initialization of a single @c mm_header .
- */
-
- mm_header() : count_(1), redir_(this), destroy_(false)
- {
- includes_.push_back(& tag_);
- }
-
-
- /**
- Release of a @c mm_header with possible destruction of all its elements and other @c mm_header s unified to it.
-
- @return True if the @c mm_header was released.
- */
-
- bool release()
- {
- mm_header * p = redir();
-
- if (-- p->count_ == 0)
- {
- p->destroy_ = true;
- for (intrusive_list::iterator<owned_base, & owned_base::mm_tag_> i; i = p->elements_.begin(), i != p->elements_.end(); )
- delete &* i;
- p->destroy_ = false;
-
- for (intrusive_list::iterator<mm_header, & mm_header::tag_> i = p->includes_.begin(), j; j = i, i != p->includes_.end(); i = j)
- {
- ++ j;
- if (&* i != this && &* i != p)
- delete &* i;
- }
-
- if (p != this)
- delete p;
-
- return true;
- }
-
- return false;
- }
-
-
- /**
- Recursive search for the @c mm_header header of an union.
-
- @return @c mm_header responsible for managing the counter of an union.
- */
-
- mm_header * redir() const
- {
- if (redir_ == this) return redir_;
- else return redir_ = redir_->redir();
- }
-
-
- /**
- Unification with a new @c mm_header .
-
- @param p New @c mm_header to unify with.
- */
-
- void redir(mm_header * p)
- {
- if (redir_ != p->redir())
- {
- redir_ = p->redir();
- redir_->includes_.merge(includes_);
- redir_->elements_.merge(elements_);
- redir_->count_ += count_;
- }
- }
-
-
- /**
- Finds the elements constituting one or many @c mm_header s unified.
-
- @return List of all elements.
- */
-
- intrusive_list * elements() const
- {
- return & redir()->elements_;
- }
-
-
- /**
- Allocates a new @c mm_header using the fast pool allocator.
-
- @param s Size of the @c mm_header .
- @return Pointer of the new memory block.
- */
-
- void * operator new (size_t s)
- {
- return pool_.allocate(s);
- }
-
-
- /**
- Placement new.
-
- @param s Size of the @c mm_header .
- @param p Address to construct the @c mm_header on.
- @return Address to construct the @c mm_header on.
- */
-
- void * operator new (size_t s, mm_header * p)
- {
- return p;
- }
-
-
- /**
- Deallocates a @c mm_header from the fast pool allocator.
-
- @param p Address of the @c mm_header to deallocate.
- */
-
- void operator delete (void * p)
- {
- pool_.deallocate(static_cast<mm_header *>(p), sizeof(mm_header));
- }
-};
-
-
-fast_pool_allocator<mm_header> mm_header::pool_;
-
-
-/**
- Deterministic memory manager of constant complexity.
-
- Complete memory management utility on top of standard reference counting.
-*/
-
-template <typename T>
- class mm_ptr : public mm_ptr_base<T>
- {
- template <typename> friend class mm_ptr;
-
- typedef mm_ptr_base<T> base;
-
- using base::share;
- using base::po_;
-
- union
- {
- mm_header * ps_; /**< Pointer to the @c mm_header node @c mm_ptr<> belongs to. */
- intrusive_stack::node pn_; /**< Tag used for enlisting a pointer on the heap to later share the @c mm_header it belongs to. */
- };
-
- public:
- typedef T value_type;
- typedef mm<value_type> element_type;
-
-
- /**
- Initialization of a pointer living on the stack or proper enlistment if living on the heap.
- */
-
- mm_ptr() : ps_(0)
- {
- if (! owned_base::pool_.is_from(this))
- ps_ = new mm_header();
- else
- owned_base::pool_.top(this)->ptrs_.push(& pn_);
- }
-
-
- /**
- Initialization of a pointer living on the stack or proper enlistment if living on the heap.
-
- @param p New pointee object to manage.
- */
-
- template <typename V>
- mm_ptr(mm<V> * p) : base(p)
- {
- if (! owned_base::pool_.is_from(this))
- {
- ps_ = new mm_header();
-
- init(p);
- }
- else
- {
- owned_base::pool_.top(this)->ptrs_.push(& pn_);
- owned_base::pool_.top(this)->inits_.merge(p->inits_);
- }
- }
-
-
- /**
- Initialization of a pointer living on the stack or proper enlistment if living on the heap.
-
- @param p New pointer to manage.
- */
-
- template <typename V>
- mm_ptr(mm_ptr<V> const & p) : base(p)
- {
- if (! owned_base::pool_.is_from(this))
- ps_ = new mm_header();
- else
- owned_base::pool_.top(this)->ptrs_.push(& pn_);
-
- ps_->redir(p.ps_);
- }
-
-
- /**
- Initialization of a pointer living on the stack or proper enlistment if living on the heap.
-
- @param p New pointer to manage.
- */
-
- mm_ptr(mm_ptr<T> const & p) : base(p)
- {
- if (! owned_base::pool_.is_from(this))
- ps_ = new mm_header();
- else
- owned_base::pool_.top(this)->ptrs_.push(& pn_);
-
- ps_->redir(p.ps_);
- }
-
-
- /**
- Assignment & union of 2 @c mm_header s if the pointee resides a different @c mm_header.
-
- @param p New pointee object to manage.
- */
-
- template <typename V>
- mm_ptr & operator = (mm<V> * p)
- {
- release(false);
-
- init(p);
-
- base::operator = (p);
-
- return * this;
- }
-
-
- /**
- Assignment & union of 2 @c mm_header s if the pointee resides a different @c mm_header.
-
- @param p New pointer to manage.
- */
-
- template <typename V>
- mm_ptr & operator = (mm_ptr<V> const & p)
- {
- if (ps_->redir() != p.ps_->redir())
- {
- release(false);
-
- ps_->redir(p.ps_);
- }
- base::operator = (p);
-
- return * this;
- }
-
-
- /**
- Assignment & union of 2 @c mm_header s if the pointee resides a different @c mm_header.
-
- @param p New pointer to manage.
- */
-
- mm_ptr & operator = (mm_ptr<T> const & p)
- {
- return operator = <T>(p);
- }
-
- void reset()
- {
- release(false);
- }
-
- ~mm_ptr()
- {
- if (ps_->destroy_)
- base::po_ = 0;
- else
- release(true);
- }
-
- private:
- /**
- Release of the pointee object with or without destroying the entire @c mm_header it belongs to.
-
- @param d Destroy (true) or reuse (false) the @c mm_header it is releasing.
- */
-
- void release(bool d)
- {
- if (! owned_base::pool_.is_from(this))
- if (ps_->release())
- {
- base::po_ = 0;
-
- if (! d)
- new (ps_) mm_header();
- else
- delete ps_;
- }
- else
- {
- base::reset();
-
- if (! d)
- ps_ = new mm_header();
- }
- else
- base::reset();
- }
-
-
- /**
- Enlist & initialize pointee objects belonging to the same @c mm_header . This initialization occurs when a pointee object is affected to the first pointer living on the stack it encounters.
-
- @param p Pointee object to initialize.
- */
-
- void init(owned_base * p)
- {
- if (p->init_)
- return;
-
- // iterate memory blocks
- for (intrusive_list::iterator<owned_base, & owned_base::init_tag_> i = p->inits_.begin(); i != p->inits_.end(); ++ i)
- {
- i->init_ = true;
- ps_->elements()->push_back(& i->mm_tag_);
-
- // iterate mm_ptr elements
- for (intrusive_stack::iterator<mm_ptr, & mm_ptr::pn_> j = i->ptrs_.begin(), k; k = j, j != i->ptrs_.end(); j = k)
- {
- ++ k;
- j->ps_ = ps_;
- }
- }
- }
- };
-
-
-} // namespace sh
-
-} // namespace detail
-
-using detail::sh::mm_ptr;
-using detail::sh::mm;
-
-} // namespace boost
-
-
-#if defined(_MSC_VER)
-#pragma warning( pop )
-#endif
-
-
-#endif // #ifndef BOOST_DETAIL_SH_RTCMM_H_INCLUDED

Added: sandbox/mutual_ptr/boost/mutual_allocator.hpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/boost/mutual_allocator.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,127 @@
+/**
+ @file
+ Boost mutual_allocator.hpp header file.
+
+ @note
+ Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
+
+ Distributed under the Boost Software License, Version 1.0.
+
+ See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+
+ See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
+*/
+
+
+#ifndef BOOST_MUTUAL_ALLOCATOR_HPP_INCLUDED
+#define BOOST_MUTUAL_ALLOCATOR_HPP_INCLUDED
+
+// MS compatible compilers support #pragma once
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/mutual_ptr.hpp>
+
+
+namespace boost
+{
+
+namespace detail
+{
+
+namespace sh
+{
+
+
+/**
+ STL compliant allocator.
+
+ @note
+ Default object contructor is called inside allocate() to save temporaries.
+*/
+
+template <typename T>
+ class mutual_allocator
+ {
+ typedef T element_type;
+
+ public:
+ typedef mutual<T> value_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T * pointer;
+ typedef const T * const_pointer;
+ typedef element_type & reference;
+ typedef const element_type & const_reference;
+
+ template <typename U>
+ struct rebind
+ {
+ typedef mutual_allocator<U> other;
+ };
+
+ mutual_allocator() throw() {}
+ mutual_allocator(const mutual_allocator &) throw() {}
+ template <typename U>
+ mutual_allocator(const mutual_allocator<U> &) throw() {}
+
+ ~mutual_allocator() throw() {}
+ pointer address(reference x) const { return & x; }
+ const_pointer address(const_reference x) const { return & x; }
+
+ size_type max_size() const throw()
+ {
+ return size_t(-1) / sizeof(T);
+ }
+
+ pointer allocate(size_type s, const void * = 0)
+ {
+ //value_type * p = (value_type *) value_type::operator new(sizeof(value_type));
+ value_type * p = new value_type();
+
+ return p->element();
+ }
+
+ void construct(pointer p, const T & x)
+ {
+ //::new (p) owned_base;
+ //::new (p->element()) T(x);
+ }
+
+ void destroy(pointer p)
+ {
+ p->reset();
+ }
+
+ void deallocate(pointer p, size_type)
+ {
+ }
+ };
+
+template <typename T>
+ inline bool operator == (const mutual_allocator<T> &, const mutual_allocator<T> &)
+ {
+ return true;
+ }
+
+template <typename T>
+ inline bool operator != (const mutual_allocator<T> &, const mutual_allocator<T> &)
+ {
+ return false;
+ }
+
+
+} // namespace sh
+
+} // namespace detail
+
+using detail::sh::mutual_allocator;
+using detail::sh::operator ==;
+using detail::sh::operator !=;
+
+} // namespace boost
+
+#endif // #ifndef BOOST_SHIFTED_ALLOCATOR_HPP_INCLUDED

Added: sandbox/mutual_ptr/boost/mutual_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/boost/mutual_ptr.hpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,451 @@
+/**
+ @file
+ Boost mutual_ptr.hpp header file.
+
+ @author
+ Copyright (c) 2008 Phil Bouchard <phil_at_[hidden]>.
+
+ @note
+ Distributed under the Boost Software License, Version 1.0.
+
+ See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+
+ See http://www.boost.org/libs/smart_ptr/doc/index.html for documentation.
+
+
+ Thanks to: Steven Watanabe <watanabesj_at_[hidden]>
+*/
+
+
+#ifndef BOOST_DETAIL_MUTUAL_PTR_INCLUDED
+#define BOOST_DETAIL_MUTUAL_PTR_INCLUDED
+
+
+#if defined(_MSC_VER)
+#pragma warning( push )
+#pragma warning( disable : 4355 )
+
+#include <new.h>
+#endif
+
+#include <iostream>
+#include <boost/pool/pool_alloc.hpp>
+#include <boost/type_traits/add_pointer.hpp>
+#include <boost/smart_ptr/detail/atomic_count.hpp>
+#include <boost/thread/thread.hpp>
+
+#include <boost/detail/intrusive_list.hpp>
+#include <boost/detail/intrusive_stack.hpp>
+#include <boost/detail/roofof.hpp>
+#include <boost/detail/mutual_ptr_base.hpp>
+
+
+namespace boost
+{
+
+namespace detail
+{
+
+namespace sh
+{
+
+
+class mutual_base;
+
+
+/**
+ Set header.
+
+ Proxy object used to count the number of pointers from the stack are referencing pointee objects belonging to the same @c mutual_header .
+*/
+
+class mutual_header
+{
+ typedef detail::atomic_count count_type;
+
+ count_type count_; /**< Count of the number of pointers from the stack referencing the same @c mutual_header .*/
+ mutable mutual_header * redir_; /**< Redirection in the case of an union multiple sets.*/
+
+ intrusive_list includes_; /**< List of all sets of an union. */
+ intrusive_list elements_; /**< List of all pointee objects belonging to a @c mutual_header . */
+
+ static fast_pool_allocator<mutual_header> pool_;/**< Pool where all sets are allocated. */
+
+public:
+#ifndef BOOST_DISABLE_THREADS
+ mutex mutex_;
+#endif
+ bool destroy_; /**< Destruction sequence initiated. */
+ intrusive_list::node tag_; /**< Tag used to enlist to @c mutual_header::includes_ . */
+
+
+ /**
+ Initialization of a single @c mutual_header .
+ */
+
+ mutual_header() : count_(1), redir_(this), destroy_(false)
+ {
+ includes_.push_back(& tag_);
+ }
+
+
+ /**
+ Release of a @c mutual_header with possible destruction of all its elements and other sets unified to it.
+
+ @return True if the @c mutual_header was released.
+ */
+
+ bool release()
+ {
+ mutual_header * p = redir();
+
+ if (-- p->count_ == 0)
+ {
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(mutex_);
+#endif
+ p->destroy_ = true;
+ for (intrusive_list::iterator<mutual_base, & mutual_base::mutual_tag_> i; i = p->elements_.begin(), i != p->elements_.end(); )
+ delete &* i;
+ p->destroy_ = false;
+
+ for (intrusive_list::iterator<mutual_header, & mutual_header::tag_> i = p->includes_.begin(), j; j = i, i != p->includes_.end(); i = j)
+ {
+ ++ j;
+ if (&* i != this && &* i != p)
+ delete &* i;
+ }
+
+ if (p != this)
+ delete p;
+
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ Recursive search for the @c mutual_header header of an union.
+
+ @return @c mutual_header responsible for managing the counter of an union.
+ */
+
+ mutual_header * redir() const
+ {
+ if (redir_ == this) return redir_;
+ else return redir_ = redir_->redir();
+ }
+
+
+ /**
+ Unification with a new @c mutual_header .
+
+ @param p New @c mutual_header to unify with.
+ */
+
+ void redir(mutual_header * p)
+ {
+ if (redir_ != p->redir())
+ {
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(mutex_);
+#endif
+ redir_ = p->redir();
+ redir_->includes_.merge(includes_);
+ redir_->elements_.merge(elements_);
+ new (& redir_->count_) count_type(redir_->count_ + count_); /**< Hack */
+ }
+ }
+
+
+ /**
+ Finds the elements constituting one or many sets unified.
+
+ @return List of all elements.
+ */
+
+ intrusive_list * elements() const
+ {
+ return & redir()->elements_;
+ }
+
+
+ /**
+ Allocates a new @c mutual_header using the fast pool allocator.
+
+ @param s Size of the @c mutual_header .
+ @return Pointer of the new memory block.
+ */
+
+ void * operator new (size_t s)
+ {
+ return pool_.allocate(s);
+ }
+
+
+ /**
+ Placement new.
+
+ @param s Size of the @c mutual_header .
+ @param p Address to construct the @c mutual_header on.
+ @return Address to construct the @c mutual_header on.
+ */
+
+ void * operator new (size_t s, mutual_header * p)
+ {
+ return p;
+ }
+
+
+ /**
+ Deallocates a @c mutual_header from the fast pool allocator.
+
+ @param p Address of the @c mutual_header to deallocate.
+ */
+
+ void operator delete (void * p)
+ {
+ pool_.deallocate(static_cast<mutual_header *>(p), sizeof(mutual_header));
+ }
+};
+
+
+fast_pool_allocator<mutual_header> mutual_header::pool_;
+
+
+/**
+ Deterministic memory manager of constant complexity.
+
+ Complete memory management utility on top of standard reference counting.
+*/
+
+template <typename T>
+ class mutual_ptr : public mutual_ptr_base<T>
+ {
+ template <typename> friend class mutual_ptr;
+
+ typedef mutual_ptr_base<T> base;
+
+ using base::share;
+ using base::po_;
+
+ union
+ {
+ mutual_header * ps_; /**< Pointer to the @c mutual_header node @c mutual_ptr<> belongs to. */
+ intrusive_stack::node pn_; /**< Tag used for enlisting a pointer on the heap to later share the @c mutual_header it belongs to. */
+ };
+
+ public:
+ typedef T value_type;
+ typedef mutual<value_type> element_type;
+
+
+ /**
+ Initialization of a pointer living on the stack or proper enlistment if living on the heap.
+ */
+
+ mutual_ptr() : ps_(0)
+ {
+ if (! mutual_base::pool_.is_from(this))
+ ps_ = new mutual_header();
+ else
+ mutual_base::pool_.top(this)->ptrs_.push(& pn_);
+ }
+
+
+ /**
+ Initialization of a pointer living on the stack or proper enlistment if living on the heap.
+
+ @param p New pointee object to manage.
+ */
+
+ template <typename V>
+ mutual_ptr(mutual<V> * p) : base(p)
+ {
+ if (! mutual_base::pool_.is_from(this))
+ {
+ ps_ = new mutual_header();
+
+ init(p);
+ }
+ else
+ {
+ mutual_base::pool_.top(this)->ptrs_.push(& pn_);
+ mutual_base::pool_.top(this)->inits_.merge(p->inits_);
+ }
+ }
+
+
+ /**
+ Initialization of a pointer living on the stack or proper enlistment if living on the heap.
+
+ @param p New pointer to manage.
+ */
+
+ template <typename V>
+ mutual_ptr(mutual_ptr<V> const & p) : base(p)
+ {
+ if (! mutual_base::pool_.is_from(this))
+ ps_ = new mutual_header();
+ else
+ mutual_base::pool_.top(this)->ptrs_.push(& pn_);
+
+ ps_->redir(p.ps_);
+ }
+
+
+ /**
+ Initialization of a pointer living on the stack or proper enlistment if living on the heap.
+
+ @param p New pointer to manage.
+ */
+
+ mutual_ptr(mutual_ptr<T> const & p) : base(p)
+ {
+ if (! mutual_base::pool_.is_from(this))
+ ps_ = new mutual_header();
+ else
+ mutual_base::pool_.top(this)->ptrs_.push(& pn_);
+
+ ps_->redir(p.ps_);
+ }
+
+
+ /**
+ Assignment & union of 2 sets if the pointee resides a different @c mutual_header.
+
+ @param p New pointee object to manage.
+ */
+
+ template <typename V>
+ mutual_ptr & operator = (mutual<V> * p)
+ {
+ release(false);
+
+ init(p);
+
+ base::operator = (p);
+
+ return * this;
+ }
+
+
+ /**
+ Assignment & union of 2 sets if the pointee resides a different @c mutual_header.
+
+ @param p New pointer to manage.
+ */
+
+ template <typename V>
+ mutual_ptr & operator = (mutual_ptr<V> const & p)
+ {
+ if (ps_->redir() != p.ps_->redir())
+ {
+ release(false);
+
+ ps_->redir(p.ps_);
+ }
+ base::operator = (p);
+
+ return * this;
+ }
+
+
+ /**
+ Assignment & union of 2 sets if the pointee resides a different @c mutual_header.
+
+ @param p New pointer to manage.
+ */
+
+ mutual_ptr & operator = (mutual_ptr<T> const & p)
+ {
+ return operator = <T>(p);
+ }
+
+ void reset()
+ {
+ release(false);
+ }
+
+ ~mutual_ptr()
+ {
+ if (ps_->destroy_)
+ base::po_ = 0;
+ else
+ release(true);
+ }
+
+ private:
+ /**
+ Release of the pointee object with or without destroying the entire @c mutual_header it belongs to.
+
+ @param d Destroy (true) or reuse (false) the @c mutual_header it is releasing.
+ */
+
+ void release(bool d)
+ {
+ base::reset();
+
+ if (! mutual_base::pool_.is_from(this))
+ if (ps_->release())
+ if (! d)
+ new (ps_) mutual_header();
+ else
+ delete ps_;
+ else
+ if (! d)
+ ps_ = new mutual_header();
+ }
+
+
+ /**
+ Enlist & initialize pointee objects belonging to the same @c mutual_header . This initialization occurs when a pointee object is affected to the first pointer living on the stack it encounters.
+
+ @param p Pointee object to initialize.
+ */
+
+ void init(mutual_base * p)
+ {
+ if (p->init_)
+ return;
+
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(ps_->mutex_);
+#endif
+
+ // iterate memory blocks
+ for (intrusive_list::iterator<mutual_base, & mutual_base::init_tag_> i = p->inits_.begin(); i != p->inits_.end(); ++ i)
+ {
+ i->init_ = true;
+ ps_->elements()->push_back(& i->mutual_tag_);
+
+ // iterate mutual_ptr elements
+ for (intrusive_stack::iterator<mutual_ptr, & mutual_ptr::pn_> j = i->ptrs_.begin(), k; k = j, j != i->ptrs_.end(); j = k)
+ {
+ ++ k;
+ j->ps_ = ps_;
+ }
+ }
+ }
+ };
+
+
+} // namespace sh
+
+} // namespace detail
+
+using detail::sh::mutual_ptr;
+using detail::sh::mutual;
+
+} // namespace boost
+
+
+#if defined(_MSC_VER)
+#pragma warning( pop )
+#endif
+
+
+#endif // #ifndef BOOST_DETAIL_SH_RTCMM_H_INCLUDED

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/Cyclicism1.png
==============================================================================
Binary files. No diff available.

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/Cyclicism2.png
==============================================================================
Binary files. No diff available.

Copied: sandbox/mutual_ptr/libs/smart_ptr/doc/Doxyfile (from r71462, /sandbox/mm_ptr/libs/smart_ptr/doc/Doxyfile)
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/doc/Doxyfile (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/Doxyfile 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -25,7 +25,7 @@
 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded
 # by quotes) that should identify the project.
 
-PROJECT_NAME = Memory Managed Pointer
+PROJECT_NAME = Mutual Pointer
 
 # The PROJECT_NUMBER tag can be used to enter a project or revision number.
 # This could be handy for archiving the generated documentation or

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/Introduction.png
==============================================================================
Binary files. No diff available.

Deleted: /sandbox/mm_ptr/libs/smart_ptr/doc/MMPointer.ppt
==============================================================================
Binary file. No diff available.

Added: sandbox/mutual_ptr/libs/smart_ptr/doc/MutualPointer.ppt
==============================================================================
Binary file. No diff available.

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/Union1.png
==============================================================================
Binary files. No diff available.

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/Union2.png
==============================================================================
Binary files. No diff available.

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/index.html
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/doc/index.html (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/index.html 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -62,7 +62,7 @@
   <dl class="index">
     <dt>Overview</dt>
 
- <dt>Presentation</dt>
+ <dt>Presentation</dt>
 
     <dt>Reference</dt>
 

Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/overview.html
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/doc/overview.html (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/overview.html 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -82,17 +82,17 @@
   <p>Reference counting is a different approach where objects pointed to are aware of the number of times they are referenced. This means a counter within the object
   is incremented or decremented according to the number of smart pointers that are referencing or dereferencing it. There is a lost in performance as compared to
   garbage collection because of the extra time required to manage the counter every time the pointer is reassigned or dereferenced. Reference counting can also leave
- a group of blocks of memory referencing each other called "cyclic" (see presentation) unnoticed and therefore never freed by the
+ a group of blocks of memory referencing each other called "cyclic" (see presentation) unnoticed and therefore never freed by the
   application. On the other hand the destruction of the object is done instantaneously and thus the behavior or the application can be predicted.</p>
 
   <h2><a name="sp" id="sp"></a>Memory Managed Pointer</h2>
 
   <p>Memory Managed Pointer is a memory manager on top of reference counting and is also able to detect outright unreferenced cyclic blocks of memory. It is a fast as
   the popular smart pointer <i>boost::shared_ptr&#60;T&#62;</i> but is not requiring a bigger memory usage per pointer (2 times <i>sizeof(void *)</i>), given its
- ability to detect cyclic blocks of memory with no coding overhead. In terms of programing requirements, <i>mm_ptr&#60;T&#62;</i> simply requires to point
+ ability to detect cyclic blocks of memory with no coding overhead. In terms of programing requirements, <i>mutual_ptr&#60;T&#62;</i> simply requires to point
   to instantiations of the <i>mm&#60;T&#62;</i> type. For example:</p>
   <pre>
- mm_ptr&#60;int&#62; v = new mm&#60;int&#62;(11);
+ mutual_ptr&#60;int&#62; v = new mutual&#60;int&#62;(11);
   </pre>
 
   <hr>

Copied: sandbox/mutual_ptr/libs/smart_ptr/doc/rationale.html (from r71464, /sandbox/mm_ptr/libs/smart_ptr/doc/rationale.html)
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/doc/rationale.html (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/rationale.html 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -72,8 +72,8 @@
   <h2><a name="introduction" id="introduction"></a>Introduction</h2>
 
   <p>Memory Managed Pointer introduces the concept of <i>set</i> where it is defined to be a one or many memory blocks referencing each other allocated on the heap pointed
- to by one or many <i>mm_ptr&#60;T&#62;</i>s allocated on the stack or the data segment (non heap) of the application. Each <i>set</i> is consequently composed of a
- list of all memory blocks constituting it and a counter tracking the number of times the <i>set</i> is referenced by a <i>mm_ptr&#60;T&#62;</i> from the stack or the data
+ to by one or many <i>mutual_ptr&#60;T&#62;</i>s allocated on the stack or the data segment (non heap) of the application. Each <i>set</i> is consequently composed of a
+ list of all memory blocks constituting it and a counter tracking the number of times the <i>set</i> is referenced by a <i>mutual_ptr&#60;T&#62;</i> from the stack or the data
   segment. For example:</p>
   
   <center>
@@ -82,7 +82,7 @@
 
   <h2><a name="cyclicism" id="cyclicism"></a>Cyclicism</h2>
   
- <p>Therefore whenever a <i>set</i> counter finds out the number of <i>mm_ptr&#60;T&#62;</i> referencing it to be zero, the deallocation of each memory block composing
+ <p>Therefore whenever a <i>set</i> counter finds out the number of <i>mutual_ptr&#60;T&#62;</i> referencing it to be zero, the deallocation of each memory block composing
   the <i>set</i> is enforced. Thus whether the <i>set</i> was composed of memory blocks referencing each other in a cyclic way or not, all of them will be subject to
   destruction and deallocation indifferent from the cyclicism problem presented by the reference counters. As we can see in the following example, the <i>set</i> counter reaches
   0 and consequently every elements composing the <i>set</i> will be destructed and deallocated:</p>
@@ -93,9 +93,9 @@
 
   <h2><a name="initialization" id="initialization"></a>Initialization</h2>
 
- <p>A <i>mm_ptr&#60;T&#62;</i> is initialized differently depending on the memory segment it is being instanciated on. If it is found to be residing the stack or the data
+ <p>A <i>mutual_ptr&#60;T&#62;</i> is initialized differently depending on the memory segment it is being instanciated on. If it is found to be residing the stack or the data
   segment then a new <i>set</i> counter will also be instanciated. If it is found to be living on the heap then a more complicated mechanism is involved to track the
- last memory block that was allocated in the same thread, find its address and stack up the <i>set</i> it will be part of until the first <i>mm_ptr&#60;T&#62;</i> found on
+ last memory block that was allocated in the same thread, find its address and stack up the <i>set</i> it will be part of until the first <i>mutual_ptr&#60;T&#62;</i> found on
   the stack is or data segment is initialized, where the new <i>set</i> counter will be shared with all of the newly allocated blocks of memory referencing each other.</p>
 
   <h2><a name="union" id="union"></a>Union</h2>

Copied: sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html (from r71464, /sandbox/mm_ptr/libs/smart_ptr/doc/tutorial.html)
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/doc/tutorial.html (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -69,31 +69,31 @@
   of a special type needed to instanciate objects referred to. For example:</p>
 
   <pre>
- mm_ptr&#60;int&#62; p = new mm&#60;int&#62;(11);
+ mutual_ptr&#60;int&#62; p = new mutual&#60;int&#62;(11);
   </pre>
 
   <p>Will instanciate a special object <i>mm&#60;int&#62;</i> having an integer as one of its member. The pointer to the object is then passed to the
- <i>mm_ptr&#60;int&#62;</i> that will manage its existence and later destroy and deallocate it when it is found to be no longer referenced.<p>
+ <i>mutual_ptr&#60;int&#62;</i> that will manage its existence and later destroy and deallocate it when it is found to be no longer referenced.<p>
 
   <p>Variants of the object type can also be used. In order to instanciate an array of integer for example, all that will be needed is to change the
   type to the following:<p>
 
   <pre>
- mm_ptr&#60;int[10]&#62; p = new mm&#60;int[10]&#62;();
+ mutual_ptr&#60;int[10]&#62; p = new mutual&#60;int[10]&#62;();
   </pre>
 
- See the following example for different cases of its usage.
+ See the following example for different cases of its usage.
   
   <h2><a name="advanced" id="advanced"></a>Advanced</h2>
 
- <p>When STL containers are made out of objects having members of type <i>mm_ptr&#60;T&#62;</i> then it will be desirable to have all of the allocated nodes
- and its members part of the same <i>set</i>. This way all of the newly allocated <i>mm_ptr&#60;T&#62;</i> will be referring to the same <i>set</i> header.
+ <p>When STL containers are made out of objects having members of type <i>mutual_ptr&#60;T&#62;</i> then it will be desirable to have all of the allocated nodes
+ and its members part of the same <i>set</i>. This way all of the newly allocated <i>mutual_ptr&#60;T&#62;</i> will be referring to the same <i>set</i> header.
   In order to do so, we must tell the container in question a new allocator that will be used to instanciate the nodes. This allocator is called:
- <i>mm_allocator&#60;T&#62;</i>. For example:</p>
+ <i>mutual_allocator&#60;T&#62;</i>. For example:</p>
 
   <pre>
- list&#60; mm_ptr&#60;int&#62;, mm_allocator&#60; mm_ptr&#60;int&#62; &#62; &#62; c;
- c.push_back(new mm&#60;int&#62;(11));
+ list&#60; mutual_ptr&#60;int&#62;, mutual_allocator&#60; mutual_ptr&#60;int&#62; &#62; &#62; c;
+ c.push_back(new mutual&#60;int&#62;(11));
   </pre>
 
   <hr>

Copied: sandbox/mutual_ptr/libs/smart_ptr/example/Makefile (from r71488, /sandbox/mm_ptr/libs/smart_ptr/example/Makefile)
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/example/Makefile (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/example/Makefile 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -16,15 +16,15 @@
 .PHONY : all depend clean
 
 
-all : mm_ptr_test1 mm_ptr_test2 mm_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
+all : mutual_ptr_test1 mutual_ptr_test2 mutual_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
 
-mm_ptr_test1: mm_ptr_test1.o
+mutual_ptr_test1: mutual_ptr_test1.o
         $(LINK) $(LFLAGS) -o $@ $^
 
-mm_ptr_test2: mm_ptr_test2.o
+mutual_ptr_test2: mutual_ptr_test2.o
         $(LINK) $(LFLAGS) -o $@ $^
 
-mm_ptr_test3: mm_ptr_test3.o
+mutual_ptr_test3: mutual_ptr_test3.o
         $(LINK) $(LFLAGS) -o $@ $^ -lboost_unit_test_framework
 
 local_pool_test1: local_pool_test1.o
@@ -41,7 +41,7 @@
         $(CXX) ${INCPATH} -MM $^ > $@
 
 clean:
- $(RM) mm_ptr_test1 mm_ptr_test2 mm_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
+ $(RM) mutual_ptr_test1 mutual_ptr_test2 mutual_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
         $(RM) $(OBJECTS)
         $(RM) *~ core
 

Deleted: /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test1.cpp
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test1.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,64 +0,0 @@
-/**
- @file
- mm_ptr_test2.cpp
-
- @note
- Memory manager handling heap deallocations in constant time.
-*/
-
-#include <iostream>
-
-#include <boost/mm_ptr.hpp>
-
-
-using namespace std;
-using namespace boost;
-
-
-struct A
-{
- int i;
- mm_ptr<A> p;
-
- A(int i = 0) : i(i)
- {
- std::cout << __FUNCTION__ << ": " << i << std::endl;
- }
-
- ~A()
- {
- std::cout << __FUNCTION__ << ": " << i << std::endl;
- }
-};
-
-
-int main()
-{
- mm_ptr<A> p = new mm<A>(7);
- mm_ptr<A> q = new mm<A>(8);
- mm_ptr<A> r = new mm<A>(9);
-
- mm_ptr<void> t = new mm<A>(10);
- mm_ptr<int const volatile> v = new mm<int const volatile>(11);
-
- p->p = p;
- q = r;
- v = new mm<int const volatile>(12);
-
- cout << "p->i = " << p->i << endl;
- cout << "q->i = " << q->i << endl;
- cout << "r->i = " << r->i << endl;
- cout << "* v = " << * v << endl;
-
- // The following don't work with MSVC:
-#if ! defined(_MSC_VER)
- mm_ptr<A[5]> s = new mm<A[5]>();
- mm_ptr<char[9]> u = new mm<char[9]>();
-
- u[4] = 'Z';
-
- cout << "u[4] = " << u[4] << endl;
-#endif
-
- cout << "Done." << endl;
-}

Deleted: /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test2.cpp
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test2.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,128 +0,0 @@
-/**
- @file
- mm_ptr_test2.cpp
-
- @author
- Steven Watanabe <watanabesj_at_[hidden]>
-*/
-
-#include <boost/mm_ptr.hpp>
-#include <boost/mm_allocator.hpp>
-
-#include <list>
-#include <vector>
-#include <iostream>
-
-#include <boost/mpl/range_c.hpp>
-#include <boost/mpl/for_each.hpp>
-#include <boost/array.hpp>
-
-
-static int count;
-
-using boost::mm_ptr;
-using boost::mm;
-using boost::mm_allocator;
-using boost::operator ==;
-using boost::operator !=;
-
-struct node {
- node() {
- ++count;
- }
- ~node() {
- --count;
- }
- mm_ptr<node> prior;
- mm_ptr<node> next;
-};
-
-struct list {
-public:
- list() {}
- void clear() {
- front.reset();
- back.reset();
- }
- void insert() {
- if(front.get() == 0) {
- back = new mm<node>();
- } else {
- back->next = new mm<node>();
- back->next->prior = back;
- back = back->next;
- }
- }
- ~list()
- {
- }
-private:
- mm_ptr<node> front;
- mm_ptr<node> back;
-};
-
-struct vector {
- vector() { ++count; }
- ~vector() { --count; }
- vector(const vector& other) : elements(other.elements) { ++count; }
- //std::vector<mm_ptr<vector> > elements;
- std::list<mm_ptr<vector>, mm_allocator< mm_ptr<vector> > > elements; //! works fine
-};
-
-struct create_type {
- template<class T>
- void operator()(T) const {
- new mm<boost::array<char, T::value> >();
- }
-};
-
-int main() {
- count = 0;
- {
- list l;
- for(int j = 0; j < 2; ++j) {
- for(int i = 0; i < 1000; ++i) {
- l.insert();
- }
- l.clear();
- }
- }
- std::cout << count << std::endl;
-
- count = 0;
- {
- mm_ptr<vector> v = new mm<vector>();
- v->elements.push_back(v);
- }
- std::cout << count << std::endl;
-
- count = 0;
- {
- mm_ptr<vector> v = new mm<vector>();
- v->elements.push_back(v);
- }
- std::cout << count << std::endl;
-
- {
- vector v;
- v.elements.push_back(new mm<vector>());
- }
- std::cout << count << std::endl;
-
- count = 0;
- {
- mm_ptr<int> test = new mm<int>(5);
- test = test;
-
- std::cout << "test = " << * test << std::endl;
- }
- std::cout << count << std::endl;
-
- count = 0;
- for(int i = 0; i < 500; ++i) {
- boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
- }
- std::cout << count << std::endl;
-
- //_exit(-1); // bypassing bug in pool destructor
-}

Deleted: /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test3.cpp
==============================================================================
--- /sandbox/mm_ptr/libs/smart_ptr/example/mm_ptr_test3.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
+++ (empty file)
@@ -1,131 +0,0 @@
-/**
- @file
- mm_ptr_test3.cpp
-
- @note
- MinGW users must link with: -Wl,--enable-runtime-pseudo-reloc
-
- @author
- Steven Watanabe <watanabesj_at_[hidden]>
-*/
-
-
-
-#include <boost/mm_ptr.hpp>
-#include <boost/mm_allocator.hpp>
-
-#include <vector>
-#include <iostream>
-
-#include <boost/mpl/range_c.hpp>
-#include <boost/mpl/for_each.hpp>
-#include <boost/array.hpp>
-
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MAIN
-
-#include <boost/test/unit_test.hpp>
-
-static int count;
-
-using boost::mm_ptr;
-using boost::mm;
-using boost::mm_allocator;
-
-struct node {
- node() {
- ++count;
- }
- ~node() {
- --count;
- }
- node(const node&) {
- ++count;
- }
- mm_ptr<node> prior;
- mm_ptr<node> next;
-};
-
-struct list {
-public:
- list() {}
- void clear() {
- front.reset();
- back.reset();
- }
- void insert() {
- if(front.get() == 0) {
- front = back = new mm<node>();
- } else {
- back->next = new mm<node>();
- back->next->prior = back;
- back = back->next;
- }
- }
-private:
- mm_ptr<node> front;
- mm_ptr<node> back;
-};
-
-struct vector {
- vector() { ++count; }
- ~vector() { --count; }
- vector(const vector& other) : elements(other.elements) { ++count; }
- std::vector<mm_ptr<vector>, mm_allocator<mm_ptr<vector> > > elements;
-};
-
-struct create_type {
- template<class T>
- void operator()(T) const {
- new mm<boost::array<char, T::value> >();
- }
-};
-
-BOOST_AUTO_TEST_CASE(test_mm_ptr) {
-
- count = 0;
- {
- mm_ptr<vector> v = new mm<vector>();
- v->elements.push_back(v);
- }
- BOOST_CHECK_EQUAL(count, 0);
-
- count = 0;
- {
- list l;
- for(int j = 0; j < 2; ++j) {
- for(int i = 0; i < 2; ++i) {
- l.insert();
- }
- l.clear();
- }
- }
- BOOST_CHECK_EQUAL(count, 0);
-
- count = 0;
- {
- mm_ptr<int> test = new mm<int>(5);
- test = test;
-
- BOOST_CHECK_NE(test.get(), static_cast<int*>(0));
- BOOST_CHECK_EQUAL(*test, 5);
- }
-
- for(int i = 0; i < 500; ++i) {
- boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
- }
-
- count = 0;
- {
- mm_ptr<vector> v = new mm<vector>();
- v->elements.push_back(v);
- }
- BOOST_CHECK_EQUAL(count, 0);
-
- {
- vector v;
- v.elements.push_back(new mm<vector>());
- }
- BOOST_CHECK_EQUAL(count, 0);
-
-}

Added: sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test1.cpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test1.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,79 @@
+/**
+ @file
+ mutual_ptr_test2.cpp
+
+ @note
+ Memory manager handling heap deallocations in constant time.
+*/
+
+#include <iostream>
+
+#include <boost/mutual_ptr.hpp>
+
+
+using namespace std;
+using namespace boost;
+
+
+struct A
+{
+ int i;
+ mutual_ptr<A> p;
+
+ A(int i = 0) : i(i)
+ {
+ cout << __FUNCTION__ << ": " << i << endl;
+ }
+
+ ~A()
+ {
+ cout << __FUNCTION__ << ": " << i << endl;
+ }
+};
+
+
+int main()
+{
+ cout << "Cyclicism:" << endl;
+ {
+ mutual_ptr<A> p = new mutual<A>(7);
+ mutual_ptr<A> q = new mutual<A>(8);
+ mutual_ptr<A> r = new mutual<A>(9);
+
+ mutual_ptr<void> t = new mutual<A>(10);
+ mutual_ptr<int const volatile> v = new mutual<int const volatile>(11);
+
+ p->p = p;
+ q = r;
+ v = new mutual<int const volatile>(12);
+
+ cout << "p->i = " << p->i << endl;
+ cout << "q->i = " << q->i << endl;
+ cout << "r->i = " << r->i << endl;
+ cout << "* v = " << * v << endl;
+ }
+ cout << endl;
+
+ // The following don't work with MSVC:
+#if ! defined(_MSC_VER)
+ cout << "Array access:" << endl;
+ {
+ mutual_ptr<A[5]> s = new mutual<A[5]>();
+ mutual_ptr<char[9]> u = new mutual<char[9]>();
+
+ u[4] = 'Z';
+
+ cout << "u[4] = " << u[4] << endl;
+ }
+ cout << endl;
+#endif
+
+ cout << "Order of destruction:" << endl;
+ {
+ mutual_ptr<A> v = new mutual<A>(0);
+ v->p = new mutual<A>(1);
+ v->p->p = new mutual<A>(2);
+ v->p->p->p = v;
+ }
+ cout << endl;
+}

Added: sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test2.cpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test2.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,128 @@
+/**
+ @file
+ mutual_ptr_test2.cpp
+
+ @author
+ Steven Watanabe <watanabesj_at_[hidden]>
+*/
+
+#include <boost/mutual_ptr.hpp>
+#include <boost/mutual_allocator.hpp>
+
+#include <list>
+#include <vector>
+#include <iostream>
+
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/array.hpp>
+
+
+static int count;
+
+using boost::mutual_ptr;
+using boost::mutual;
+using boost::mutual_allocator;
+using boost::operator ==;
+using boost::operator !=;
+
+struct node {
+ node() {
+ ++count;
+ }
+ ~node() {
+ --count;
+ }
+ mutual_ptr<node> prior;
+ mutual_ptr<node> next;
+};
+
+struct list {
+public:
+ list() {}
+ void clear() {
+ front.reset();
+ back.reset();
+ }
+ void insert() {
+ if(front.get() == 0) {
+ back = new mutual<node>();
+ } else {
+ back->next = new mutual<node>();
+ back->next->prior = back;
+ back = back->next;
+ }
+ }
+ ~list()
+ {
+ }
+private:
+ mutual_ptr<node> front;
+ mutual_ptr<node> back;
+};
+
+struct vector {
+ vector() { ++count; }
+ ~vector() { --count; }
+ vector(const vector& other) : elements(other.elements) { ++count; }
+ //std::vector<mutual_ptr<vector> > elements;
+ std::list<mutual_ptr<vector>, mutual_allocator< mutual_ptr<vector> > > elements; //! works fine
+};
+
+struct create_type {
+ template<class T>
+ void operator()(T) const {
+ new mutual<boost::array<char, T::value> >();
+ }
+};
+
+int main() {
+ count = 0;
+ {
+ list l;
+ for(int j = 0; j < 2; ++j) {
+ for(int i = 0; i < 1000; ++i) {
+ l.insert();
+ }
+ l.clear();
+ }
+ }
+ std::cout << count << std::endl;
+
+ count = 0;
+ {
+ mutual_ptr<vector> v = new mutual<vector>();
+ v->elements.push_back(v);
+ }
+ std::cout << count << std::endl;
+
+ count = 0;
+ {
+ mutual_ptr<vector> v = new mutual<vector>();
+ v->elements.push_back(v);
+ }
+ std::cout << count << std::endl;
+
+ {
+ vector v;
+ v.elements.push_back(new mutual<vector>());
+ }
+ std::cout << count << std::endl;
+
+ count = 0;
+ {
+ mutual_ptr<int> test = new mutual<int>(5);
+ test = test;
+
+ std::cout << "test = " << * test << std::endl;
+ }
+ std::cout << count << std::endl;
+
+ count = 0;
+ for(int i = 0; i < 500; ++i) {
+ boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
+ }
+ std::cout << count << std::endl;
+
+ //_exit(-1); // bypassing bug in pool destructor
+}

Added: sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test3.cpp
==============================================================================
--- (empty file)
+++ sandbox/mutual_ptr/libs/smart_ptr/example/mutual_ptr_test3.cpp 2011-04-26 21:01:35 EDT (Tue, 26 Apr 2011)
@@ -0,0 +1,131 @@
+/**
+ @file
+ mutual_ptr_test3.cpp
+
+ @note
+ MinGW users must link with: -Wl,--enable-runtime-pseudo-reloc
+
+ @author
+ Steven Watanabe <watanabesj_at_[hidden]>
+*/
+
+
+
+#include <boost/mutual_ptr.hpp>
+#include <boost/mutual_allocator.hpp>
+
+#include <vector>
+#include <iostream>
+
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/array.hpp>
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/test/unit_test.hpp>
+
+static int count;
+
+using boost::mutual_ptr;
+using boost::mutual;
+using boost::mutual_allocator;
+
+struct node {
+ node() {
+ ++count;
+ }
+ ~node() {
+ --count;
+ }
+ node(const node&) {
+ ++count;
+ }
+ mutual_ptr<node> prior;
+ mutual_ptr<node> next;
+};
+
+struct list {
+public:
+ list() {}
+ void clear() {
+ front.reset();
+ back.reset();
+ }
+ void insert() {
+ if(front.get() == 0) {
+ front = back = new mutual<node>();
+ } else {
+ back->next = new mutual<node>();
+ back->next->prior = back;
+ back = back->next;
+ }
+ }
+private:
+ mutual_ptr<node> front;
+ mutual_ptr<node> back;
+};
+
+struct vector {
+ vector() { ++count; }
+ ~vector() { --count; }
+ vector(const vector& other) : elements(other.elements) { ++count; }
+ std::vector<mutual_ptr<vector>, mutual_allocator<mutual_ptr<vector> > > elements;
+};
+
+struct create_type {
+ template<class T>
+ void operator()(T) const {
+ new mutual<boost::array<char, T::value> >();
+ }
+};
+
+BOOST_AUTO_TEST_CASE(test_mutual_ptr) {
+
+ count = 0;
+ {
+ mutual_ptr<vector> v = new mutual<vector>();
+ v->elements.push_back(v);
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ count = 0;
+ {
+ list l;
+ for(int j = 0; j < 2; ++j) {
+ for(int i = 0; i < 2; ++i) {
+ l.insert();
+ }
+ l.clear();
+ }
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ count = 0;
+ {
+ mutual_ptr<int> test = new mutual<int>(5);
+ test = test;
+
+ BOOST_CHECK_NE(test.get(), static_cast<int*>(0));
+ BOOST_CHECK_EQUAL(*test, 5);
+ }
+
+ for(int i = 0; i < 500; ++i) {
+ boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
+ }
+
+ count = 0;
+ {
+ mutual_ptr<vector> v = new mutual<vector>();
+ v->elements.push_back(v);
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ {
+ vector v;
+ v.elements.push_back(new mutual<vector>());
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+}


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