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

Xisco Fauli anistenis at gmail.com
Tue Jun 14 11:21:14 UTC 2016


 include/unotools/misccfg.hxx       |    5 ++++
 unotools/source/config/misccfg.cxx |   42 ++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 23 deletions(-)

New commits:
commit 6eebac959595f4bd7d4bd40c8325f1bc2782b3b8
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Tue Jun 14 02:19:52 2016 +0200

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

diff --git a/include/unotools/misccfg.hxx b/include/unotools/misccfg.hxx
index 9aebe79..297e48e 100644
--- a/include/unotools/misccfg.hxx
+++ b/include/unotools/misccfg.hxx
@@ -21,11 +21,16 @@
 
 #include <unotools/unotoolsdllapi.h>
 #include <unotools/options.hxx>
+#include <memory>
 
 namespace utl
 {
+class SfxMiscCfg;
 class UNOTOOLS_DLLPUBLIC MiscCfg : public detail::Options
 {
+private:
+    std::shared_ptr<SfxMiscCfg> m_pImpl;
+
 public:
     MiscCfg( );
     virtual ~MiscCfg( );
diff --git a/unotools/source/config/misccfg.cxx b/unotools/source/config/misccfg.cxx
index e2ef188f..aad808b 100644
--- a/unotools/source/config/misccfg.cxx
+++ b/unotools/source/config/misccfg.cxx
@@ -33,8 +33,7 @@ namespace utl
 {
 class SfxMiscCfg;
 
-static SfxMiscCfg* g_pOptions = nullptr;
-static sal_Int32 nRefCount = 0;
+std::weak_ptr<SfxMiscCfg> m_pOptions;
 
 class SfxMiscCfg : public utl::ConfigItem
 {
@@ -51,7 +50,7 @@ private:
 
 public:
     SfxMiscCfg( );
-    virtual ~SfxMiscCfg( );
+    ~SfxMiscCfg( );
 
     virtual void            Notify( const css::uno::Sequence<OUString>& aPropertyNames) override;
 
@@ -82,6 +81,8 @@ SfxMiscCfg::SfxMiscCfg() :
 
 SfxMiscCfg::~SfxMiscCfg()
 {
+    if ( IsModified() )
+        Commit();
 }
 
 void SfxMiscCfg::SetNotFoundWarning( bool bSet)
@@ -185,68 +186,63 @@ MiscCfg::MiscCfg( )
 {
     // Global access, must be guarded (multithreading)
     ::osl::MutexGuard aGuard( LocalSingleton::get() );
-    if ( !g_pOptions )
+    m_pImpl = m_pOptions.lock();
+    if ( !m_pImpl )
     {
-        g_pOptions = new SfxMiscCfg;
-
+        m_pImpl = std::make_shared<SfxMiscCfg>();
+        m_pOptions = m_pImpl;
         ItemHolder1::holdConfigItem(E_MISCCFG);
     }
 
-    ++nRefCount;
-    g_pOptions->AddListener(this);
+    m_pImpl->AddListener(this);
 }
 
 MiscCfg::~MiscCfg( )
 {
     // Global access, must be guarded (multithreading)
     ::osl::MutexGuard aGuard( LocalSingleton::get() );
-    g_pOptions->RemoveListener(this);
-    if ( !--nRefCount )
-    {
-        if ( g_pOptions->IsModified() )
-            g_pOptions->Commit();
-        DELETEZ( g_pOptions );
-    }
+    m_pImpl->RemoveListener(this);
+    m_pImpl.reset();
 }
 
 bool MiscCfg::IsNotFoundWarning()   const
 {
-    return g_pOptions->IsNotFoundWarning();
+    return m_pImpl->IsNotFoundWarning();
 }
 
 void MiscCfg::SetNotFoundWarning(   bool bSet)
 {
-    g_pOptions->SetNotFoundWarning( bSet );
+    m_pImpl->SetNotFoundWarning( bSet );
 }
 
 bool MiscCfg::IsPaperSizeWarning()  const
 {
-    return g_pOptions->IsPaperSizeWarning();
+    return m_pImpl->IsPaperSizeWarning();
 }
 
 void MiscCfg::SetPaperSizeWarning(bool bSet)
 {
-    g_pOptions->SetPaperSizeWarning( bSet );
+    m_pImpl->SetPaperSizeWarning( bSet );
 }
 
 bool MiscCfg::IsPaperOrientationWarning()   const
 {
-    return g_pOptions->IsPaperOrientationWarning();
+    return m_pImpl->IsPaperOrientationWarning();
 }
 
 void MiscCfg::SetPaperOrientationWarning(   bool bSet)
 {
-    g_pOptions->SetPaperOrientationWarning( bSet );
+    m_pImpl->SetPaperOrientationWarning( bSet );
 }
 
 sal_Int32 MiscCfg::GetYear2000() const
 {
-    return g_pOptions->GetYear2000();
+    return m_pImpl->GetYear2000();
 }
 
 void MiscCfg::SetYear2000( sal_Int32 nSet )
 {
-    g_pOptions->SetYear2000( nSet );
+    m_pImpl->SetYear2000( nSet );
 }
 
 }


More information about the Libreoffice-commits mailing list