From 912f14c4e5c7db2a3acc0ae75995114ddfb12dea Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Wed, 15 Jun 2016 20:18:38 +0200 Subject: tdf#89329: use shared_ptr for pImpl in fontoptions Change-Id: I844f23d7674fe6e564575b150ba1f94754da4d3b Reviewed-on: https://gerrit.libreoffice.org/26325 Tested-by: Jenkins Reviewed-by: Noel Grandin --- unotools/source/config/fontoptions.cxx | 39 ++++++++++------------------------ 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'unotools') diff --git a/unotools/source/config/fontoptions.cxx b/unotools/source/config/fontoptions.cxx index 9214987a4506..4aa7732e7135 100644 --- a/unotools/source/config/fontoptions.cxx +++ b/unotools/source/config/fontoptions.cxx @@ -243,45 +243,28 @@ Sequence< OUString > SvtFontOptions_Impl::impl_GetPropertyNames() return seqPropertyNames; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtFontOptions_Impl* SvtFontOptions::m_pDataContainer = nullptr; -sal_Int32 SvtFontOptions::m_nRefCount = 0; - -// constructor +std::weak_ptr m_pFontOptions; SvtFontOptions::SvtFontOptions() { // Global access, must be guarded (multithreading!). MutexGuard aGuard( impl_GetOwnStaticMutex() ); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already exist! - if( m_pDataContainer == nullptr ) - { - m_pDataContainer = new SvtFontOptions_Impl; + m_pImpl = m_pFontOptions.lock(); + if( !m_pImpl ) + { + m_pImpl = std::make_shared(); + m_pFontOptions = m_pImpl; ItemHolder1::holdConfigItem(E_FONTOPTIONS); } } -// destructor - SvtFontOptions::~SvtFontOptions() { // Global access, must be guarded (multithreading!) MutexGuard aGuard( impl_GetOwnStaticMutex() ); - // Decrease our refcount. - --m_nRefCount; - // If last instance was deleted ... - // we must destroy our static data container! - if( m_nRefCount <= 0 ) - { - delete m_pDataContainer; - m_pDataContainer = nullptr; - } + + m_pImpl.reset(); } // public method @@ -289,7 +272,7 @@ SvtFontOptions::~SvtFontOptions() bool SvtFontOptions::IsFontHistoryEnabled() const { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - return m_pDataContainer->IsFontHistoryEnabled(); + return m_pImpl->IsFontHistoryEnabled(); } // public method @@ -297,7 +280,7 @@ bool SvtFontOptions::IsFontHistoryEnabled() const bool SvtFontOptions::IsFontWYSIWYGEnabled() const { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - return m_pDataContainer->IsFontWYSIWYGEnabled(); + return m_pImpl->IsFontWYSIWYGEnabled(); } // public method @@ -305,7 +288,7 @@ bool SvtFontOptions::IsFontWYSIWYGEnabled() const void SvtFontOptions::EnableFontWYSIWYG( bool bState ) { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - m_pDataContainer->EnableFontWYSIWYG( bState ); + m_pImpl->EnableFontWYSIWYG( bState ); } namespace -- cgit