diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-15 20:15:13 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-16 06:47:09 +0000 |
commit | a25d1a111150288b066351dfe11f75e5e4f81cfb (patch) | |
tree | d1c9e8676cad1421befe3d39f2cfe0fdbd6fe213 /unotools | |
parent | 4c8ff754ea25a77476a31aec9a9214c30490f0ad (diff) |
tdf#89329: use shared_ptr for pImpl in historyoptions
Change-Id: I0020b7e66fe8e09db9a96127a77c3792afab63a8
Reviewed-on: https://gerrit.libreoffice.org/26324
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/historyoptions.cxx | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/unotools/source/config/historyoptions.cxx b/unotools/source/config/historyoptions.cxx index 70f66081d411..1cd25871da49 100644 --- a/unotools/source/config/historyoptions.cxx +++ b/unotools/source/config/historyoptions.cxx @@ -523,66 +523,47 @@ void SvtHistoryOptions_Impl::DeleteItem(EHistoryType eHistory, const OUString& s } } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtHistoryOptions_Impl* SvtHistoryOptions::m_pDataContainer = nullptr; -sal_Int32 SvtHistoryOptions::m_nRefCount = 0; - -// constructor +std::weak_ptr<SvtHistoryOptions_Impl> m_pHistoryOptions; SvtHistoryOptions::SvtHistoryOptions() { MutexGuard aGuard(theHistoryOptionsMutex::get()); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already exist! - if( m_pDataContainer == nullptr ) + m_pImpl = m_pHistoryOptions.lock(); + if( !m_pImpl ) { - m_pDataContainer = new SvtHistoryOptions_Impl; - + m_pImpl = std::make_shared<SvtHistoryOptions_Impl>(); + m_pHistoryOptions = m_pImpl; ItemHolder1::holdConfigItem(E_HISTORYOPTIONS); } } -// destructor - SvtHistoryOptions::~SvtHistoryOptions() { MutexGuard aGuard(theHistoryOptionsMutex::get()); - // 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(); } sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const { MutexGuard aGuard(theHistoryOptionsMutex::get()); - return m_pDataContainer->GetCapacity(eHistory); + return m_pImpl->GetCapacity(eHistory); } void SvtHistoryOptions::Clear( EHistoryType eHistory ) { MutexGuard aGuard(theHistoryOptionsMutex::get()); - m_pDataContainer->Clear( eHistory ); + m_pImpl->Clear( eHistory ); } Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const { MutexGuard aGuard(theHistoryOptionsMutex::get()); - return m_pDataContainer->GetList( eHistory ); + return m_pImpl->GetList( eHistory ); } void SvtHistoryOptions::AppendItem(EHistoryType eHistory, @@ -591,14 +572,14 @@ void SvtHistoryOptions::AppendItem(EHistoryType eHistory, { MutexGuard aGuard(theHistoryOptionsMutex::get()); - m_pDataContainer->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail); + m_pImpl->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail); } void SvtHistoryOptions::DeleteItem(EHistoryType eHistory, const OUString& sURL) { MutexGuard aGuard(theHistoryOptionsMutex::get()); - m_pDataContainer->DeleteItem(eHistory, sURL); + m_pImpl->DeleteItem(eHistory, sURL); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |