|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55148 - in sandbox/fmhess/boost/generic_ptr: . detail
From: fmhess_at_[hidden]
Date: 2009-07-24 17:16:02
Author: fmhess
Date: 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
New Revision: 55148
URL: http://svn.boost.org/trac/boost/changeset/55148
Log:
Split some stuff out of shared.hpp into pointer_traits.hpp,
detail/operator_bool.hpp, and detail/util.hpp so it can be used
by other generic pointer classes.
Made generic_ptr::shared constructor which uses default deleter
apply get_plain_old_pointer()
to incoming generic pointer before it is bound to checked_delete.
Added initial pass at generic_ptr::monitor (no
explicit lock types yet, such as monitor_unique_lock).
Added generic_ptr::intrusive, a generic pointer version of
intrusive_ptr.
Added:
sandbox/fmhess/boost/generic_ptr/detail/
sandbox/fmhess/boost/generic_ptr/detail/operator_bool.hpp
- copied, changed from r55087, /trunk/boost/smart_ptr/detail/operator_bool.hpp
sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp
- copied, changed from r55089, /trunk/boost/signals2/detail/unique_lock.hpp
sandbox/fmhess/boost/generic_ptr/detail/util.hpp (contents, props changed)
sandbox/fmhess/boost/generic_ptr/intrusive.hpp
- copied, changed from r55137, /trunk/boost/smart_ptr/intrusive_ptr.hpp
sandbox/fmhess/boost/generic_ptr/monitor.hpp (contents, props changed)
sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp (contents, props changed)
Text files modified:
sandbox/fmhess/boost/generic_ptr/detail/operator_bool.hpp | 15 ++-
sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp | 11 +-
sandbox/fmhess/boost/generic_ptr/intrusive.hpp | 135 +++++++++++++++++----------------
sandbox/fmhess/boost/generic_ptr/shared.hpp | 159 ++-------------------------------------
sandbox/fmhess/boost/generic_ptr/weak.hpp | 8 +-
5 files changed, 95 insertions(+), 233 deletions(-)
Copied: sandbox/fmhess/boost/generic_ptr/detail/operator_bool.hpp (from r55087, /trunk/boost/smart_ptr/detail/operator_bool.hpp)
==============================================================================
--- /trunk/boost/smart_ptr/detail/operator_bool.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/detail/operator_bool.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -1,6 +1,7 @@
// This header intentionally has no include guards.
//
// Copyright (c) 2001-2009 Peter Dimov
+// Copyright (c) 2009 Frank Mori Hess
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
@@ -10,7 +11,7 @@
operator bool () const
{
- return px != 0;
+ return get_plain_old_pointer(px) != 0;
}
#elif defined( _MANAGED )
@@ -23,7 +24,7 @@
operator unspecified_bool_type() const // never throws
{
- return px == 0? 0: unspecified_bool;
+ return get_plain_old_pointer(px) == 0 ? 0: unspecified_bool;
}
#elif \
@@ -31,20 +32,20 @@
( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
- typedef T * (this_type::*unspecified_bool_type)() const;
+ typedef T (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
- return px == 0? 0: &this_type::get;
+ return get_plain_old_pointer(px) == 0 ? 0: &this_type::get;
}
#else
- typedef T * this_type::*unspecified_bool_type;
+ typedef T this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
- return px == 0? 0: &this_type::px;
+ return get_plain_old_pointer(px) == 0 ? 0: &this_type::px;
}
#endif
@@ -52,5 +53,5 @@
// operator! is redundant, but some compilers need it
bool operator! () const // never throws
{
- return px == 0;
+ return get_plain_old_pointer(px) == 0;
}
Copied: sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp (from r55089, /trunk/boost/signals2/detail/unique_lock.hpp)
==============================================================================
--- /trunk/boost/signals2/detail/unique_lock.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -9,14 +9,14 @@
// See http://www.boost.org/libs/signals2 for library home page.
-#ifndef BOOST_SIGNALS2_UNIQUE_LOCK_HPP
-#define BOOST_SIGNALS2_UNIQUE_LOCK_HPP
+#ifndef BOOST_GENERIC_PTR_UNIQUE_LOCK_HPP
+#define BOOST_GENERIC_PTR_UNIQUE_LOCK_HPP
#include <boost/noncopyable.hpp>
namespace boost
{
- namespace signals2
+ namespace generic_ptr
{
namespace detail
{
@@ -36,7 +36,8 @@
Mutex &_mutex;
};
} // namespace detail
- } // namespace signals2
+ } // namespace generic_ptr
} // namespace boost
-#endif // BOOST_SIGNALS2_UNIQUE_LOCK_HPP
+#endif // BOOST_GENERIC_PTR_UNIQUE_LOCK_HPP
+
Added: sandbox/fmhess/boost/generic_ptr/detail/util.hpp
==============================================================================
--- (empty file)
+++ sandbox/fmhess/boost/generic_ptr/detail/util.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -0,0 +1,31 @@
+//
+// generic_ptr/detail/util.hpp
+//
+// Copyright (c) 2009 Frank Mori Hess
+//
+// 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)
+
+#ifndef BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
+#define BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
+
+namespace boost
+{
+ namespace generic_ptr
+ {
+ namespace detail
+ {
+ template<typename T>
+ void set_plain_old_pointer_to_null(T * &p)
+ {
+ p = 0;
+ }
+ template<typename T>
+ void set_plain_old_pointer_to_null(const T&)
+ {}
+ } // namespace detail
+ } // namespace generic_ptr
+} // namespace boost
+
+#endif // #ifndef BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
Copied: sandbox/fmhess/boost/generic_ptr/intrusive.hpp (from r55137, /trunk/boost/smart_ptr/intrusive_ptr.hpp)
==============================================================================
--- /trunk/boost/smart_ptr/intrusive_ptr.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/intrusive.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -1,16 +1,17 @@
-#ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
-#define BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
+#ifndef BOOST_GENERIC_PTR_INTRUSIVE_PTR_INCLUDED
+#define BOOST_GENERIC_PTR_INTRUSIVE_PTR_INCLUDED
//
-// intrusive_ptr.hpp
+// generic_ptr/intrusive.hpp
//
// Copyright (c) 2001, 2002 Peter Dimov
+// Copyright (c) 2009 Frank Mori Hess
//
// 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/intrusive_ptr.html for documentation.
+// See http://www.boost.org/libs/generic_ptr for documentation.
//
#include <boost/config.hpp>
@@ -22,7 +23,10 @@
#include <boost/assert.hpp>
#include <boost/detail/workaround.hpp>
+#include <boost/generic_ptr/detail/util.hpp>
+#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/smart_ptr/detail/sp_convertible.hpp>
+#include <boost/utility/swap.hpp>
#include <boost/config/no_tr1/functional.hpp> // for std::less
@@ -37,39 +41,35 @@
namespace boost
{
-
-//
-// intrusive_ptr
-//
-// A smart pointer that uses intrusive reference counting.
-//
-// Relies on unqualified calls to
-//
-// void intrusive_ptr_add_ref(T * p);
-// void intrusive_ptr_release(T * p);
+namespace generic_ptr
+{
//
-// (p != 0)
+// generic_ptr::intrusive
//
-// The object is responsible for destroying itself.
+// A generalization of intrusive_ptr which can use a generic pointer type.
//
-template<class T> class intrusive_ptr
+template<class T> class intrusive
{
private:
- typedef intrusive_ptr this_type;
+ typedef intrusive this_type;
public:
- typedef T element_type;
+ typedef typename pointer_traits<T>::value_type value_type;
+ typedef value_type element_type;
+ typedef T pointer;
+ typedef typename pointer_traits<T>::reference reference;
- intrusive_ptr(): px( 0 )
+ intrusive(): px()
{
}
- intrusive_ptr( T * p, bool add_ref = true ): px( p )
+
+ intrusive( T p, bool add_ref = true ): px( p )
{
- if( px != 0 && add_ref ) intrusive_ptr_add_ref( px );
+ if( get_plain_old_pointer(px) != 0 && add_ref ) intrusive_ptr_add_ref( get_plain_old_pointer(px) );
}
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
@@ -77,33 +77,37 @@
template<class U>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- intrusive_ptr( intrusive_ptr<U> const & rhs, typename detail::sp_enable_if_convertible<U,T>::type = detail::sp_empty() )
+ intrusive( intrusive<U> const & rhs, typename boost::detail::sp_enable_if_convertible
+ <
+ typename pointer_traits<U>::value_type,
+ typename pointer_traits<T>::value_type
+ >::type = boost::detail::sp_empty() )
#else
- intrusive_ptr( intrusive_ptr<U> const & rhs )
+ intrusive( intrusive<U> const & rhs )
#endif
: px( rhs.get() )
{
- if( px != 0 ) intrusive_ptr_add_ref( px );
+ if( get_plain_old_pointer(px) != 0 ) intrusive_ptr_add_ref( get_plain_old_pointer(px) );
}
#endif
- intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
+ intrusive(intrusive const & rhs): px( rhs.px )
{
- if( px != 0 ) intrusive_ptr_add_ref( px );
+ if( get_plain_old_pointer(px) != 0 ) intrusive_ptr_add_ref( get_plain_old_pointer(px) );
}
- ~intrusive_ptr()
+ ~intrusive()
{
- if( px != 0 ) intrusive_ptr_release( px );
+ if( get_plain_old_pointer(px) != 0 ) intrusive_ptr_release( get_plain_old_pointer(px) );
}
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
- template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
+ template<class U> intrusive & operator=(intrusive<U> const & rhs)
{
this_type(rhs).swap(*this);
return *this;
@@ -115,12 +119,12 @@
#if defined( BOOST_HAS_RVALUE_REFS )
- intrusive_ptr(intrusive_ptr && rhs): px( rhs.px )
+ intrusive(intrusive && rhs): px( rhs.px )
{
- rhs.px = 0;
+ detail::set_plain_old_pointer_to_null(px);
}
- intrusive_ptr & operator=(intrusive_ptr && rhs)
+ intrusive & operator=(intrusive && rhs)
{
this_type(std::move(rhs)).swap(*this);
return *this;
@@ -128,13 +132,13 @@
#endif
- intrusive_ptr & operator=(intrusive_ptr const & rhs)
+ intrusive & operator=(intrusive const & rhs)
{
this_type(rhs).swap(*this);
return *this;
}
- intrusive_ptr & operator=(T * rhs)
+ intrusive & operator=(T rhs)
{
this_type(rhs).swap(*this);
return *this;
@@ -145,69 +149,67 @@
this_type().swap( *this );
}
- void reset( T * rhs )
+ void reset( T rhs )
{
this_type( rhs ).swap( *this );
}
- T * get() const
+ pointer get() const
{
return px;
}
- T & operator*() const
+ reference operator*() const
{
- BOOST_ASSERT( px != 0 );
+ BOOST_ASSERT( get_plain_old_pointer(px) != 0 );
return *px;
}
- T * operator->() const
+ pointer operator->() const
{
- BOOST_ASSERT( px != 0 );
+ BOOST_ASSERT( get_plain_old_pointer(px) != 0 );
return px;
}
// implicit conversion to "bool"
-#include <boost/smart_ptr/detail/operator_bool.hpp>
+#include <boost/generic_ptr/detail/operator_bool.hpp>
- void swap(intrusive_ptr & rhs)
+ void swap(intrusive & rhs)
{
- T * tmp = px;
- px = rhs.px;
- rhs.px = tmp;
+ boost::swap(px, rhs.px);
}
private:
- T * px;
+ T px;
};
-template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
+template<class T, class U> inline bool operator==(intrusive<T> const & a, intrusive<U> const & b)
{
return a.get() == b.get();
}
-template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
+template<class T, class U> inline bool operator!=(intrusive<T> const & a, intrusive<U> const & b)
{
return a.get() != b.get();
}
-template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b)
+template<class T, class U> inline bool operator==(intrusive<T> const & a, U * b)
{
return a.get() == b;
}
-template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b)
+template<class T, class U> inline bool operator!=(intrusive<T> const & a, U * b)
{
return a.get() != b;
}
-template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b)
+template<class T, class U> inline bool operator==(T * a, intrusive<U> const & b)
{
return a == b.get();
}
-template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b)
+template<class T, class U> inline bool operator!=(T * a, intrusive<U> const & b)
{
return a != b.get();
}
@@ -216,41 +218,41 @@
// Resolve the ambiguity between our op!= and the one in rel_ops
-template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
+template<class T> inline bool operator!=(intrusive<T> const & a, intrusive<T> const & b)
{
return a.get() != b.get();
}
#endif
-template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
+template<class T> inline bool operator<(intrusive<T> const & a, intrusive<T> const & b)
{
return std::less<T *>()(a.get(), b.get());
}
-template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs)
+template<class T> void swap(intrusive<T> & lhs, intrusive<T> & rhs)
{
lhs.swap(rhs);
}
// mem_fn support
-template<class T> T * get_pointer(intrusive_ptr<T> const & p)
+template<class T> T * get_pointer(intrusive<T> const & p)
{
return p.get();
}
-template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
+template<class T, class U> intrusive<T> static_pointer_cast(intrusive<U> const & p)
{
return static_cast<T *>(p.get());
}
-template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
+template<class T, class U> intrusive<T> const_pointer_cast(intrusive<U> const & p)
{
return const_cast<T *>(p.get());
}
-template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
+template<class T, class U> intrusive<T> dynamic_pointer_cast(intrusive<U> const & p)
{
return dynamic_cast<T *>(p.get());
}
@@ -261,7 +263,7 @@
#if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
-template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p)
+template<class Y> std::ostream & operator<< (std::ostream & os, intrusive<Y> const & p)
{
os << p.get();
return os;
@@ -275,10 +277,10 @@
# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
using std::basic_ostream;
-template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
+template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive<Y> const & p)
# else
-template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
-# endif
+template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive<Y> const & p)
+# endif
{
os << p.get();
return os;
@@ -290,10 +292,11 @@
#endif // !defined(BOOST_NO_IOSTREAM)
+} // namespace generic_ptr
} // namespace boost
#ifdef BOOST_MSVC
# pragma warning(pop)
-#endif
+#endif
-#endif // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
+#endif // #ifndef BOOST_GENERIC_PTR_INTRUSIVE_HPP_INCLUDED
Added: sandbox/fmhess/boost/generic_ptr/monitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/fmhess/boost/generic_ptr/monitor.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -0,0 +1,144 @@
+//
+// generic_ptr/monitor.hpp
+//
+// Copyright (c) 2009 Frank Mori Hess
+//
+// 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/generic_ptr for documentation.
+//
+
+#ifndef BOOST_GENERIC_PTR_MONITOR_HPP_INCLUDED
+#define BOOST_GENERIC_PTR_MONITOR_HPP_INCLUDED
+
+#include <boost/generic_ptr/pointer_traits.hpp>
+#include <boost/generic_ptr/detail/unique_lock.hpp>
+#include <boost/generic_ptr/shared.hpp>
+#include <boost/utility/swap.hpp>
+
+namespace boost
+{
+ namespace generic_ptr
+ {
+ template<typename T, typename PointerToMutex>
+ class monitor
+ {
+ typedef monitor this_type;
+ //FIXME: take advantage of rvalue refs if available
+ template<typename Mutex>
+ class temporary_monitor_lock
+ {
+ public:
+ temporary_monitor_lock(T p, Mutex &m): _object_p(p),
+ _lock(new detail::unique_lock<Mutex>(m))
+ {}
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ temporary_monitor_lock(temporary_monitor_lock &&other):
+ _object_p(std::move(other._object_p),
+ _lock(std::move(other._lock))
+ {}
+#endif
+ T operator->() const
+ {
+ return _object_p;
+ }
+ private:
+ T _object_p;
+ shared<detail::unique_lock<Mutex> *> _lock;
+ };
+
+ public:
+ typedef typename pointer_traits<T>::value_type value_type;
+ typedef T pointer;
+ typedef typename pointer_traits<T>::reference reference;
+ typedef PointerToMutex pointer_to_mutex_type;
+ typedef typename pointer_traits<PointerToMutex>::value_type mutex_type;
+
+ template<typename ValueType>
+ struct rebind
+ {
+ typedef monitor<typename generic_ptr::rebind<pointer, ValueType>::other, PointerToMutex > other;
+ };
+
+ monitor(): px(), _mutex_p()
+ {}
+ template<typename U>
+ monitor( U p, PointerToMutex mutex_p ): px( p ), _mutex_p(mutex_p)
+ {}
+ template<typename U>
+ monitor(const monitor<U, pointer_to_mutex_type> & other): px(other.px), _mutex_p(other._mutex_p)
+ {}
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ monitor(monitor && other): px(std::move(other.px)), _mutex_p(std::move(other._mutex_p)
+ {}
+ template<typename U>
+ monitor(monitor<U> && other): px(std::move(other.px)), _mutex_p(std::move(other._mutex_p)
+ {}
+#endif
+
+ void swap(monitor & other)
+ {
+ boost::swap(px, other.px);
+ boost::swap(_mutex_p, other._mutex_p);
+ }
+
+ monitor & operator=(const monitor & other)
+ {
+ monitor(other).swap(*this);
+ return *this;
+ }
+
+ template<typename U>
+ monitor & operator=(const monitor<U, pointer_to_mutex_type> & other)
+ {
+ monitor(other).swap(*this);
+ return *this;
+ }
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ monitor & operator=(monitor && other)
+ {
+ monitor(std::move(other)).swap(*this);
+ return *this;
+ }
+ template<typename U>
+ monitor & operator=(monitor<U, pointer_to_mutex_type> && other)
+ {
+ monitor(std::move(other)).swap(*this);
+ return *this;
+ }
+#endif
+ void reset()
+ {
+ monitor().swap(*this);
+ }
+ template<typename U> void reset(U object_p, pointer_to_mutex_type mutex_p)
+ {
+ monitor(object_p, mutex_p).swap(*this);
+ }
+
+ pointer get() const {return px;}
+ pointer_to_mutex_type get_mutex() const {return _mutex_p;}
+
+// implicit conversion to "bool"
+#include <boost/generic_ptr/detail/operator_bool.hpp>
+
+ temporary_monitor_lock<mutex_type> operator->() const
+ {
+ return temporary_monitor_lock<mutex_type>(px, *_mutex_p);
+ }
+ private:
+ pointer px;
+ pointer_to_mutex_type _mutex_p;
+ };
+
+ template<typename T, typename PointerToMutex>
+ T get_pointer(const monitor<T, PointerToMutex> &mp)
+ {
+ return mp.get();
+ }
+ } // namespace generic_ptr
+} // namespace boost
+
+#endif // #ifndef BOOST_GENERIC_PTR_MONITOR_HPP_INCLUDED
Added: sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -0,0 +1,113 @@
+//
+// generic_ptr/pointer_traits.hpp
+//
+// Copyright (c) 2009 Frank Mori Hess
+//
+// 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/generic_ptr for documentation.
+//
+
+#ifndef BOOST_GENERIC_PTR_POINTER_TRAITS_HPP_INCLUDED
+#define BOOST_GENERIC_PTR_POINTER_TRAITS_HPP_INCLUDED
+
+#include <boost/get_pointer.hpp>
+#include <boost/mpl/identity.hpp>
+
+namespace boost
+{
+ namespace generic_ptr
+ {
+ template<typename T> struct pointer_traits
+ {
+ typedef typename T::value_type value_type;
+ typedef typename T::pointer pointer;
+ typedef typename T::reference reference;
+ };
+
+ template<typename T> struct pointer_traits<T*>
+ {
+ typedef T value_type;
+ typedef T * pointer;
+ typedef T & reference;
+ };
+
+ template<> struct pointer_traits<void*>
+ {
+ typedef void value_type;
+ typedef void * pointer;
+ typedef void reference;
+ };
+
+ template<> struct pointer_traits<const void*>
+ {
+ typedef void value_type;
+ typedef const void * pointer;
+ typedef void reference;
+ };
+
+ template<> struct pointer_traits<volatile void*>
+ {
+ typedef void value_type;
+ typedef volatile void * pointer;
+ typedef void reference;
+ };
+
+ template<> struct pointer_traits<const volatile void*>
+ {
+ typedef void value_type;
+ typedef const volatile void * pointer;
+ typedef void reference;
+ };
+
+ template<typename T>
+ T * get_plain_old_pointer(T * p)
+ {
+ return p;
+ }
+
+ template<typename GenericPtr>
+ typename pointer_traits<GenericPtr>::value_type *
+ get_plain_old_pointer(GenericPtr gp)
+ {
+ using boost::get_pointer;
+ return get_plain_old_pointer(get_pointer(gp));
+ }
+
+ // two-argument cast overloads for raw pointers (really belongs in boost/pointer_cast.hpp)
+ template<typename T, typename U>
+ T* static_pointer_cast(U *r, boost::mpl::identity<T>)
+ {
+ return static_cast<T*>(r);
+ }
+
+ template<typename T, typename U>
+ T* const_pointer_cast(U *r, boost::mpl::identity<T>)
+ {
+ return const_cast<T*>(r);
+ }
+
+ template<typename T, typename U>
+ T* dynamic_pointer_cast(U *r, boost::mpl::identity<T>)
+ {
+ return dynamic_cast<T*>(r);
+ }
+
+ template<typename GenericPtr, typename ValueType>
+ struct rebind
+ {
+ typedef typename GenericPtr::template rebind<ValueType>::other other;
+ };
+
+ template<typename T, typename ValueType>
+ struct rebind<T*, ValueType>
+ {
+ typedef ValueType * other;
+ };
+
+ } // namespace generic_ptr
+} // namespace boost
+
+#endif // #ifndef BOOST_GENERIC_PTR_POINTER_TRAITS_HPP_INCLUDED
Modified: sandbox/fmhess/boost/generic_ptr/shared.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/shared.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/shared.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -38,7 +38,8 @@
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
-#include <boost/get_pointer.hpp>
+#include <boost/generic_ptr/detail/util.hpp>
+#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/pointer_cast.hpp>
#include <boost/throw_exception.hpp>
@@ -79,93 +80,6 @@
template<typename T> class weak;
template<typename T> class enable_shared_from_this;
-template<typename T> struct pointer_traits
-{
- typedef typename T::value_type value_type;
- typedef typename T::pointer pointer;
- typedef typename T::reference reference;
-};
-
-template<typename T> struct pointer_traits<T*>
-{
- typedef T value_type;
- typedef T * pointer;
- typedef T & reference;
-};
-
-template<> struct pointer_traits<void*>
-{
- typedef void value_type;
- typedef void * pointer;
- typedef void reference;
-};
-
-template<> struct pointer_traits<const void*>
-{
- typedef void value_type;
- typedef const void * pointer;
- typedef void reference;
-};
-
-template<> struct pointer_traits<volatile void*>
-{
- typedef void value_type;
- typedef volatile void * pointer;
- typedef void reference;
-};
-
-template<> struct pointer_traits<const volatile void*>
-{
- typedef void value_type;
- typedef const volatile void * pointer;
- typedef void reference;
-};
-
-template<typename GenericPtr, typename ValueType>
-struct rebind
-{
- typedef typename GenericPtr::template rebind<ValueType>::other other;
-};
-
-template<typename T, typename ValueType>
-struct rebind<T*, ValueType>
-{
- typedef ValueType * other;
-};
-
-template<typename T>
-T * get_plain_old_pointer(T * p)
-{
- return p;
-}
-
-template<typename GenericPtr>
-typename pointer_traits<GenericPtr>::value_type *
- get_plain_old_pointer(GenericPtr gp)
-{
- using boost::get_pointer;
- return get_plain_old_pointer(get_pointer(gp));
-}
-
-// two-argument cast overloads for raw pointers (really belongs in boost/pointer_cast.hpp)
-template<typename T, typename U>
-T* static_pointer_cast(U *r, boost::mpl::identity<T>)
-{
- return static_cast<T*>(r);
-}
-
-template<typename T, typename U>
-T* const_pointer_cast(U *r, boost::mpl::identity<T>)
-{
- return const_cast<T*>(r);
-}
-
-template<typename T, typename U>
-T* dynamic_pointer_cast(U *r, boost::mpl::identity<T>)
-{
- return dynamic_cast<T*>(r);
-}
-
namespace detail
{
@@ -226,15 +140,6 @@
boost::detail::sp_enable_if_convertible<typename pointer_traits<Y>::value_type, typename pointer_traits<T>::value_type>
{};
-template<typename T>
-void set_plain_pointer_to_null(const T&)
-{}
-template<typename T>
-void set_plain_pointer_to_null(T * &p)
-{
- p = 0;
-}
-
} // namespace detail
@@ -253,8 +158,8 @@
public:
- typedef typename pointer_traits<T>::value_type element_type;
typedef typename pointer_traits<T>::value_type value_type;
+ typedef value_type element_type;
typedef T pointer;
typedef typename pointer_traits<T>::reference reference;
typedef weak<T> weak_type;
@@ -270,7 +175,7 @@
}
template<class Y>
- explicit shared( Y p ): px( p ), pn( p ) // Y must be complete
+ explicit shared( Y p ): px( p ), pn( get_plain_old_pointer(p) ) // Y must be complete
{
detail::sp_enable_shared_from_this( this, &p, get_plain_old_pointer(p) );
}
@@ -425,12 +330,12 @@
// Move support
-#if defined( BOOST_HAS_RVALUE_REFS )
+#ifndef BOOST_NO_RVALUE_REFERENCES
shared( shared && r ): px( r.px ), pn() // never throws
{
pn.swap( r.pn );
- detail::set_plain_pointer_to_null(r.px);
+ detail::set_plain_old_pointer_to_null(r.px);
}
template<class Y>
@@ -446,7 +351,7 @@
: px( r.px ), pn() // never throws
{
pn.swap( r.pn );
- detail::set_plain_pointer_to_null(r.px);
+ detail::set_plain_old_pointer_to_null(r.px);
}
shared & operator=( shared && r ) // never throws
@@ -507,55 +412,7 @@
}
// implicit conversion to "bool"
-
-#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
-
- operator bool () const
- {
- return get_plain_old_pointer(px) != 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 get_plain_old_pointer(px) == 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 T (this_type::*unspecified_bool_type)() const;
-
- operator unspecified_bool_type() const // never throws
- {
- return get_plain_old_pointer(px) == 0 ? 0: &this_type::get;
- }
-
-#else
-
- typedef T this_type::*unspecified_bool_type;
-
- operator unspecified_bool_type() const // never throws
- {
- return get_plain_old_pointer(px) == 0 ? 0: &this_type::px;
- }
-
-#endif
-
- // operator! is redundant, but some compilers need it
- bool operator! () const // never throws
- {
- return get_plain_old_pointer(px) == 0;
- }
+#include <boost/generic_ptr/detail/operator_bool.hpp>
bool unique() const // never throws
{
Modified: sandbox/fmhess/boost/generic_ptr/weak.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/weak.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/weak.hpp 2009-07-24 17:16:01 EDT (Fri, 24 Jul 2009)
@@ -79,7 +79,7 @@
{
}
-#if defined( BOOST_HAS_RVALUE_REFS )
+#ifndef BOOST_NO_RVALUE_REFERENCES
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
@@ -93,13 +93,13 @@
#endif
: px(r.lock().get()), pn(std::move(r.pn)) // never throws
{
- detail::set_plain_pointer_to_null(r.px);
+ detail::set_plain_old_pointer_to_null(r.px);
}
// for better efficiency in the T == Y case
weak( weak && r ): px( r.px ), pn(std::move(r.pn)) // never throws
{
- detail::set_plain_pointer_to_null(r.px);
+ detail::set_plain_old_pointer_to_null(r.px);
}
// for better efficiency in the T == Y case
@@ -136,7 +136,7 @@
return *this;
}
-#if defined( BOOST_HAS_RVALUE_REFS )
+#ifndef BOOST_NO_RVALUE_REFERENCES
template<class Y>
weak & operator=(weak<Y> && r)
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