summaryrefslogtreecommitdiff
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
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>
-rw-r--r--include/unotools/printwarningoptions.hxx24
-rw-r--r--unotools/source/config/printwarningoptions.cxx48
2 files changed, 18 insertions, 54 deletions
diff --git a/include/unotools/printwarningoptions.hxx b/include/unotools/printwarningoptions.hxx
index 7c425539a6c2..b0f8ef9f2a63 100644
--- a/include/unotools/printwarningoptions.hxx
+++ b/include/unotools/printwarningoptions.hxx
@@ -25,6 +25,7 @@
#include <osl/mutex.hxx>
#include <rtl/ustring.hxx>
#include <unotools/options.hxx>
+#include <memory>
/*-************************************************************************************************************
@short forward declaration to our private date container implementation
@@ -43,17 +44,6 @@ class SvtPrintWarningOptions_Impl;
class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtPrintWarningOptions : public utl::detail::Options
{
public:
- /*-****************************************************************************************************
- @short standard constructor and destructor
- @descr This will initialize an instance with default values.
- We implement these class with a refcount mechanism! Every instance of this class increase it
- at create and decrease it at delete time - but all instances use the same data container!
- He is implemented as a static member ...
-
- @seealso member m_nRefCount
- @seealso member m_pDataContainer
- *//*-*****************************************************************************************************/
-
SvtPrintWarningOptions();
virtual ~SvtPrintWarningOptions();
@@ -86,17 +76,7 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtPrintWarningOptions : public utl::de
UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex();
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 SvtPrintWarningOptions_Impl* m_pDataContainer;
- static sal_Int32 m_nRefCount;
+ std::shared_ptr<SvtPrintWarningOptions_Impl> m_pImpl;
}; // class SvtPrintWarningOptions
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