[Libreoffice-commits] core.git: 2 commits - extensions/source include/sfx2 sfx2/source

Noel Grandin noel.grandin at collabora.co.uk
Mon May 7 06:33:38 UTC 2018


 extensions/source/scanner/sane.cxx |   11 +++-----
 extensions/source/scanner/sane.hxx |    2 -
 include/sfx2/dinfdlg.hxx           |   11 ++++----
 sfx2/source/dialog/dinfdlg.cxx     |   46 +++++++++++++++++--------------------
 4 files changed, 33 insertions(+), 37 deletions(-)

New commits:
commit 91af898b2a9193219bd28aa64296eaf0e145beb6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri May 4 14:02:49 2018 +0200

    loplugin:useuniqueptr in Sane
    
    Change-Id: I06e9423e667ee87d767bbc17e62798ae0586e975
    Reviewed-on: https://gerrit.libreoffice.org/53877
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index 4bd94f30d83e..90eb652282b2 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -273,9 +273,7 @@ void Sane::ReloadOptions()
     mnOptions = pOptions[ 0 ];
     if( static_cast<size_t>(pZero->size) > sizeof( SANE_Word ) )
         fprintf( stderr, "driver returned numer of options with larger size tha SANE_Word !!!\n" );
-    if( mppOptions )
-        delete [] mppOptions;
-    mppOptions = new const SANE_Option_Descriptor*[ mnOptions ];
+    mppOptions.reset(new const SANE_Option_Descriptor*[ mnOptions ]);
     mppOptions[ 0 ] = pZero;
     for( int i = 1; i < mnOptions; i++ )
         mppOptions[ i ] = p_get_option_descriptor( maHandle, i );
@@ -323,8 +321,7 @@ void Sane::Close()
     if( maHandle )
     {
         p_close( maHandle );
-        delete [] mppOptions;
-        mppOptions = nullptr;
+        mppOptions.reset();
         maHandle = nullptr;
         mnDevice = -1;
     }
