Kaydet (Commit) dad8d71f authored tarafından Xisco Fauli's avatar Xisco Fauli Kaydeden (comit) Noel Grandin

tdf#89329: use shared_ptr for pImpl in toolpanelopt

Change-Id: I2035971f6633aed1389ffae5815c7000699b9735
Reviewed-on: https://gerrit.libreoffice.org/26279Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 94d2b31d
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment