diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-15 19:49:05 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-16 06:44:31 +0000 |
commit | 6cf574071e83663f8e1bcf70b0135a6258788a29 (patch) | |
tree | a3dbcb480a099f369ff1b57fdccbc926676b7212 /unotools | |
parent | 11c2acfa5a837b7d1fff31e20a87eddbba08f742 (diff) |
tdf#89329: use shared_ptr for pImpl in cmdoptions
Change-Id: Ie6297cf8c26964a6c7cc017c1257c61825c2c791
Reviewed-on: https://gerrit.libreoffice.org/26320
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/cmdoptions.cxx | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/unotools/source/config/cmdoptions.cxx b/unotools/source/config/cmdoptions.cxx index 82e5a93167d4..0fb89bee6343 100644 --- a/unotools/source/config/cmdoptions.cxx +++ b/unotools/source/config/cmdoptions.cxx @@ -286,44 +286,28 @@ Sequence< OUString > SvtCommandOptions_Impl::impl_GetPropertyNames() return lDisabledItems; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtCommandOptions_Impl* SvtCommandOptions::m_pDataContainer = nullptr; -sal_Int32 SvtCommandOptions::m_nRefCount = 0; - -// constructor +std::weak_ptr<SvtCommandOptions_Impl> m_pCommandOptions; SvtCommandOptions::SvtCommandOptions() { // Global access, must be guarded (multithreading!). MutexGuard aGuard( GetOwnStaticMutex() ); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already exist! - if( m_pDataContainer == nullptr ) + + m_pImpl = m_pCommandOptions.lock(); + if( !m_pImpl ) { - m_pDataContainer = new SvtCommandOptions_Impl; + m_pImpl = std::make_shared<SvtCommandOptions_Impl>(); + m_pCommandOptions = m_pImpl; ItemHolder1::holdConfigItem(E_CMDOPTIONS); } } -// destructor - SvtCommandOptions::~SvtCommandOptions() { // Global access, must be guarded (multithreading!) MutexGuard aGuard( 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 @@ -331,7 +315,7 @@ SvtCommandOptions::~SvtCommandOptions() bool SvtCommandOptions::HasEntries( CmdOption eOption ) const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->HasEntries( eOption ); + return m_pImpl->HasEntries( eOption ); } // public method @@ -339,7 +323,7 @@ bool SvtCommandOptions::HasEntries( CmdOption eOption ) const bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& aCommandURL ) const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->Lookup( eCmdOption, aCommandURL ); + return m_pImpl->Lookup( eCmdOption, aCommandURL ); } // public method @@ -347,7 +331,7 @@ bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& aCommandUR void SvtCommandOptions::EstablisFrameCallback(const css::uno::Reference< css::frame::XFrame >& xFrame) { MutexGuard aGuard( GetOwnStaticMutex() ); - m_pDataContainer->EstablisFrameCallback(xFrame); + m_pImpl->EstablisFrameCallback(xFrame); } namespace |