From 7d9797e091c8295693e97c7068f79f42a7f02643 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Tue, 3 Jun 2014 01:58:57 +0200 Subject: [PATCH] SGSharedPtr: add constructor to convert from SGWeakPtr. --- simgear/structure/SGSharedPtr.hxx | 3 +++ simgear/structure/shared_ptr_test.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index 87497b8e..9e92a7b0 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -60,6 +60,9 @@ public: template SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) { get(_ptr); } + template + explicit SGSharedPtr(const SGWeakPtr& p): _ptr(0) + { reset(p.lock().get()); } ~SGSharedPtr(void) { reset(); } diff --git a/simgear/structure/shared_ptr_test.cpp b/simgear/structure/shared_ptr_test.cpp index d7b73641..877e1468 100644 --- a/simgear/structure/shared_ptr_test.cpp +++ b/simgear/structure/shared_ptr_test.cpp @@ -72,6 +72,9 @@ BOOST_AUTO_TEST_CASE( virtual_weak_ptr ) SGSharedPtr ptr1( weak_ptr.lock() ); BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 2 ); + // converting constructor + BOOST_REQUIRE_EQUAL( SGSharedPtr(weak_ptr), ptr1 ); + SGSharedPtr ptr2( weak_ptr.lock() ); BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 3 ); -- 2.39.5