include/tools/weakbase.h | 5 +++-- include/tools/weakbase.hxx | 26 +++++--------------------- 2 files changed, 8 insertions(+), 23 deletions(-)
New commits: commit c941b5a103b5f2105106834c74842a3909216f9a Author: Noel Grandin <n...@peralex.com> Date: Tue Jun 7 11:31:47 2016 +0200 remove some manual refcounting in tools Change-Id: Ic911b38f77dda7ce564f315a97624c9054c77a38 Reviewed-on: https://gerrit.libreoffice.org/26010 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noelgran...@gmail.com> diff --git a/include/tools/weakbase.h b/include/tools/weakbase.h index cd1ab64..aba255e 100644 --- a/include/tools/weakbase.h +++ b/include/tools/weakbase.h @@ -21,6 +21,7 @@ #include <sal/types.h> #include <osl/diagnose.h> +#include <rtl/ref.hxx> /** the template classes in this header are helper to implement weak references to implementation objects that are not refcounted. @@ -113,7 +114,7 @@ public: inline WeakReference<reference_type>& operator= (const WeakReference<reference_type> & handle); private: - WeakConnection< reference_type >* mpWeakConnection; + rtl::Reference<WeakConnection< reference_type >> mpWeakConnection; }; /** derive your implementation classes from this class if you want them to support weak references */ @@ -136,7 +137,7 @@ public: private: inline WeakConnection< reference_type >* getWeakConnection(); - WeakConnection< reference_type >* mpWeakConnection; + rtl::Reference<WeakConnection< reference_type >> mpWeakConnection; }; } diff --git a/include/tools/weakbase.hxx b/include/tools/weakbase.hxx index 4087160..bdbcded 100644 --- a/include/tools/weakbase.hxx +++ b/include/tools/weakbase.hxx @@ -31,7 +31,6 @@ template< class reference_type > inline WeakReference< reference_type >::WeakReference() { mpWeakConnection = new WeakConnection<reference_type>( 0 ); - mpWeakConnection->acquire(); } template< class reference_type > @@ -41,21 +40,17 @@ inline WeakReference< reference_type >::WeakReference( reference_type* pReferenc mpWeakConnection = pReference->getWeakConnection(); else mpWeakConnection = new WeakConnection<reference_type>( 0 ); - - mpWeakConnection->acquire(); } template< class reference_type > inline WeakReference< reference_type >::WeakReference( const WeakReference< reference_type >& rWeakRef ) { mpWeakConnection = rWeakRef.mpWeakConnection; - mpWeakConnection->acquire(); } template< class reference_type > inline WeakReference< reference_type >::~WeakReference() { - mpWeakConnection->release(); } template< class reference_type > @@ -73,20 +68,16 @@ inline reference_type * WeakReference< reference_type >::get() const template< class reference_type > inline void WeakReference< reference_type >::reset( reference_type* pReference ) { - mpWeakConnection->release(); - if( pReference ) mpWeakConnection = pReference->getWeakConnection(); else mpWeakConnection = new WeakConnection<reference_type>( 0 ); - - mpWeakConnection->acquire(); } template< class reference_type > inline reference_type * WeakReference< reference_type >::operator->() const { - OSL_PRECOND(mpWeakConnection, "tools::WeakReference::operator->() : null body"); + OSL_PRECOND(mpWeakConnection.is(), "tools::WeakReference::operator->() : null body"); return mpWeakConnection->mpReference; } @@ -126,10 +117,7 @@ inline WeakReference<reference_type>& WeakReference<reference_type>::operator= ( { if (&rReference != this) { - mpWeakConnection->release(); - mpWeakConnection = rReference.mpWeakConnection; - mpWeakConnection->acquire(); } return *this; } @@ -137,36 +125,32 @@ inline WeakReference<reference_type>& WeakReference<reference_type>::operator= ( template< class reference_type > inline WeakBase< reference_type >::WeakBase() { - mpWeakConnection = nullptr; } template< class reference_type > inline WeakBase< reference_type >::~WeakBase() { - if( mpWeakConnection ) + if( mpWeakConnection.is() ) { mpWeakConnection->mpReference = 0; - mpWeakConnection->release(); - mpWeakConnection = nullptr; } } template< class reference_type > inline void WeakBase< reference_type >::clearWeak() { - if( mpWeakConnection ) + if( mpWeakConnection.is() ) mpWeakConnection->mpReference = 0; } template< class reference_type > inline WeakConnection< reference_type >* WeakBase< reference_type >::getWeakConnection() { - if( !mpWeakConnection ) + if( !mpWeakConnection.is() ) { mpWeakConnection = new WeakConnection< reference_type >( static_cast< reference_type* >( this ) ); - mpWeakConnection->acquire(); } - return mpWeakConnection; + return mpWeakConnection.get(); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits