[Libreoffice-commits] core.git: include/svtools svtools/source
Xisco Fauli
anistenis at gmail.com
Thu Jun 16 06:53:34 UTC 2016
include/svtools/toolpanelopt.hxx | 29 +---------------------
svtools/source/config/toolpanelopt.cxx | 43 +++++++++++++--------------------
2 files changed, 20 insertions(+), 52 deletions(-)
New commits:
commit dad8d71f4a73b64e534c1977e09e54905b8e27e8
Author: Xisco Fauli <anistenis at gmail.com>
Date: Wed Jun 15 01:20:36 2016 +0200
tdf#89329: use shared_ptr for pImpl in toolpanelopt
Change-Id: I2035971f6633aed1389ffae5815c7000699b9735
Reviewed-on: https://gerrit.libreoffice.org/26279
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/include/svtools/toolpanelopt.hxx b/include/svtools/toolpanelopt.hxx
index 8fcda68..2480e2e 100644
--- a/include/svtools/toolpanelopt.hxx
+++ b/include/svtools/toolpanelopt.hxx
@@ -25,13 +25,8 @@
#include <osl/mutex.hxx>
#include <rtl/ustring.hxx>
#include <unotools/options.hxx>
+#include <memory>
-/** forward declaration to our private date container implementation
-
- We use these class as internal member to support small memory requirements.
- You can create the container if it is necessary. The class which use these mechanism
- is faster and smaller then a complete implementation!
-*/
class SvtToolPanelOptions_Impl;
/** collect information about sidebar group
@@ -41,16 +36,6 @@ class SvtToolPanelOptions_Impl;
class SVT_DLLPUBLIC SvtToolPanelOptions: public utl::detail::Options
{
public:
- /** standard constructor and destructor
-
- 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 ...
-
- \sa member m_nRefCount
- \sa member m_pDataContainer
- */
SvtToolPanelOptions();
virtual ~SvtToolPanelOptions();
@@ -77,17 +62,7 @@ class SVT_DLLPUBLIC SvtToolPanelOptions: public utl::detail::Options
SVT_DLLPRIVATE static ::osl::Mutex& GetInitMutex();
private:
-
- /**
- \attention
- Don't initialize these static members in these headers!
- \li Double defined symbols will be detected ...
- \li and unresolved externals exist at linking time.
- Do it in your source only.
- */
- static SvtToolPanelOptions_Impl* m_pDataContainer;
- static sal_Int32 m_nRefCount;
-
+ std::shared_ptr<SvtToolPanelOptions_Impl> m_pImpl;
};
#endif
diff --git a/svtools/source/config/toolpanelopt.cxx b/svtools/source/config/toolpanelopt.cxx
index bddf81d..5294886 100644
--- a/svtools/source/config/toolpanelopt.cxx
+++ b/svtools/source/config/toolpanelopt.cxx
@@ -297,20 +297,18 @@ Sequence< OUString > SvtToolPanelOptions_Impl::GetPropertyNames()
return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
}
-// initialize static member, see definition for further information
-// DON'T DO IT IN YOUR HEADER!
-SvtToolPanelOptions_Impl* SvtToolPanelOptions::m_pDataContainer = nullptr;
-sal_Int32 SvtToolPanelOptions::m_nRefCount = 0;
+std::weak_ptr<SvtToolPanelOptions_Impl> m_pOptions;
SvtToolPanelOptions::SvtToolPanelOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetInitMutex() );
- ++m_nRefCount;
- // ... and initialize our data container only if it not already exist!
- if( m_pDataContainer == nullptr )
+
+ m_pImpl = m_pOptions.lock();
+ if( !m_pImpl )
{
- m_pDataContainer = new SvtToolPanelOptions_Impl;
+ m_pImpl = std::make_shared<SvtToolPanelOptions_Impl>();
+ m_pOptions = m_pImpl;
}
}
@@ -318,63 +316,58 @@ SvtToolPanelOptions::~SvtToolPanelOptions()
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetInitMutex() );
- --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();
}
bool SvtToolPanelOptions::GetVisibleImpressView() const
{
- return m_pDataContainer->m_bVisibleImpressView;
+ return m_pImpl->m_bVisibleImpressView;
}
void SvtToolPanelOptions::SetVisibleImpressView(bool bVisible)
{
- m_pDataContainer->m_bVisibleImpressView = bVisible;
+ m_pImpl->m_bVisibleImpressView = bVisible;
}
bool SvtToolPanelOptions::GetVisibleOutlineView() const
{
- return m_pDataContainer->m_bVisibleOutlineView;
+ return m_pImpl->m_bVisibleOutlineView;
}
void SvtToolPanelOptions::SetVisibleOutlineView(bool bVisible)
{
- m_pDataContainer->m_bVisibleOutlineView = bVisible;
+ m_pImpl->m_bVisibleOutlineView = bVisible;
}
bool SvtToolPanelOptions::GetVisibleNotesView() const
{
- return m_pDataContainer->m_bVisibleNotesView;
+ return m_pImpl->m_bVisibleNotesView;
}
void SvtToolPanelOptions::SetVisibleNotesView(bool bVisible)
{
- m_pDataContainer->m_bVisibleNotesView = bVisible;
+ m_pImpl->m_bVisibleNotesView = bVisible;
}
bool SvtToolPanelOptions::GetVisibleHandoutView() const
{
- return m_pDataContainer->m_bVisibleHandoutView;
+ return m_pImpl->m_bVisibleHandoutView;
}
void SvtToolPanelOptions::SetVisibleHandoutView(bool bVisible)
{
- m_pDataContainer->m_bVisibleHandoutView = bVisible;
+ m_pImpl->m_bVisibleHandoutView = bVisible;
}
bool SvtToolPanelOptions::GetVisibleSlideSorterView() const
{
- return m_pDataContainer->m_bVisibleSlideSorterView;
+ return m_pImpl->m_bVisibleSlideSorterView;
}
void SvtToolPanelOptions::SetVisibleSlideSorterView(bool bVisible)
{
- m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
+ m_pImpl->m_bVisibleSlideSorterView = bVisible;
}
namespace
More information about the Libreoffice-commits
mailing list