summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-06-10 01:38:09 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-06-10 17:33:33 +0000
commitc17c4ca9f49f3f7f7c023c6afd172f43cf283a78 (patch)
tree87214bf7c0b69c112baf9ce451b6945c1c354a04
parentfd8f328462fc20d9a3a03b5f8ceb78faedeaa602 (diff)
tdf#89329: use shared_ptr for pImpl in ctloptions
Change-Id: I196f2bbff0e7796804c2d74eb68ebf914796993d Reviewed-on: https://gerrit.libreoffice.org/26138 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--include/svl/ctloptions.hxx3
-rw-r--r--svl/source/config/ctloptions.cxx76
2 files changed, 40 insertions, 39 deletions
diff --git a/include/svl/ctloptions.hxx b/include/svl/ctloptions.hxx
index 0cc0e5b8141a..518f73e1d6b1 100644
--- a/include/svl/ctloptions.hxx
+++ b/include/svl/ctloptions.hxx
@@ -22,6 +22,7 @@
#include <svl/svldllapi.h>
#include <sal/types.h>
#include <unotools/options.hxx>
+#include <memory>
class SvtCTLOptions_Impl;
@@ -30,7 +31,7 @@ class SvtCTLOptions_Impl;
class SVL_DLLPUBLIC SvtCTLOptions : public utl::detail::Options
{
private:
- SvtCTLOptions_Impl* m_pImp;
+ std::shared_ptr<SvtCTLOptions_Impl> m_pImpl;
public:
diff --git a/svl/source/config/ctloptions.cxx b/svl/source/config/ctloptions.cxx
index d95d4c5e7723..ef2a6106bfc2 100644
--- a/svl/source/config/ctloptions.cxx
+++ b/svl/source/config/ctloptions.cxx
@@ -373,26 +373,27 @@ void SvtCTLOptions_Impl::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumer
}
}
// global
+std::weak_ptr<SvtCTLOptions_Impl> pCTLOptions;
-static SvtCTLOptions_Impl* pCTLOptions = nullptr;
-static sal_Int32 nCTLRefCount = 0;
namespace { struct CTLMutex : public rtl::Static< osl::Mutex, CTLMutex > {}; }
SvtCTLOptions::SvtCTLOptions( bool bDontLoad )
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( CTLMutex::get() );
- if ( !pCTLOptions )
+
+ m_pImpl = pCTLOptions.lock();
+ if ( !m_pImpl )
{
- pCTLOptions = new SvtCTLOptions_Impl;
+ m_pImpl = std::make_shared<SvtCTLOptions_Impl>();
+ pCTLOptions = m_pImpl;
ItemHolder2::holdConfigItem(E_CTLOPTIONS);
}
- if( !bDontLoad && !pCTLOptions->IsLoaded() )
- pCTLOptions->Load();
- ++nCTLRefCount;
- m_pImp = pCTLOptions;
- m_pImp->AddListener(this);
+ if( !bDontLoad && !m_pImpl->IsLoaded() )
+ m_pImpl->Load();
+
+ m_pImpl->AddListener(this);
}
@@ -401,87 +402,86 @@ SvtCTLOptions::~SvtCTLOptions()
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( CTLMutex::get() );
- m_pImp->RemoveListener(this);
- if ( !--nCTLRefCount )
- DELETEZ( pCTLOptions );
+ m_pImpl->RemoveListener(this);
+ m_pImpl.reset();
}
void SvtCTLOptions::SetCTLFontEnabled( bool _bEnabled )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLFontEnabled( _bEnabled );
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLFontEnabled( _bEnabled );
}
bool SvtCTLOptions::IsCTLFontEnabled() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->IsCTLFontEnabled();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->IsCTLFontEnabled();
}
void SvtCTLOptions::SetCTLSequenceChecking( bool _bEnabled )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLSequenceChecking(_bEnabled);
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLSequenceChecking(_bEnabled);
}
bool SvtCTLOptions::IsCTLSequenceChecking() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->IsCTLSequenceChecking();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->IsCTLSequenceChecking();
}
void SvtCTLOptions::SetCTLSequenceCheckingRestricted( bool _bEnable )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLSequenceCheckingRestricted(_bEnable);
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLSequenceCheckingRestricted(_bEnable);
}
bool SvtCTLOptions::IsCTLSequenceCheckingRestricted() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->IsCTLSequenceCheckingRestricted();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->IsCTLSequenceCheckingRestricted();
}
void SvtCTLOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLSequenceCheckingTypeAndReplace(_bEnable);
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLSequenceCheckingTypeAndReplace(_bEnable);
}
bool SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->IsCTLSequenceCheckingTypeAndReplace();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->IsCTLSequenceCheckingTypeAndReplace();
}
void SvtCTLOptions::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLCursorMovement( _eMovement );
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLCursorMovement( _eMovement );
}
SvtCTLOptions::CursorMovement SvtCTLOptions::GetCTLCursorMovement() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->GetCTLCursorMovement();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->GetCTLCursorMovement();
}
void SvtCTLOptions::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals )
{
- assert(pCTLOptions->IsLoaded());
- pCTLOptions->SetCTLTextNumerals( _eNumerals );
+ assert(m_pImpl->IsLoaded());
+ m_pImpl->SetCTLTextNumerals( _eNumerals );
}
SvtCTLOptions::TextNumerals SvtCTLOptions::GetCTLTextNumerals() const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->GetCTLTextNumerals();
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->GetCTLTextNumerals();
}
bool SvtCTLOptions::IsReadOnly(EOption eOption) const
{
- assert(pCTLOptions->IsLoaded());
- return pCTLOptions->IsReadOnly(eOption);
+ assert(m_pImpl->IsLoaded());
+ return m_pImpl->IsReadOnly(eOption);
}