[Libreoffice-commits] core.git: include/unotools unotools/source
Xisco Fauli
anistenis at gmail.com
Thu Jun 16 06:45:08 UTC 2016
include/unotools/cmdoptions.hxx | 24 +--------------------
unotools/source/config/cmdoptions.cxx | 38 +++++++++-------------------------
2 files changed, 13 insertions(+), 49 deletions(-)
New commits:
commit 6cf574071e83663f8e1bcf70b0135a6258788a29
Author: Xisco Fauli <anistenis at gmail.com>
Date: Wed Jun 15 19:49:05 2016 +0200
tdf#89329: use shared_ptr for pImpl in cmdoptions
Change-Id: Ie6297cf8c26964a6c7cc017c1257c61825c2c791
Reviewed-on: https://gerrit.libreoffice.org/26320
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/include/unotools/cmdoptions.hxx b/include/unotools/cmdoptions.hxx
index 8e0b487..b5d0ad8 100644
--- a/include/unotools/cmdoptions.hxx
+++ b/include/unotools/cmdoptions.hxx
@@ -25,6 +25,7 @@
#include <com/sun/star/frame/XFrame.hpp>
#include <rtl/ustring.hxx>
#include <unotools/options.hxx>
+#include <memory>
/*-************************************************************************************************************
@descr The method GetList() returns a list of property values.
@@ -58,17 +59,6 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtCommandOptions : public utl::detail:
CMDOPTION_NONE
};
- /*-****************************************************************************************************
- @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
- *//*-*****************************************************************************************************/
-
SvtCommandOptions();
virtual ~SvtCommandOptions();
@@ -121,17 +111,7 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtCommandOptions : public utl::detail:
UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex();
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 SvtCommandOptions_Impl* m_pDataContainer;
- static sal_Int32 m_nRefCount;
+ std::shared_ptr<SvtCommandOptions_Impl> m_pImpl;
}; // class SvtCmdOptions
diff --git a/unotools/source/config/cmdoptions.cxx b/unotools/source/config/cmdoptions.cxx
index 82e5a93..0fb89be 100644
--- a/unotools/source/config/cmdoptions.cxx
+++ b/unotools/source/config/cmdoptions.cxx
@@ -286,44 +286,28 @@ Sequence< OUString > SvtCommandOptions_Impl::impl_GetPropertyNames()
return lDisabledItems;
}
-// initialize static member
-// DON'T DO IT IN YOUR HEADER!
-// see definition for further information
-
-SvtCommandOptions_Impl* SvtCommandOptions::m_pDataContainer = nullptr;
-sal_Int32 SvtCommandOptions::m_nRefCount = 0;
-
-// constructor
+std::weak_ptr<SvtCommandOptions_Impl> m_pCommandOptions;
SvtCommandOptions::SvtCommandOptions()
{
// 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 = m_pCommandOptions.lock();
+ if( !m_pImpl )
{
- m_pDataContainer = new SvtCommandOptions_Impl;
+ m_pImpl = std::make_shared<SvtCommandOptions_Impl>();
+ m_pCommandOptions = m_pImpl;
ItemHolder1::holdConfigItem(E_CMDOPTIONS);
}
}
-// destructor
-
SvtCommandOptions::~SvtCommandOptions()
{
// 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
@@ -331,7 +315,7 @@ SvtCommandOptions::~SvtCommandOptions()
bool SvtCommandOptions::HasEntries( CmdOption eOption ) const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->HasEntries( eOption );
+ return m_pImpl->HasEntries( eOption );
}
// public method
@@ -339,7 +323,7 @@ bool SvtCommandOptions::HasEntries( CmdOption eOption ) const
bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& aCommandURL ) const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->Lookup( eCmdOption, aCommandURL );
+ return m_pImpl->Lookup( eCmdOption, aCommandURL );
}
// public method
@@ -347,7 +331,7 @@ bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& aCommandUR
void SvtCommandOptions::EstablisFrameCallback(const css::uno::Reference< css::frame::XFrame >& xFrame)
{
MutexGuard aGuard( GetOwnStaticMutex() );
- m_pDataContainer->EstablisFrameCallback(xFrame);
+ m_pImpl->EstablisFrameCallback(xFrame);
}
namespace
More information about the Libreoffice-commits
mailing list