diff options
-rw-r--r-- | include/svtools/toolpanelopt.hxx | 29 | ||||
-rw-r--r-- | svtools/source/config/toolpanelopt.cxx | 43 |
2 files changed, 20 insertions, 52 deletions
diff --git a/include/svtools/toolpanelopt.hxx b/include/svtools/toolpanelopt.hxx index 8fcda683e36f..2480e2e0d8e5 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 bddf81d75c82..5294886095fe 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 |