include/unotools/historyoptions.hxx | 13 +-------- unotools/source/config/historyoptions.cxx | 41 ++++++++---------------------- 2 files changed, 13 insertions(+), 41 deletions(-)
New commits: commit a25d1a111150288b066351dfe11f75e5e4f81cfb Author: Xisco Fauli <aniste...@gmail.com> Date: Wed Jun 15 20:15:13 2016 +0200 tdf#89329: use shared_ptr for pImpl in historyoptions Change-Id: I0020b7e66fe8e09db9a96127a77c3792afab63a8 Reviewed-on: https://gerrit.libreoffice.org/26324 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noelgran...@gmail.com> diff --git a/include/unotools/historyoptions.hxx b/include/unotools/historyoptions.hxx index 4c0d5a7..51601db 100644 --- a/include/unotools/historyoptions.hxx +++ b/include/unotools/historyoptions.hxx @@ -28,6 +28,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <rtl/ustring.hxx> #include <unotools/options.hxx> +#include <memory> // The method GetList() returns a list of property values. // Use follow defines to separate values by names. @@ -102,17 +103,7 @@ public: void DeleteItem(EHistoryType eHistory, const OUString& sURL); private: - - /* Attention - - Don't initialize these static members in these headers! - a) Double defined symbols will be detected ... - b) and unresolved externals exist at linking time. - Do it in your source only. - */ - - static SvtHistoryOptions_Impl* m_pDataContainer; - static sal_Int32 m_nRefCount; + std::shared_ptr<SvtHistoryOptions_Impl> m_pImpl; }; #endif // INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX diff --git a/unotools/source/config/historyoptions.cxx b/unotools/source/config/historyoptions.cxx index 70f6608..1cd2587 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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits