[Libreoffice-commits] core.git: include/unotools unotools/source
Xisco Fauli
anistenis at gmail.com
Thu Jun 16 06:43:17 UTC 2016
include/unotools/extendedsecurityoptions.hxx | 24 +-------------
unotools/source/config/extendedsecurityoptions.cxx | 35 +++++----------------
2 files changed, 11 insertions(+), 48 deletions(-)
New commits:
commit 2400c271748f85355b689391d3aec405fcf3bff7
Author: Xisco Fauli <anistenis at gmail.com>
Date: Wed Jun 15 20:22:29 2016 +0200
tdf#89329: use shared_ptr for pImpl in extendedsecurityoptions
Change-Id: I3d344c4872bbed9527f254a4eabc48534e38452f
Reviewed-on: https://gerrit.libreoffice.org/26326
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/include/unotools/extendedsecurityoptions.hxx b/include/unotools/extendedsecurityoptions.hxx
index 070e377..8726c72 100644
--- a/include/unotools/extendedsecurityoptions.hxx
+++ b/include/unotools/extendedsecurityoptions.hxx
@@ -24,6 +24,7 @@
#include <osl/mutex.hxx>
#include <rtl/ustring.hxx>
#include <unotools/options.hxx>
+#include <memory>
/*-************************************************************************************************************
@short forward declaration to our private date container implementation
@@ -52,17 +53,6 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtExtendedSecurityOptions : public utl
OPEN_ALWAYS
};
- /*-****************************************************************************************************
- @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
- *//*-*****************************************************************************************************/
-
SvtExtendedSecurityOptions();
virtual ~SvtExtendedSecurityOptions();
@@ -83,17 +73,7 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtExtendedSecurityOptions : public utl
// private member
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 SvtExtendedSecurityOptions_Impl* m_pDataContainer;
- static sal_Int32 m_nRefCount;
+ std::shared_ptr<SvtExtendedSecurityOptions_Impl> m_pImpl;
}; // class SvtExtendedSecurityOptions
diff --git a/unotools/source/config/extendedsecurityoptions.cxx b/unotools/source/config/extendedsecurityoptions.cxx
index 3a4f5cb..1fb58bd 100644
--- a/unotools/source/config/extendedsecurityoptions.cxx
+++ b/unotools/source/config/extendedsecurityoptions.cxx
@@ -239,45 +239,28 @@ Sequence< OUString > SvtExtendedSecurityOptions_Impl::GetPropertyNames()
return seqPropertyNames;
}
-// initialize static member
-// DON'T DO IT IN YOUR HEADER!
-// see definition for further information
-
-SvtExtendedSecurityOptions_Impl* SvtExtendedSecurityOptions::m_pDataContainer = nullptr;
-sal_Int32 SvtExtendedSecurityOptions::m_nRefCount = 0;
-
-// constructor
+std::weak_ptr<SvtExtendedSecurityOptions_Impl> m_pExtendedSecurityOptions;
SvtExtendedSecurityOptions::SvtExtendedSecurityOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetInitMutex() );
- // Increase our refcount ...
- ++m_nRefCount;
- // ... and initialize our data container only if it not already exist!
- if( m_pDataContainer == nullptr )
- {
- m_pDataContainer = new SvtExtendedSecurityOptions_Impl;
+ m_pImpl = m_pExtendedSecurityOptions.lock();
+ if( !m_pImpl )
+ {
+ m_pImpl = std::make_shared<SvtExtendedSecurityOptions_Impl>();
+ m_pExtendedSecurityOptions = m_pImpl;
ItemHolder1::holdConfigItem(E_EXTENDEDSECURITYOPTIONS);
}
}
-// destructor
-
SvtExtendedSecurityOptions::~SvtExtendedSecurityOptions()
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetInitMutex() );
- // 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
@@ -285,7 +268,7 @@ SvtExtendedSecurityOptions::~SvtExtendedSecurityOptions()
SvtExtendedSecurityOptions::OpenHyperlinkMode SvtExtendedSecurityOptions::GetOpenHyperlinkMode()
{
MutexGuard aGuard( GetInitMutex() );
- return m_pDataContainer->GetOpenHyperlinkMode();
+ return m_pImpl->GetOpenHyperlinkMode();
}
namespace
More information about the Libreoffice-commits
mailing list