sfx2/source/doc/objmisc.cxx  |    2 +-
 sfx2/source/doc/objxtor.cxx  |    1 +
 sfx2/source/inc/objshimp.hxx |    2 +-
 svx/source/form/fmundo.cxx   |   33 ++++++++++++---------------------
 svx/source/inc/fmundo.hxx    |    7 +++++--
 5 files changed, 20 insertions(+), 25 deletions(-)

New commits:
commit 358d31b4c862782a3717b8ad00cd8d5ddd6ea1e3
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Nov 8 10:14:19 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Nov 9 06:24:44 2023 +0100

    loplugin:fieldcast in SfxObjectShell_Impl
    
    Change-Id: Iae953c39abd66bf1a484590d322974382f25d278
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159173
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index c6bd3b62ddd6..dbd8c5ea059b 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1582,7 +1582,7 @@ SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
         DBG_ASSERT( pMedium, "No Medium" );
         pImpl->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
     }
-    return static_cast<SvKeyValueIterator*>( pImpl->xHeaderAttributes.get() );
+    return pImpl->xHeaderAttributes.get();
 }
 
 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 8c3029edd128..b29db8f509b2 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -78,6 +78,7 @@
 #include <sfx2/sfxuno.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
 #include <sfx2/infobar.hxx>
+#include <svtools/svparser.hxx>
 
 #include <basic/basicmanagerrepository.hxx>
 
diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx
index e7cf6e6ee062..793b4388702a 100644
--- a/sfx2/source/inc/objshimp.hxx
+++ b/sfx2/source/inc/objshimp.hxx
@@ -103,7 +103,7 @@ struct SfxObjectShell_Impl final : public 
::sfx2::IMacroDocumentAccess
     bool                bModalMode;
     bool                bRunningMacro;
     bool                bReadOnlyUI;
-    tools::SvRef<SvRefBase>  xHeaderAttributes;
+    tools::SvRef<SvKeyValueIterator>  xHeaderAttributes;
     ::rtl::Reference< SfxBaseModel >
                         pBaseModel;
     sal_uInt16          nStyleFilter;
commit a4f52e3bb7f034035ba90ac95611253098959dfd
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Nov 8 09:54:40 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Nov 9 06:24:34 2023 +0100

    loplugin:fieldcast in FmXUndoEnvironment
    
    which means we can also use unique_ptr to manage this field.
    
    Change-Id: Icf31fa718af455148601efafbcc69067c5c27a16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159172
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/svx/source/form/fmundo.cxx b/svx/source/form/fmundo.cxx
index 0c554afb4b02..9bbe99a81d6e 100644
--- a/svx/source/form/fmundo.cxx
+++ b/svx/source/form/fmundo.cxx
@@ -151,6 +151,9 @@ struct PropertyInfo
                                             // as if it's transient or 
persistent
 };
 
+}
+
+
 struct PropertySetInfo
 {
     typedef std::map<OUString, PropertyInfo> AllProperties;
@@ -160,17 +163,11 @@ struct PropertySetInfo
                                             // sal_False -> the set has _no_ 
such property or its value isn't empty
 };
 
-}
-
-typedef std::map<Reference< XPropertySet >, PropertySetInfo> 
PropertySetInfoCache;
-
-
 static OUString static_STR_UNDO_PROPERTY;
 
 
 FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel)
                    :rModel( _rModel )
-                   ,m_pPropertySetCache( nullptr )
                    ,m_pScriptingEnv( new svxform::FormScriptingEnvironment( 
_rModel ) )
                    ,m_Locks( 0 )
                    ,bReadOnly( false )
@@ -189,9 +186,6 @@ FmXUndoEnvironment::~FmXUndoEnvironment()
 {
     if ( !m_bDisposed )   // i120746, call FormScriptingEnvironment::dispose 
to avoid memory leak
         m_pScriptingEnv->dispose();
-
-    if (m_pPropertySetCache)
-        delete static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
 }
 
 void FmXUndoEnvironment::dispose()
