Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55652 - in sandbox/fmhess: boost/generic_ptr libs/generic_ptr/test
From: fmhess_at_[hidden]
Date: 2009-08-18 13:17:49


Author: fmhess
Date: 2009-08-18 13:17:48 EDT (Tue, 18 Aug 2009)
New Revision: 55652
URL: http://svn.boost.org/trac/boost/changeset/55652

Log:
Added some tests for external smart pointer support, and fixed some issues.

Text files modified:
   sandbox/fmhess/boost/generic_ptr/pointer_cast.hpp | 74 ++++++++++++++++++++++++++++++++++++++++
   sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp | 18 +++++++++
   sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp | 25 ++++++++++++
   3 files changed, 115 insertions(+), 2 deletions(-)

Modified: sandbox/fmhess/boost/generic_ptr/pointer_cast.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/pointer_cast.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/pointer_cast.hpp 2009-08-18 13:17:48 EDT (Tue, 18 Aug 2009)
@@ -15,8 +15,35 @@
 
 #include <boost/generic_ptr/pointer_traits.hpp>
 
+namespace std
+{
+ template<typename T> class shared_ptr;
+ template<typename T, typename U>
+ shared_ptr<T> static_pointer_cast(const shared_ptr<U> &r);
+ template<typename T, typename U>
+ shared_ptr<T> const_pointer_cast(const shared_ptr<U> &r);
+ template<typename T, typename U>
+ shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U> &r);
+} // namespace std
+
 namespace boost
 {
+ template<typename T> class shared_ptr;
+ template<typename T, typename U>
+ shared_ptr<T> static_pointer_cast(const shared_ptr<U> &r);
+ template<typename T, typename U>
+ shared_ptr<T> const_pointer_cast(const shared_ptr<U> &r);
+ template<typename T, typename U>
+ shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U> &r);
+
+ template<typename T> class intrusive_ptr;
+ template<typename T, typename U>
+ intrusive_ptr<T> static_pointer_cast(const intrusive_ptr<U> &r);
+ template<typename T, typename U>
+ intrusive_ptr<T> const_pointer_cast(const intrusive_ptr<U> &r);
+ template<typename T, typename U>
+ intrusive_ptr<T> dynamic_pointer_cast(const intrusive_ptr<U> &r);
+
   namespace generic_ptr
   {
     // two-argument cast overloads for raw pointers
@@ -36,6 +63,53 @@
       return dynamic_cast<T*>(r);
     }
 
+ // two-argument cast overloads for some external smart pointer types
+ template<typename T, typename U>
+ shared_ptr<T> static_pointer_cast(const shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::static_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ shared_ptr<T> const_pointer_cast(const shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::const_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::dynamic_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ std::shared_ptr<T> static_pointer_cast(const std::shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return std::static_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ std::shared_ptr<T> const_pointer_cast(const std::shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return std::const_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ std::shared_ptr<T> dynamic_pointer_cast(const std::shared_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return std::dynamic_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ intrusive_ptr<T> static_pointer_cast(const intrusive_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::static_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ intrusive_ptr<T> const_pointer_cast(const intrusive_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::const_pointer_cast<T>(r);
+ }
+ template<typename T, typename U>
+ intrusive_ptr<T> dynamic_pointer_cast(const intrusive_ptr<U> &r, boost::mpl::identity<T>)
+ {
+ return boost::dynamic_pointer_cast<T>(r);
+ }
+
     template<typename ToValueType, typename U>
     typename rebind<U, ToValueType>::other static_pointer_cast(const U &r)
     {

Modified: sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/pointer_traits.hpp 2009-08-18 13:17:48 EDT (Tue, 18 Aug 2009)
@@ -104,6 +104,23 @@
 #endif
 
     template<typename T>
+ T* get_pointer(const std::shared_ptr<T> &p)
+ {
+ return p.get();
+ }
+ template<typename T>
+ T* get_pointer(const std::unique_ptr<T> &p)
+ {
+ return p.get();
+ }
+ template<typename GenericPointer>
+ typename pointer_traits<GenericPointer>::pointer get_pointer(const GenericPointer &p)
+ {
+ using boost::get_pointer;
+ return get_pointer(p);
+ }
+
+ template<typename T>
     T * get_plain_old_pointer(T * p)
     {
       return p;
@@ -113,7 +130,6 @@
     typename pointer_traits<GenericPtr>::value_type *
         get_plain_old_pointer(const GenericPtr &gp)
     {
- using boost::get_pointer;
       return get_plain_old_pointer(get_pointer(gp));
     }
 

Modified: sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp
==============================================================================
--- sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp (original)
+++ sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp 2009-08-18 13:17:48 EDT (Tue, 18 Aug 2009)
@@ -19,6 +19,8 @@
 #include <boost/generic_ptr/pointer_traits.hpp>
 #include <boost/generic_ptr/shared.hpp>
 #include <boost/generic_ptr/throwing.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/intrusive_ptr.hpp>
 
 namespace bgp = boost::generic_ptr;
 
@@ -245,6 +247,27 @@
     conversion_to_void_test(p, true);
     overload_resolution_test(p);
   }
- //TODO: add tests for external pointer types
+ // some tests for external pointer types
+ {
+ boost::shared_ptr<X> p(new X());
+ member_access_test(p);
+ dereference_test(p);
+ rebind_test(p);
+ cast_test(p);
+ conversion_to_base_test(p);
+ conversion_to_void_test(p);
+ overload_resolution_test(p);
+ }
+ {
+ X x;
+ boost::intrusive_ptr<X> p(&x);
+ member_access_test(p);
+ dereference_test(p);
+ rebind_test(p);
+ cast_test(p);
+ conversion_to_base_test(p);
+ // conversion_to_void_test(p); // intrusive doesn't support void pointers
+ overload_resolution_test(p);
+ }
   return boost::report_errors();
 }


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