@@ -513,7 +510,7 @@ bool Sane::CheckConsistency( const char* pMes, bool bInit )
 
     if( bInit )
     {
-        pDescArray = mppOptions;
+        pDescArray = mppOptions.get();
         if( mppOptions )
             pZero = mppOptions[0];
         return true;
@@ -521,7 +518,7 @@ bool Sane::CheckConsistency( const char* pMes, bool bInit )
 
     bool bConsistent = true;
 
-    if( pDescArray != mppOptions )
+    if( pDescArray != mppOptions.get() )
         bConsistent = false;
     if( pZero != mppOptions[0] )
         bConsistent = false;
diff --git a/extensions/source/scanner/sane.hxx b/extensions/source/scanner/sane.hxx
index ae8b6861eff7..7145ab133b27 100644
--- a/extensions/source/scanner/sane.hxx
+++ b/extensions/source/scanner/sane.hxx
@@ -80,7 +80,7 @@ private:
     static SANE_Device**        ppDevices;
     static int                  nDevices;
 
-    const SANE_Option_Descriptor**  mppOptions;
+    std::unique_ptr<const SANE_Option_Descriptor*[]> mppOptions;
     int                             mnOptions;
     int                             mnDevice;
     SANE_Handle                     maHandle;
commit a36d67240c303101fb6a56e40ff46aa1023089f3
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri May 4 13:37:40 2018 +0200

    loplugin:useuniqueptr in SfxDocumentInfoItem and CustomPropertiesWindow
    
    Change-Id: I535200a5b26725cdefc3e6e3ce5e1e925e7a7bfd
    Reviewed-on: https://gerrit.libreoffice.org/53876
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/dinfdlg.hxx b/include/sfx2/dinfdlg.hxx
index 9516b74868d8..2e61a28583ee 100644
--- a/include/sfx2/dinfdlg.hxx
+++ b/include/sfx2/dinfdlg.hxx
@@ -46,6 +46,7 @@
 #include <sfx2/tabdlg.hxx>
 
 #include <boost/optional/optional.hpp>
+#include <memory>
 
 namespace com { namespace sun { namespace star {
     namespace document {
@@ -81,7 +82,7 @@ private:
     bool                         m_bDeleteUserData;
     bool                         m_bUseUserData;
     bool                         m_bUseThumbnailSave;
-    std::vector< CustomProperty* >    m_aCustomProperties;
+    std::vector< std::unique_ptr<CustomProperty> >    m_aCustomProperties;
     css::uno::Sequence< css::document::CmisProperty > m_aCmisProperties;
 
 public:
@@ -150,7 +151,7 @@ public:
     bool        IsUseThumbnailSave() const { return m_bUseThumbnailSave;}
 
 
-    std::vector< CustomProperty* >  GetCustomProperties() const;
+    std::vector< std::unique_ptr<CustomProperty> > GetCustomProperties() const;
     void        ClearCustomProperties();
     void        AddCustomProperty(  const OUString& sName,
                                     const css::uno::Any& rValue );
@@ -402,7 +403,7 @@ private:
     sal_Int32                           m_nTypeBoxWidth;
     sal_Int32                           m_nLineHeight;
     sal_Int32                           m_nScrollPos;
-    std::vector<CustomProperty*>        m_aCustomProperties;
+    std::vector<std::unique_ptr<CustomProperty>> m_aCustomProperties;
     std::vector<CustomPropertyLine*>    m_aCustomPropertiesLines;
     CustomPropertyLine*                 m_pCurrentLine;
     SvNumberFormatter                   m_aNumberFormatter;
@@ -455,7 +456,7 @@ public:
 
     css::uno::Sequence< css::beans::PropertyValue >
                         GetCustomProperties();
-    void                SetCustomProperties(const std::vector<CustomProperty*>& rProperties);
+    void                SetCustomProperties(std::vector< std::unique_ptr<CustomProperty> >&& rProperties);
     void                SetRemovedHdl( const Link<void*,void>& rLink ) { m_aRemovedHdl = rLink; }
 };
 
@@ -488,7 +489,7 @@ public:
     css::uno::Sequence<css::beans::PropertyValue>
                  GetCustomProperties() const
                         { return m_pPropertiesWin->GetCustomProperties(); }
-    void         SetCustomProperties(const std::vector<CustomProperty*>& rProperties);
+    void         SetCustomProperties(std::vector< std::unique_ptr<CustomProperty> >&& rProperties);
 
     void         Init(VclBuilderContainer& rParent);
     virtual void Resize() override;
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index f5d2ce07a86e..84ebee9d8c62 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -248,8 +248,8 @@ SfxDocumentInfoItem::SfxDocumentInfoItem( const OUString& rFile,
                 }
 
                 uno::Any aValue = xSet->getPropertyValue(pProps[i].Name);
-                CustomProperty* pProp = new CustomProperty( pProps[i].Name, aValue );
-                m_aCustomProperties.push_back( pProp );
+                std::unique_ptr<CustomProperty> pProp(new CustomProperty( pProps[i].Name, aValue ));
+                m_aCustomProperties.push_back( std::move(pProp) );
             }
         }
 
@@ -284,11 +284,11 @@ SfxDocumentInfoItem::SfxDocumentInfoItem( const SfxDocumentInfoItem& rItem )
     , m_bUseUserData( rItem.m_bUseUserData )
     , m_bUseThumbnailSave( rItem.m_bUseThumbnailSave )
 {
-    for (const CustomProperty* pOtherProp : rItem.m_aCustomProperties)
+    for (auto const & pOtherProp : rItem.m_aCustomProperties)
     {
-        CustomProperty* pProp = new CustomProperty( pOtherProp->m_sName,
-                                                    pOtherProp->m_aValue );
-        m_aCustomProperties.push_back( pProp );
+        std::unique_ptr<CustomProperty> pProp(new CustomProperty( pOtherProp->m_sName,
+                                                    pOtherProp->m_aValue ));
+        m_aCustomProperties.push_back( std::move(pProp) );
     }
 
     m_aCmisProperties = rItem.m_aCmisProperties;
@@ -402,7 +402,7 @@ void SfxDocumentInfoItem::UpdateDocumentInfo(
             }
         }
 
-        for (const CustomProperty* pProp : m_aCustomProperties)
+        for (auto const & pProp : m_aCustomProperties)
         {
             try
             {
@@ -438,14 +438,14 @@ void SfxDocumentInfoItem::SetUseThumbnailSave( bool bSet )
     m_bUseThumbnailSave = bSet;
 }
 
-std::vector< CustomProperty* > SfxDocumentInfoItem::GetCustomProperties() const
+std::vector< std::unique_ptr<CustomProperty> > SfxDocumentInfoItem::GetCustomProperties() const
 {
-    std::vector< CustomProperty* > aRet;
-    for (CustomProperty* pOtherProp : m_aCustomProperties)
+    std::vector< std::unique_ptr<CustomProperty> > aRet;
+    for (auto const & pOtherProp : m_aCustomProperties)
     {
-        CustomProperty* pProp = new CustomProperty( pOtherProp->m_sName,
-                                                    pOtherProp->m_aValue );
-        aRet.push_back( pProp );
+        std::unique_ptr<CustomProperty> pProp(new CustomProperty( pOtherProp->m_sName,
+                                                    pOtherProp->m_aValue ));
+        aRet.push_back( std::move(pProp) );
     }
 
     return aRet;
@@ -453,15 +453,13 @@ std::vector< CustomProperty* > SfxDocumentInfoItem::GetCustomProperties() const
 
 void SfxDocumentInfoItem::ClearCustomProperties()
 {
-    for (CustomProperty* pProp : m_aCustomProperties)
-        delete pProp;
     m_aCustomProperties.clear();
 }
 
 void SfxDocumentInfoItem::AddCustomProperty( const OUString& sName, const Any& rValue )
 {
-    CustomProperty* pProp = new CustomProperty( sName, rValue );
-    m_aCustomProperties.push_back( pProp );
+    std::unique_ptr<CustomProperty> pProp(new CustomProperty( sName, rValue ));
+    m_aCustomProperties.push_back( std::move(pProp) );
 }
 
 
@@ -1702,7 +1700,7 @@ void CustomPropertiesWindow::SetVisibleLineCount(sal_uInt32 nCount)
 
 void CustomPropertiesWindow::AddLine(const OUString& sName, Any const & rAny)
 {
-    m_aCustomProperties.push_back(new CustomProperty(sName, rAny));
+    m_aCustomProperties.push_back(std::unique_ptr<CustomProperty>(new CustomProperty(sName, rAny)));
     ReloadLinesContent();
 }
 
@@ -1864,9 +1862,9 @@ void CustomPropertiesWindow::StoreCustomProperties()
     }
 }
 
-void CustomPropertiesWindow::SetCustomProperties(const std::vector<CustomProperty*>& rProperties)
+void CustomPropertiesWindow::SetCustomProperties(std::vector< std::unique_ptr<CustomProperty> >&& rProperties)
 {
-    m_aCustomProperties = rProperties;
+    m_aCustomProperties = std::move(rProperties);
     ReloadLinesContent();
 }
 
@@ -2107,9 +2105,9 @@ void CustomPropertiesControl::AddLine( Any const & rAny )
         m_pVertScroll->DoScroll(nLineCount + 1);
 }
 
-void CustomPropertiesControl::SetCustomProperties(const std::vector<CustomProperty*>& rProperties)
+void CustomPropertiesControl::SetCustomProperties(std::vector< std::unique_ptr<CustomProperty> >&& rProperties)
 {
-    m_pPropertiesWin->SetCustomProperties(rProperties);
+    m_pPropertiesWin->SetCustomProperties(std::move(rProperties));
     long nLineCount = m_pPropertiesWin->GetTotalLineCount();
     m_pVertScroll->SetRangeMax(nLineCount + 1);
 }
@@ -2209,8 +2207,8 @@ void SfxCustomPropertiesPage::Reset( const SfxItemSet* rItemSet )
 {
     m_pPropertiesCtrl->ClearAllLines();
     const SfxDocumentInfoItem& rInfoItem = rItemSet->Get(SID_DOCINFO);
-    std::vector< CustomProperty* > aCustomProps = rInfoItem.GetCustomProperties();
-    m_pPropertiesCtrl->SetCustomProperties(aCustomProps);
+    std::vector< std::unique_ptr<CustomProperty> > aCustomProps = rInfoItem.GetCustomProperties();
+    m_pPropertiesCtrl->SetCustomProperties(std::move(aCustomProps));
 }
 
 DeactivateRC SfxCustomPropertiesPage::DeactivatePage( SfxItemSet* /*pSet*/ )


More information about the Libreoffice-commits mailing list