]> git.mxchange.org Git - simgear.git/commitdiff
SGSharedPtr: add constructor to convert from SGWeakPtr.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 2 Jun 2014 23:58:57 +0000 (01:58 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 2 Jun 2014 23:58:57 +0000 (01:58 +0200)
simgear/structure/SGSharedPtr.hxx
simgear/structure/shared_ptr_test.cpp

index 87497b8e0bfde5ec02d0bc12c3b2697769837cdf..9e92a7b0f396530e7496e18ea59f1e44b98315bb 100644 (file)
@@ -60,6 +60,9 @@ public:
   template<typename U>
   SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get())
   { get(_ptr); }
+  template<typename U>
+  explicit SGSharedPtr(const SGWeakPtr<U>& p): _ptr(0)
+  { reset(p.lock().get()); }
   ~SGSharedPtr(void)
   { reset(); }
   
index d7b7364155f01447b29ca26ee5edc7269b353803..877e1468e2b6aceec8717f8c7b3f6f61c50b5168 100644 (file)
@@ -72,6 +72,9 @@ BOOST_AUTO_TEST_CASE( virtual_weak_ptr )
   SGSharedPtr<Base1> ptr1( weak_ptr.lock() );
   BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 2 );
 
+  // converting constructor
+  BOOST_REQUIRE_EQUAL( SGSharedPtr<Base1>(weak_ptr), ptr1 );
+
   SGSharedPtr<Base2> ptr2( weak_ptr.lock() );
   BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 3 );