summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-06-15 19:57:51 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-06-16 06:43:44 +0000
commit11c2acfa5a837b7d1fff31e20a87eddbba08f742 (patch)
tree95d6e97b849a144cf66a4813edba261e6e51ce7f /unotools
parent2400c271748f85355b689391d3aec405fcf3bff7 (diff)
tdf#89329: use shared_ptr for pImpl in printwarningoptions
Change-Id: I0b202ae78d2afe5fad4aa4bb4a3323f2672b1b93 Reviewed-on: https://gerrit.libreoffice.org/26321 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/config/printwarningoptions.cxx48
1 files changed, 16 insertions, 32 deletions
diff --git a/unotools/source/config/printwarningoptions.cxx b/unotools/source/config/printwarningoptions.cxx
index 4cc0f26c108a..42b1059759eb 100644
--- a/unotools/source/config/printwarningoptions.cxx
+++ b/unotools/source/config/printwarningoptions.cxx
@@ -221,44 +221,28 @@ Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
return seqPropertyNames;
}
-// initialize static member
-// DON'T DO IT IN YOUR HEADER!
-// see definition for further information
-
-SvtPrintWarningOptions_Impl* SvtPrintWarningOptions::m_pDataContainer = nullptr;
-sal_Int32 SvtPrintWarningOptions::m_nRefCount = 0;
-
-// constructor
+std::weak_ptr<SvtPrintWarningOptions_Impl> m_pPrintWarningOptions;
SvtPrintWarningOptions::SvtPrintWarningOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetOwnStaticMutex() );
- // Increase our refcount ...
- ++m_nRefCount;
- // ... and initialize our data container only if it not already!
- if( m_pDataContainer == nullptr )
+
+ m_pImpl = m_pPrintWarningOptions.lock();
+ if( !m_pImpl )
{
- m_pDataContainer = new SvtPrintWarningOptions_Impl();
+ m_pImpl = std::make_shared<SvtPrintWarningOptions_Impl>();
+ m_pPrintWarningOptions = m_pImpl;
ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
}
}
-// destructor
-
SvtPrintWarningOptions::~SvtPrintWarningOptions()
{
// 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
@@ -266,7 +250,7 @@ SvtPrintWarningOptions::~SvtPrintWarningOptions()
bool SvtPrintWarningOptions::IsPaperSize() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->IsPaperSize();
+ return m_pImpl->IsPaperSize();
}
// public method
@@ -274,7 +258,7 @@ bool SvtPrintWarningOptions::IsPaperSize() const
bool SvtPrintWarningOptions::IsPaperOrientation() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->IsPaperOrientation();
+ return m_pImpl->IsPaperOrientation();
}
// public method
@@ -282,7 +266,7 @@ bool SvtPrintWarningOptions::IsPaperOrientation() const
bool SvtPrintWarningOptions::IsTransparency() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->IsTransparency();
+ return m_pImpl->IsTransparency();
}
// public method
@@ -290,7 +274,7 @@ bool SvtPrintWarningOptions::IsTransparency() const
void SvtPrintWarningOptions::SetPaperSize( bool bState )
{
MutexGuard aGuard( GetOwnStaticMutex() );
- m_pDataContainer->SetPaperSize( bState );
+ m_pImpl->SetPaperSize( bState );
}
// public method
@@ -298,7 +282,7 @@ void SvtPrintWarningOptions::SetPaperSize( bool bState )
void SvtPrintWarningOptions::SetPaperOrientation( bool bState )
{
MutexGuard aGuard( GetOwnStaticMutex() );
- m_pDataContainer->SetPaperOrientation( bState );
+ m_pImpl->SetPaperOrientation( bState );
}
// public method
@@ -306,19 +290,19 @@ void SvtPrintWarningOptions::SetPaperOrientation( bool bState )
void SvtPrintWarningOptions::SetTransparency( bool bState )
{
MutexGuard aGuard( GetOwnStaticMutex() );
- m_pDataContainer->SetTransparency( bState );
+ m_pImpl->SetTransparency( bState );
}
bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
+ return m_pImpl->IsModifyDocumentOnPrintingAllowed();
}
void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( bool bState )
{
MutexGuard aGuard( GetOwnStaticMutex() );
- m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState );
+ m_pImpl->SetModifyDocumentOnPrintingAllowed( bState );
}
namespace