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

Xisco Fauli anistenis at gmail.com
Thu Jun 16 06:47:13 UTC 2016


 include/unotools/localisationoptions.hxx       |   24 +---------------
 unotools/source/config/localisationoptions.cxx |   37 ++++++-------------------
 2 files changed, 12 insertions(+), 49 deletions(-)

New commits:
commit 4c8ff754ea25a77476a31aec9a9214c30490f0ad
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Jun 15 20:11:15 2016 +0200

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

diff --git a/include/unotools/localisationoptions.hxx b/include/unotools/localisationoptions.hxx
index ff183fe..cfd706a 100644
--- a/include/unotools/localisationoptions.hxx
+++ b/include/unotools/localisationoptions.hxx
@@ -23,6 +23,7 @@
 #include <unotools/unotoolsdllapi.h>
 #include <osl/mutex.hxx>
 #include <unotools/options.hxx>
+#include <memory>
 
 /*-************************************************************************************************************
     @short          forward declaration to our private date container implementation
@@ -41,17 +42,6 @@ class SvtLocalisationOptions_Impl;
 class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtLocalisationOptions : public utl::detail::Options
 {
     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
-        *//*-*****************************************************************************************************/
-
          SvtLocalisationOptions();
         virtual ~SvtLocalisationOptions();
 
@@ -98,17 +88,7 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtLocalisationOptions : public utl::de
         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 SvtLocalisationOptions_Impl* m_pDataContainer;
-        static sal_Int32                    m_nRefCount;
+        std::shared_ptr<SvtLocalisationOptions_Impl> m_pImpl;
 
 };      // class SvtLocalisationOptions
 
diff --git a/unotools/source/config/localisationoptions.cxx b/unotools/source/config/localisationoptions.cxx
index 609577a..87ceaed 100644
--- a/unotools/source/config/localisationoptions.cxx
+++ b/unotools/source/config/localisationoptions.cxx
@@ -218,45 +218,28 @@ Sequence< OUString > SvtLocalisationOptions_Impl::GetPropertyNames()
     return seqPropertyNames;
 }
 
-//  initialize static member
-//  DON'T DO IT IN YOUR HEADER!
-//  see definition for further information
-
-SvtLocalisationOptions_Impl*    SvtLocalisationOptions::m_pDataContainer    = nullptr;
-sal_Int32                       SvtLocalisationOptions::m_nRefCount         = 0;
-
-//  constructor
+std::weak_ptr<SvtLocalisationOptions_Impl> m_pLocalisationOptions;
 
 SvtLocalisationOptions::SvtLocalisationOptions()
 {
     // 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_pDataContainer = new SvtLocalisationOptions_Impl;
 
+    m_pImpl = m_pLocalisationOptions.lock();
+    if( !m_pImpl )
+    {
+        m_pImpl = std::make_shared<SvtLocalisationOptions_Impl>();
+        m_pLocalisationOptions = m_pImpl;
         ItemHolder1::holdConfigItem(E_LOCALISATIONOPTIONS);
     }
 }
 
-//  destructor
-
 SvtLocalisationOptions::~SvtLocalisationOptions()
 {
     // 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
@@ -264,7 +247,7 @@ SvtLocalisationOptions::~SvtLocalisationOptions()
 bool SvtLocalisationOptions::IsAutoMnemonic() const
 {
     MutexGuard aGuard( GetOwnStaticMutex() );
-    return m_pDataContainer->IsAutoMnemonic();
+    return m_pImpl->IsAutoMnemonic();
 }
 
 //  public method
@@ -272,7 +255,7 @@ bool SvtLocalisationOptions::IsAutoMnemonic() const
 sal_Int32 SvtLocalisationOptions::GetDialogScale() const
 {
     MutexGuard aGuard( GetOwnStaticMutex() );
-    return m_pDataContainer->GetDialogScale();
+    return m_pImpl->GetDialogScale();
 }
 
 namespace


More information about the Libreoffice-commits mailing list