tdf#89329: use shared_ptr for pImpl in compatibility...

... and remove some, at least from my point of view,
useless comments

Change-Id: Id97c90dd7764ae4569468abc73c79ae9b2a56e75
Reviewed-on: https://gerrit.libreoffice.org/26235
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Xisco Fauli
2016-06-14 01:53:10 +02:00
committed by Noel Grandin
parent 7a60b2f3de
commit decc3bfae8
2 changed files with 24 additions and 80 deletions

View File

@@ -25,8 +25,7 @@
#include <com/sun/star/uno/Sequence.h> #include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <unotools/options.hxx> #include <unotools/options.hxx>
#include <memory>
// types, enums, ...
enum CompatibilityOptions enum CompatibilityOptions
{ {
@@ -84,24 +83,7 @@ class SvtCompatibilityOptions_Impl;
class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options
{ {
// public methods
public: public:
// constructor / destructor
/*-****************************************************************************************************
@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
*//*-*****************************************************************************************************/
SvtCompatibilityOptions(); SvtCompatibilityOptions();
virtual ~SvtCompatibilityOptions(); virtual ~SvtCompatibilityOptions();
@@ -164,8 +146,6 @@ class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options
bool IsConsiderWrappingStyle() const; bool IsConsiderWrappingStyle() const;
bool IsExpandWordSpace() const; bool IsExpandWordSpace() const;
// private methods
private: private:
/*-**************************************************************************************************** /*-****************************************************************************************************
@@ -178,20 +158,7 @@ class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options
UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex(); UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex();
// private member std::shared_ptr<SvtCompatibilityOptions_Impl> m_pImpl;
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 SvtCompatibilityOptions_Impl* m_pDataContainer;
static sal_Int32 m_nRefCount;
}; // class SvtCompatibilityOptions }; // class SvtCompatibilityOptions

View File

@@ -580,61 +580,40 @@ void SvtCompatibilityOptions_Impl::impl_ExpandPropertyNames(
} }
} }
// initialize static member std::weak_ptr<SvtCompatibilityOptions_Impl> m_pOptions;
// DON'T DO IT IN YOUR HEADER!
// see definition for further information
SvtCompatibilityOptions_Impl* SvtCompatibilityOptions::m_pDataContainer = nullptr;
sal_Int32 SvtCompatibilityOptions::m_nRefCount = 0;
// constructor
SvtCompatibilityOptions::SvtCompatibilityOptions() SvtCompatibilityOptions::SvtCompatibilityOptions()
{ {
// Global access, must be guarded (multithreading!). // Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
// Increase our refcount ...
++m_nRefCount; m_pImpl = m_pOptions.lock();
// ... and initialize our data container only if it not already exist! if( !m_pImpl )
if( m_pDataContainer == nullptr )
{ {
m_pDataContainer = new SvtCompatibilityOptions_Impl; m_pImpl = std::make_shared<SvtCompatibilityOptions_Impl>();
m_pOptions = m_pImpl;
ItemHolder1::holdConfigItem(E_COMPATIBILITY); ItemHolder1::holdConfigItem(E_COMPATIBILITY);
} }
} }
// destructor
SvtCompatibilityOptions::~SvtCompatibilityOptions() SvtCompatibilityOptions::~SvtCompatibilityOptions()
{ {
// Global access, must be guarded (multithreading!) // Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
// Decrease our refcount. m_pImpl.reset();
--m_nRefCount;
// If last instance was deleted ...
// we must destroy our static data container!
if( m_nRefCount <= 0 )
{
delete m_pDataContainer;
m_pDataContainer = nullptr;
}
} }
// public method
void SvtCompatibilityOptions::Clear() void SvtCompatibilityOptions::Clear()
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->Clear(); m_pImpl->Clear();
} }
void SvtCompatibilityOptions::SetDefault( const OUString & sName, bool bValue ) void SvtCompatibilityOptions::SetDefault( const OUString & sName, bool bValue )
{ {
m_pDataContainer->SetDefault( sName, bValue ); m_pImpl->SetDefault( sName, bValue );
} }
// public method
void SvtCompatibilityOptions::AppendItem( const OUString& sName, void SvtCompatibilityOptions::AppendItem( const OUString& sName,
const OUString& sModule, const OUString& sModule,
bool bUsePrtMetrics, bool bUsePrtMetrics,
@@ -651,7 +630,7 @@ void SvtCompatibilityOptions::AppendItem( const OUString& sName,
bool bProtectForm ) bool bProtectForm )
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->AppendItem( m_pImpl->AppendItem(
sName, sModule, bUsePrtMetrics, bAddSpacing, sName, sModule, bUsePrtMetrics, bAddSpacing,
bAddSpacingAtPages, bUseOurTabStops, bNoExtLeading, bAddSpacingAtPages, bUseOurTabStops, bNoExtLeading,
bUseLineSpacing, bAddTableSpacing, bUseObjPos, bUseLineSpacing, bAddTableSpacing, bUseObjPos,
@@ -661,73 +640,73 @@ void SvtCompatibilityOptions::AppendItem( const OUString& sName,
bool SvtCompatibilityOptions::IsUsePrtDevice() const bool SvtCompatibilityOptions::IsUsePrtDevice() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsUsePrtDevice(); return m_pImpl->IsUsePrtDevice();
} }
bool SvtCompatibilityOptions::IsAddSpacing() const bool SvtCompatibilityOptions::IsAddSpacing() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsAddSpacing(); return m_pImpl->IsAddSpacing();
} }
bool SvtCompatibilityOptions::IsAddSpacingAtPages() const bool SvtCompatibilityOptions::IsAddSpacingAtPages() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsAddSpacingAtPages(); return m_pImpl->IsAddSpacingAtPages();
} }
bool SvtCompatibilityOptions::IsUseOurTabStops() const bool SvtCompatibilityOptions::IsUseOurTabStops() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsUseOurTabStops(); return m_pImpl->IsUseOurTabStops();
} }
bool SvtCompatibilityOptions::IsNoExtLeading() const bool SvtCompatibilityOptions::IsNoExtLeading() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsNoExtLeading(); return m_pImpl->IsNoExtLeading();
} }
bool SvtCompatibilityOptions::IsUseLineSpacing() const bool SvtCompatibilityOptions::IsUseLineSpacing() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsUseLineSpacing(); return m_pImpl->IsUseLineSpacing();
} }
bool SvtCompatibilityOptions::IsAddTableSpacing() const bool SvtCompatibilityOptions::IsAddTableSpacing() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsAddTableSpacing(); return m_pImpl->IsAddTableSpacing();
} }
bool SvtCompatibilityOptions::IsUseObjectPositioning() const bool SvtCompatibilityOptions::IsUseObjectPositioning() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsUseObjPos(); return m_pImpl->IsUseObjPos();
} }
bool SvtCompatibilityOptions::IsUseOurTextWrapping() const bool SvtCompatibilityOptions::IsUseOurTextWrapping() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsUseOurTextWrapping(); return m_pImpl->IsUseOurTextWrapping();
} }
bool SvtCompatibilityOptions::IsConsiderWrappingStyle() const bool SvtCompatibilityOptions::IsConsiderWrappingStyle() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsConsiderWrappingStyle(); return m_pImpl->IsConsiderWrappingStyle();
} }
bool SvtCompatibilityOptions::IsExpandWordSpace() const bool SvtCompatibilityOptions::IsExpandWordSpace() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsExpandWordSpace(); return m_pImpl->IsExpandWordSpace();
} }
Sequence< Sequence< PropertyValue > > SvtCompatibilityOptions::GetList() const Sequence< Sequence< PropertyValue > > SvtCompatibilityOptions::GetList() const
{ {
MutexGuard aGuard( GetOwnStaticMutex() ); MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->GetList(); return m_pImpl->GetList();
} }
namespace namespace
@@ -735,8 +714,6 @@ namespace
class theCompatibilityOptionsMutex : public rtl::Static<osl::Mutex, theCompatibilityOptionsMutex>{}; class theCompatibilityOptionsMutex : public rtl::Static<osl::Mutex, theCompatibilityOptionsMutex>{};
} }
// private method
Mutex& SvtCompatibilityOptions::GetOwnStaticMutex() Mutex& SvtCompatibilityOptions::GetOwnStaticMutex()
{ {
return theCompatibilityOptionsMutex::get(); return theCompatibilityOptionsMutex::get();