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

tdf#89329: use shared_ptr for pImpl in slidesorterbaropt

Change-Id: If5b7fd23448a584d1faebaf0a540e61f091471fa
Reviewed-on: https://gerrit.libreoffice.org/26331Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 9cef6583
......@@ -25,6 +25,7 @@
#include <osl/mutex.hxx>
#include <rtl/ustring.hxx>
#include <unotools/options.hxx>
#include <memory>
/** forward declaration to our private date container implementation
......@@ -41,16 +42,6 @@ class SvtSlideSorterBarOptions_Impl;
class SVT_DLLPUBLIC SvtSlideSorterBarOptions: 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
*/
SvtSlideSorterBarOptions();
virtual ~SvtSlideSorterBarOptions();
......@@ -79,17 +70,7 @@ class SVT_DLLPUBLIC SvtSlideSorterBarOptions: 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 SvtSlideSorterBarOptions_Impl* m_pDataContainer ;
static sal_Int32 m_nRefCount ;
std::shared_ptr<SvtSlideSorterBarOptions_Impl> m_pImpl;
};
#endif
......
......@@ -55,7 +55,7 @@ class SvtSlideSorterBarOptions_Impl : public ConfigItem
public:
SvtSlideSorterBarOptions_Impl();
virtual ~SvtSlideSorterBarOptions_Impl();
~SvtSlideSorterBarOptions_Impl() override;
/** called for notify of configmanager
......@@ -83,7 +83,7 @@ class SvtSlideSorterBarOptions_Impl : public ConfigItem
bool m_bVisibleDrawView;
private:
virtual void ImplCommit() override;
virtual void ImplCommit() final override;
/** return list of key names of our configuration management which represent oue module tree
......@@ -193,7 +193,8 @@ SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
{
assert(!IsModified()); // should have been committed
if (IsModified())
Commit();
}
static int lcl_MapPropertyName( const OUString& rCompare,
......@@ -343,20 +344,20 @@ void SvtSlideSorterBarOptions_Impl::SetVisibleViewImpl( bool& bVisibleView, bool
}
}
// initialize static member, see definition for further information
// DON'T DO IT IN YOUR HEADER!
SvtSlideSorterBarOptions_Impl* SvtSlideSorterBarOptions::m_pDataContainer = nullptr ;
sal_Int32 SvtSlideSorterBarOptions::m_nRefCount = 0 ;
namespace {
std::weak_ptr<SvtSlideSorterBarOptions_Impl> g_pSlideSorterBarOptions;
}
SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
{
// 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 = g_pSlideSorterBarOptions.lock();
if( !m_pImpl )
{
m_pDataContainer = new SvtSlideSorterBarOptions_Impl;
m_pImpl = std::make_shared<SvtSlideSorterBarOptions_Impl>();
g_pSlideSorterBarOptions = m_pImpl;
}
}
......@@ -364,75 +365,68 @@ SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
{
// 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 )
{
if (m_pDataContainer->IsModified())
m_pDataContainer->Commit();
delete m_pDataContainer;
m_pDataContainer = nullptr;
}
m_pImpl.reset();
}
bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
{
return m_pDataContainer->m_bVisibleImpressView && !comphelper::LibreOfficeKit::isActive();
return m_pImpl->m_bVisibleImpressView && !comphelper::LibreOfficeKit::isActive();
}
void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
{
m_pDataContainer->SetVisibleImpressView( bVisible );
m_pImpl->SetVisibleImpressView( bVisible );
}
bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
{
return m_pDataContainer->m_bVisibleOutlineView;
return m_pImpl->m_bVisibleOutlineView;
}
void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
{
m_pDataContainer->SetVisibleOutlineView( bVisible );
m_pImpl->SetVisibleOutlineView( bVisible );
}
bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
{
return m_pDataContainer->m_bVisibleNotesView;
return m_pImpl->m_bVisibleNotesView;
}
void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
{
m_pDataContainer->SetVisibleNotesView( bVisible );
m_pImpl->SetVisibleNotesView( bVisible );
}
bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
{
return m_pDataContainer->m_bVisibleHandoutView;
return m_pImpl->m_bVisibleHandoutView;
}
void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
{
m_pDataContainer->SetVisibleHandoutView( bVisible );
m_pImpl->SetVisibleHandoutView( bVisible );
}
bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
{
return m_pDataContainer->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
return m_pImpl->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
}
void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
{
m_pDataContainer->SetVisibleSlideSorterView( bVisible );
m_pImpl->SetVisibleSlideSorterView( bVisible );
}
bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
{
return m_pDataContainer->m_bVisibleDrawView;
return m_pImpl->m_bVisibleDrawView;
}
void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
{
m_pDataContainer->SetVisibleDrawView( bVisible );
m_pImpl->SetVisibleDrawView( 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