[Libreoffice-commits] core.git: include/svtools svtools/source

Xisco Fauli anistenis at gmail.com
Fri Jun 17 09:33:37 UTC 2016


 include/svtools/helpopt.hxx       |    3 +-
 svtools/source/config/helpopt.cxx |   56 ++++++++++++++++++--------------------
 2 files changed, 29 insertions(+), 30 deletions(-)

New commits:
commit 81071d8a877c5883b871a2699955ab3ef62b0bee
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Jun 15 01:56:58 2016 +0200

    tdf#89329: use shared_ptr for pImpl in helpopt
    
    Change-Id: I9d3fa64405f70cfa942935eaae6cc520f172d70d
    Reviewed-on: https://gerrit.libreoffice.org/26281
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/svtools/helpopt.hxx b/include/svtools/helpopt.hxx
index c9f44c7..3651469 100644
--- a/include/svtools/helpopt.hxx
+++ b/include/svtools/helpopt.hxx
@@ -24,12 +24,13 @@
 #include <list>
 #include <rtl/ustring.hxx>
 #include <unotools/options.hxx>
+#include <memory>
 
 class SvtHelpOptions_Impl;
 
 class SVT_DLLPUBLIC SvtHelpOptions: public utl::detail::Options
 {
-    SvtHelpOptions_Impl*    pImp;
+    std::shared_ptr<SvtHelpOptions_Impl>    pImpl;
 
 public:
                     SvtHelpOptions();
diff --git a/svtools/source/config/helpopt.cxx b/svtools/source/config/helpopt.cxx
index 94edac0..ca6b9c0 100644
--- a/svtools/source/config/helpopt.cxx
+++ b/svtools/source/config/helpopt.cxx
@@ -36,9 +36,10 @@ using namespace utl;
 using namespace com::sun::star::uno;
 using namespace com::sun::star;
 
-
-static SvtHelpOptions_Impl* pOptions = nullptr;
-static sal_Int32           nRefCount = 0;
+namespace {
+    //global
+    std::weak_ptr<SvtHelpOptions_Impl> g_pHelpOptions;
+}
 
 enum class HelpProperty
 {
@@ -60,10 +61,11 @@ class SvtHelpOptions_Impl : public utl::ConfigItem
 
     static Sequence< OUString > GetPropertyNames();
 
-    virtual void    ImplCommit() override;
+    virtual void    ImplCommit() SAL_FINAL override;
 
 public:
                     SvtHelpOptions_Impl();
+                    ~SvtHelpOptions_Impl();
 
     virtual void    Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
     void            Load( const css::uno::Sequence< OUString>& aPropertyNames);
@@ -119,7 +121,6 @@ Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
     return *pMutex;
 }
 
-
 SvtHelpOptions_Impl::SvtHelpOptions_Impl()
     : ConfigItem( OUString( "Office.Common/Help" ) )
     , bExtendedHelp( false )
@@ -131,6 +132,11 @@ SvtHelpOptions_Impl::SvtHelpOptions_Impl()
     EnableNotification( aNames );
 }
 
+SvtHelpOptions_Impl::~SvtHelpOptions_Impl()
+{
+    if ( IsModified() )
+        Commit();
+}
 
 static int lcl_MapPropertyName( const OUString& rCompare,
                 const uno::Sequence< OUString>& aInternalPropertyNames)
@@ -211,7 +217,6 @@ void  SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
     }
 }
 
-
 void SvtHelpOptions_Impl::ImplCommit()
 {
     Sequence< OUString > aNames = GetPropertyNames();
@@ -246,7 +251,6 @@ void SvtHelpOptions_Impl::ImplCommit()
     PutProperties( aNames, aValues );
 }
 
-
 void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
 {
     Load( aPropertyNames );
@@ -256,73 +260,67 @@ SvtHelpOptions::SvtHelpOptions()
 {
     // Global access, must be guarded (multithreading)
     ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
-    ++nRefCount;
-    if ( !pOptions )
-    {
-        pOptions = new SvtHelpOptions_Impl;
 
+    pImpl = g_pHelpOptions.lock();
+    if ( !pImpl )
+    {
+        pImpl = std::make_shared<SvtHelpOptions_Impl>();
+        g_pHelpOptions = pImpl;
         svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
     }
-    pImp = pOptions;
 }
 
-
 SvtHelpOptions::~SvtHelpOptions()
 {
     // Global access, must be guarded (multithreading)
     ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
-    if ( !--nRefCount )
-    {
-        if ( pOptions->IsModified() )
-            pOptions->Commit();
-        DELETEZ( pOptions );
-    }
+
+    pImpl.reset();
 }
 
 void SvtHelpOptions::SetExtendedHelp( bool b )
 {
-    pImp->SetExtendedHelp( b );
+    pImpl->SetExtendedHelp( b );
 }
 
 bool SvtHelpOptions::IsExtendedHelp() const
 {
-    return pImp->IsExtendedHelp();
+    return pImpl->IsExtendedHelp();
 }
 
 void SvtHelpOptions::SetHelpTips( bool b )
 {
-    pImp->SetHelpTips( b );
+    pImpl->SetHelpTips( b );
 }
 
 bool SvtHelpOptions::IsHelpTips() const
 {
-    return pImp->IsHelpTips();
+    return pImpl->IsHelpTips();
 }
 
-
 void SvtHelpOptions::SetWelcomeScreen( bool b )
 {
-    pImp->SetWelcomeScreen( b );
+    pImpl->SetWelcomeScreen( b );
 }
 
 bool SvtHelpOptions::IsWelcomeScreen() const
 {
-    return pImp->IsWelcomeScreen();
+    return pImpl->IsWelcomeScreen();
 }
 
 OUString SvtHelpOptions::GetSystem() const
 {
-    return pImp->GetSystem();
+    return pImpl->GetSystem();
 }
 
 const OUString&   SvtHelpOptions::GetHelpStyleSheet()const
 {
-    return pImp->GetHelpStyleSheet();
+    return pImpl->GetHelpStyleSheet();
 }
 
 void  SvtHelpOptions::SetHelpStyleSheet(const OUString& rStyleSheet)
 {
-    pImp->SetHelpStyleSheet(rStyleSheet);
+    pImpl->SetHelpStyleSheet(rStyleSheet);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list