diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-15 20:11:15 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-16 06:46:37 +0000 |
commit | 4c8ff754ea25a77476a31aec9a9214c30490f0ad (patch) | |
tree | cac01a01f29d3cda936601282c93e633121b4ca9 /unotools | |
parent | 3c31796bedc77dc55ee645987da0922c17162454 (diff) |
tdf#89329: use shared_ptr for pImpl in localisationoptions
Change-Id: I9b2f7f7e59a71c056608635773c4b4fb2120a902
Reviewed-on: https://gerrit.libreoffice.org/26323
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/localisationoptions.cxx | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/unotools/source/config/localisationoptions.cxx b/unotools/source/config/localisationoptions.cxx index 609577af010e..87ceaedf172e 100644 --- a/unotools/source/config/localisationoptions.cxx +++ b/unotools/source/config/localisationoptions.cxx @@ -218,45 +218,28 @@ Sequence< OUString > SvtLocalisationOptions_Impl::GetPropertyNames() return seqPropertyNames; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtLocalisationOptions_Impl* SvtLocalisationOptions::m_pDataContainer = nullptr; -sal_Int32 SvtLocalisationOptions::m_nRefCount = 0; - -// constructor +std::weak_ptr<SvtLocalisationOptions_Impl> m_pLocalisationOptions; SvtLocalisationOptions::SvtLocalisationOptions() { // 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_pDataContainer = new SvtLocalisationOptions_Impl; + m_pImpl = m_pLocalisationOptions.lock(); + if( !m_pImpl ) + { + m_pImpl = std::make_shared<SvtLocalisationOptions_Impl>(); + m_pLocalisationOptions = m_pImpl; ItemHolder1::holdConfigItem(E_LOCALISATIONOPTIONS); } } -// destructor - SvtLocalisationOptions::~SvtLocalisationOptions() { // 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 @@ -264,7 +247,7 @@ SvtLocalisationOptions::~SvtLocalisationOptions() bool SvtLocalisationOptions::IsAutoMnemonic() const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->IsAutoMnemonic(); + return m_pImpl->IsAutoMnemonic(); } // public method @@ -272,7 +255,7 @@ bool SvtLocalisationOptions::IsAutoMnemonic() const sal_Int32 SvtLocalisationOptions::GetDialogScale() const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->GetDialogScale(); + return m_pImpl->GetDialogScale(); } namespace |