tdf#89329: use shared_ptr for pImpl in addonsoptions
Change-Id: I159ba04fa70f324d2a7f5b3c592337b92c7f097d Reviewed-on: https://gerrit.libreoffice.org/26560 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
committed by
Noel Grandin
parent
08f2993b09
commit
3bdc5063f9
@@ -203,7 +203,6 @@ class AddonsOptions_Impl : public ConfigItem
|
||||
const MergeStatusbarInstructionContainer& GetMergeStatusbarInstructions() const { return m_aCachedStatusbarMergingInstructions;}
|
||||
void ReadConfigurationData();
|
||||
|
||||
|
||||
private:
|
||||
enum ImageSize
|
||||
{
|
||||
@@ -470,7 +469,6 @@ bool AddonsOptions_Impl::GetMergeToolbarInstructions(
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// public method
|
||||
|
||||
static Image ScaleImage( const Image &rImage, bool bBig )
|
||||
@@ -1471,43 +1469,30 @@ Sequence< OUString > AddonsOptions_Impl::GetPropertyNamesImages( const OUString&
|
||||
return lResult;
|
||||
}
|
||||
|
||||
// initialize static member
|
||||
// DON'T DO IT IN YOUR HEADER!
|
||||
// see definition for further information
|
||||
|
||||
AddonsOptions_Impl* AddonsOptions::m_pDataContainer = nullptr;
|
||||
sal_Int32 AddonsOptions::m_nRefCount = 0;
|
||||
|
||||
// constructor
|
||||
namespace{
|
||||
//global
|
||||
std::weak_ptr<AddonsOptions_Impl> g_pAddonsOptions;
|
||||
}
|
||||
|
||||
AddonsOptions::AddonsOptions()
|
||||
{
|
||||
// Global access, must be guarded (multithreading!).
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
// Increase our refcount ...
|
||||
++m_nRefCount;
|
||||
// ... and initialize our data container only if it not already exist!
|
||||
if( m_pDataContainer == nullptr )
|
||||
|
||||
m_pImpl = g_pAddonsOptions.lock();
|
||||
if( !m_pImpl )
|
||||
{
|
||||
m_pDataContainer = new AddonsOptions_Impl;
|
||||
m_pImpl = std::make_shared<AddonsOptions_Impl>();
|
||||
g_pAddonsOptions = m_pImpl;
|
||||
}
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
AddonsOptions::~AddonsOptions()
|
||||
{
|
||||
// Global access, must be guarded (multithreading!)
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
// 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
|
||||
@@ -1515,7 +1500,7 @@ AddonsOptions::~AddonsOptions()
|
||||
bool AddonsOptions::HasAddonsMenu() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->HasAddonsMenu();
|
||||
return m_pImpl->HasAddonsMenu();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1523,7 +1508,7 @@ bool AddonsOptions::HasAddonsMenu() const
|
||||
sal_Int32 AddonsOptions::GetAddonsToolBarCount() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsToolBarCount();
|
||||
return m_pImpl->GetAddonsToolBarCount();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1531,7 +1516,7 @@ sal_Int32 AddonsOptions::GetAddonsToolBarCount() const
|
||||
const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsMenu() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsMenu();
|
||||
return m_pImpl->GetAddonsMenu();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1539,7 +1524,7 @@ const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsMenu() cons
|
||||
const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsMenuBarPart() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsMenuBarPart();
|
||||
return m_pImpl->GetAddonsMenuBarPart();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1547,7 +1532,7 @@ const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsMenuBarPart
|
||||
const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsToolBarPart( sal_uInt32 nIndex ) const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsToolBarPart( nIndex );
|
||||
return m_pImpl->GetAddonsToolBarPart( nIndex );
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1555,7 +1540,7 @@ const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsToolBarPart
|
||||
const OUString AddonsOptions::GetAddonsToolbarResourceName( sal_uInt32 nIndex ) const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsToolbarResourceName( nIndex );
|
||||
return m_pImpl->GetAddonsToolbarResourceName( nIndex );
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1563,7 +1548,7 @@ const OUString AddonsOptions::GetAddonsToolbarResourceName( sal_uInt32 nIndex )
|
||||
const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsHelpMenu() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetAddonsHelpMenu();
|
||||
return m_pImpl->GetAddonsHelpMenu();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1571,7 +1556,7 @@ const Sequence< Sequence< PropertyValue > >& AddonsOptions::GetAddonsHelpMenu()
|
||||
const MergeMenuInstructionContainer& AddonsOptions::GetMergeMenuInstructions() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetMergeMenuInstructions();
|
||||
return m_pImpl->GetMergeMenuInstructions();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1581,14 +1566,14 @@ bool AddonsOptions::GetMergeToolbarInstructions(
|
||||
MergeToolbarInstructionContainer& rToolbarInstructions ) const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetMergeToolbarInstructions(
|
||||
return m_pImpl->GetMergeToolbarInstructions(
|
||||
rToolbarName, rToolbarInstructions );
|
||||
}
|
||||
|
||||
const MergeStatusbarInstructionContainer& AddonsOptions::GetMergeStatusbarInstructions() const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetMergeStatusbarInstructions();
|
||||
return m_pImpl->GetMergeStatusbarInstructions();
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1596,7 +1581,7 @@ const MergeStatusbarInstructionContainer& AddonsOptions::GetMergeStatusbarInstru
|
||||
Image AddonsOptions::GetImageFromURL( const OUString& aURL, bool bBig, bool bNoScale ) const
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
return m_pDataContainer->GetImageFromURL( aURL, bBig, bNoScale );
|
||||
return m_pImpl->GetImageFromURL( aURL, bBig, bNoScale );
|
||||
}
|
||||
|
||||
// public method
|
||||
@@ -1628,10 +1613,10 @@ Mutex& AddonsOptions::GetOwnStaticMutex()
|
||||
return *pMutex;
|
||||
}
|
||||
|
||||
IMPL_STATIC_LINK_NOARG_TYPED( AddonsOptions, Notify, void*, void )
|
||||
IMPL_LINK_NOARG_TYPED( AddonsOptions, Notify, void*, void )
|
||||
{
|
||||
MutexGuard aGuard( GetOwnStaticMutex() );
|
||||
m_pDataContainer->ReadConfigurationData();
|
||||
m_pImpl->ReadConfigurationData();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include <com/sun/star/uno/Sequence.h>
|
||||
#include <com/sun/star/beans/PropertyValue.hpp>
|
||||
#include <framework/fwedllapi.h>
|
||||
#include <memory>
|
||||
|
||||
/*-************************************************************************************************************
|
||||
@descr The method GetAddonsMenu() returns a list of property values.
|
||||
@@ -97,18 +98,6 @@ class AddonsOptions_Impl;
|
||||
class FWE_DLLPUBLIC AddonsOptions
|
||||
{
|
||||
public:
|
||||
|
||||
/*-****************************************************************************************************
|
||||
@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
|
||||
*//*-*****************************************************************************************************/
|
||||
|
||||
AddonsOptions();
|
||||
~AddonsOptions();
|
||||
|
||||
@@ -116,7 +105,6 @@ class FWE_DLLPUBLIC AddonsOptions
|
||||
@short returns if an addons menu is available
|
||||
@descr Call to retrieve if a addons menu is available
|
||||
|
||||
|
||||
@return true if there is a menu otherwise false
|
||||
*//*-*****************************************************************************************************/
|
||||
|
||||
@@ -126,7 +114,6 @@ class FWE_DLLPUBLIC AddonsOptions
|
||||
@short returns number of addons toolbars
|
||||
@descr Call to retrieve the number of addons toolbars
|
||||
|
||||
|
||||
@return number of addons toolbars
|
||||
*//*-*****************************************************************************************************/
|
||||
sal_Int32 GetAddonsToolBarCount() const ;
|
||||
@@ -208,10 +195,8 @@ class FWE_DLLPUBLIC AddonsOptions
|
||||
Image GetImageFromURL( const OUString& aURL, bool bBig, bool bNoScale ) const;
|
||||
Image GetImageFromURL( const OUString& aURL, bool bBig ) const;
|
||||
|
||||
|
||||
// private methods
|
||||
|
||||
|
||||
/*-****************************************************************************************************
|
||||
@short return a reference to a static mutex
|
||||
@descr These class is partially threadsafe (for de-/initialization only).
|
||||
@@ -229,21 +214,10 @@ class FWE_DLLPUBLIC AddonsOptions
|
||||
We create a static mutex only for one ime and use at different times.
|
||||
@return A reference to a static mutex member.
|
||||
*//*-*****************************************************************************************************/
|
||||
DECL_STATIC_LINK_TYPED( AddonsOptions, Notify, void*, void );
|
||||
DECL_LINK_TYPED( Notify, void*, void );
|
||||
|
||||
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 AddonsOptions_Impl* m_pDataContainer ;
|
||||
static sal_Int32 m_nRefCount ;
|
||||
|
||||
std::shared_ptr<AddonsOptions_Impl> m_pImpl;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user