@@ -515,10 +509,9 @@ void SAL_CALL FmXUndoEnvironment::disposing(const 
EventObject& e)
         Reference< XPropertySet > xSourceSet(e.Source, UNO_QUERY);
         if (xSourceSet.is())
         {
-            PropertySetInfoCache* pCache = 
static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
-            PropertySetInfoCache::iterator aSetPos = pCache->find(xSourceSet);
-            if (aSetPos != pCache->end())
-                pCache->erase(aSetPos);
+            PropertySetInfoCache::iterator aSetPos = 
m_pPropertySetCache->find(xSourceSet);
+            if (aSetPos != m_pPropertySetCache->end())
+                m_pPropertySetCache->erase(aSetPos);
         }
     }
 }
@@ -573,12 +566,11 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const 
PropertyChangeEvent& evt)
         //   which does not have a "ExternalData" property being <TRUE/>
 
         if (!m_pPropertySetCache)
-            m_pPropertySetCache = new PropertySetInfoCache;
-        PropertySetInfoCache* pCache = 
static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
+            m_pPropertySetCache = std::make_unique<PropertySetInfoCache>();
 
         // let's see if we know something about the set
-        PropertySetInfoCache::iterator aSetPos = pCache->find(xSet);
-        if (aSetPos == pCache->end())
+        PropertySetInfoCache::iterator aSetPos = 
m_pPropertySetCache->find(xSet);
+        if (aSetPos == m_pPropertySetCache->end())
         {
             PropertySetInfo aNewEntry;
             if (!::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xSet))
@@ -597,8 +589,8 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const 
PropertyChangeEvent& evt)
                     DBG_UNHANDLED_EXCEPTION("svx");
                 }
             }
-            aSetPos = pCache->emplace(xSet,aNewEntry).first;
-            DBG_ASSERT(aSetPos != pCache->end(), 
"FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there 
?");
+            aSetPos = m_pPropertySetCache->emplace(xSet,aNewEntry).first;
+            DBG_ASSERT(aSetPos != m_pPropertySetCache->end(), 
"FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there 
?");
         }
         else
         {   // is it the DataField property ?
@@ -711,8 +703,7 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const 
PropertyChangeEvent& evt)
         if (m_pPropertySetCache && evt.PropertyName == FM_PROP_CONTROLSOURCE)
         {
             Reference< XPropertySet >  xSet(evt.Source, UNO_QUERY);
-            PropertySetInfoCache* pCache = 
static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
-            PropertySetInfo& rSetInfo = (*pCache)[xSet];
+            PropertySetInfo& rSetInfo = (*m_pPropertySetCache)[xSet];
             rSetInfo.bHasEmptyControlSource = !evt.NewValue.hasValue() || 
::comphelper::getString(evt.NewValue).isEmpty();
         }
     }
diff --git a/svx/source/inc/fmundo.hxx b/svx/source/inc/fmundo.hxx
index 61792e1afa3f..f0e691fe67f4 100644
--- a/svx/source/inc/fmundo.hxx
+++ b/svx/source/inc/fmundo.hxx
@@ -24,7 +24,6 @@
 #include <svx/svdouno.hxx>
 #include "fmscriptingenv.hxx"
 
-
 #include <com/sun/star/util/XModifyListener.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
@@ -38,10 +37,13 @@
 
 
 #include <svl/lstner.hxx>
+#include <memory>
+#include <map>
 
 class FmFormModel;
 class FmFormObj;
 class SdrObject;
+struct PropertySetInfo;
 
 class FmUndoPropertyAction final : public SdrUndoAction
 {
@@ -114,6 +116,7 @@ public:
     static void DisposeElement( const css::uno::Reference< 
css::awt::XControlModel>& xReplaced );
 };
 
+typedef std::map<css::uno::Reference< css::beans::XPropertySet >, 
PropertySetInfo> PropertySetInfoCache;
 
 class FmXUndoEnvironment final
     : public ::cppu::WeakImplHelper<   css::beans::XPropertyChangeListener
@@ -184,7 +187,7 @@ private:
     void    switchListening( const css::uno::Reference< css::uno::XInterface 
>& _rxObject, bool _bStartListening );
 
     FmFormModel&                            rModel;
-    void*                                   m_pPropertySetCache;
+    std::unique_ptr<PropertySetInfoCache>   m_pPropertySetCache;
     ::rtl::Reference<svxform::FormScriptingEnvironment> m_pScriptingEnv;
     oslInterlockedCount                     m_Locks;
     ::osl::Mutex                            m_aMutex;

Reply via email to