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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 15 12:32:19 UTC 2018


 include/svx/galtheme.hxx         |    8 --
 svx/source/gallery2/galtheme.cxx |  121 ++++++++++++++-------------------------
 2 files changed, 49 insertions(+), 80 deletions(-)

New commits:
commit 95fe8fa97a62ae90b6d092c52d2fc6fae198e011
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Aug 13 15:31:04 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 15 14:31:57 2018 +0200

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

diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index 98bf45876bc0..c83ba9609565 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -53,8 +53,6 @@ struct GalleryObject
 };
 
 
-typedef ::std::vector< GalleryObject* > GalleryObjectList;
-
 class GalleryThemeEntry;
 class SgaObject;
 class FmFormModel;
@@ -78,7 +76,7 @@ class SVX_DLLPUBLIC GalleryTheme : public SfxBroadcaster
 
 private:
 
-    GalleryObjectList           aObjectList;
+    ::std::vector< std::unique_ptr<GalleryObject> > aObjectList;
     OUString                    m_aDestDir;
     bool                        m_bDestDirRelative;
     tools::SvRef<SotStorage>    aSvDrawStorageRef;
@@ -95,13 +93,13 @@ private:
     SAL_DLLPRIVATE bool         ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry);
     SAL_DLLPRIVATE void         ImplWrite();
     SAL_DLLPRIVATE const GalleryObject* ImplGetGalleryObject(sal_uInt32 nPos) const
-                                { return ( nPos < aObjectList.size() ) ? aObjectList[ nPos ] : nullptr; }
+                                { return aObjectList[ nPos ].get(); }
     const GalleryObject*        ImplGetGalleryObject( const INetURLObject& rURL );
 
     SAL_DLLPRIVATE sal_uInt32   ImplGetGalleryObjectPos( const GalleryObject* pObj ) const
                                 {
                                     for (sal_uInt32 i = 0, n = aObjectList.size(); i < n; ++i)
-                                        if ( pObj == aObjectList[ i ] )
+                                        if ( pObj == aObjectList[ i ].get() )
                                             return i;
                                     return SAL_MAX_UINT32;
                                 }
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 31fac1269a4d..02d8d07a7236 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -79,11 +79,11 @@ GalleryTheme::~GalleryTheme()
 {
     ImplWrite();
 
-    for (GalleryObject* pEntry : aObjectList)
+    for (auto & pEntry : aObjectList)
     {
-        Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry ) );
-        Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry ) );
-        delete pEntry;
+        Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
+        Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry.get() ) );
+        pEntry.reset();
     }
     aObjectList.clear();
 
@@ -126,12 +126,10 @@ bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, Ga
                 pEntry = new GalleryObject;
                 if ( nPos < aObjectList.size() )
                 {
-                    GalleryObjectList::iterator it = aObjectList.begin();
-                    ::std::advance( it, nPos );
-                    aObjectList.insert( it, pEntry );
+                    aObjectList.emplace( aObjectList.begin() + nPos, pEntry );
                 }
                 else
-                    aObjectList.push_back( pEntry );
+                    aObjectList.emplace_back( pEntry );
             }
             else
                 pEntry = pExistentEntry;
@@ -222,9 +220,9 @@ void GalleryTheme::ImplWrite()
 
 const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
 {
-    for (GalleryObject* i : aObjectList)
+    for (auto const & i : aObjectList)
         if ( i->aURL == rURL )
-            return i;
+            return i.get();
     return nullptr;
 }
 
@@ -295,7 +293,7 @@ INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, ConvertDat
 
             bExists = false;
 
-            for (GalleryObject* p : aObjectList)
+            for (auto const & p : aObjectList)
                 if ( p->aURL == aNewURL )
                 {
                     bExists = true;
@@ -375,7 +373,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
     {
         if (aObjectList[ iFoundPos ]->aURL == rObj.GetURL())
         {
-            pFoundEntry = aObjectList[ iFoundPos ];
+            pFoundEntry = aObjectList[ iFoundPos ].get();
             break;
         }
     }
@@ -416,64 +414,42 @@ std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
 
 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const
 {
-    const GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr;
+    const GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
 
-    if(pGalleryObject)
-    {
-        rBitmapEx = pGalleryObject->maPreviewBitmapEx;
-        rSize = pGalleryObject->maPreparedSize;
-        rTitle = pGalleryObject->maTitle;
-        rPath = pGalleryObject->maPath;
-    }
-    else
-    {
-        OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
-    }
+    rBitmapEx = pGalleryObject->maPreviewBitmapEx;
+    rSize = pGalleryObject->maPreparedSize;
+    rTitle = pGalleryObject->maTitle;
+    rPath = pGalleryObject->maPath;
 }
 
 void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath)
 {
-    GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr;
+    GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
 
-    if(pGalleryObject)
-    {
-        pGalleryObject->maPreviewBitmapEx = rBitmapEx;
-        pGalleryObject->maPreparedSize = rSize;
-        pGalleryObject->maTitle = rTitle;
-        pGalleryObject->maPath = rPath;
-    }
-    else
-    {
-        OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
-    }
+    pGalleryObject->maPreviewBitmapEx = rBitmapEx;
+    pGalleryObject->maPreparedSize = rSize;
+    pGalleryObject->maTitle = rTitle;
+    pGalleryObject->maPath = rPath;
 }
 
 void GalleryTheme::RemoveObject(sal_uInt32 nPos)
 {
-    GalleryObject* pEntry = nullptr;
-    if ( nPos < aObjectList.size() )
-    {
-        GalleryObjectList::iterator it = aObjectList.begin();
-        ::std::advance( it, nPos );
-        pEntry = *it;
-        aObjectList.erase( it );
-    }
+    auto it = aObjectList.begin() + nPos;
+    std::unique_ptr<GalleryObject> pEntry = std::move(*it);
+    aObjectList.erase( it );
 
     if( aObjectList.empty() )
         KillFile( GetSdgURL() );
 
-    if( pEntry )
-    {
-        if( SgaObjKind::SvDraw == pEntry->eObjKind )
-            aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
+    if( SgaObjKind::SvDraw == pEntry->eObjKind )
+        aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
 
-        Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry ) );
-        Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry ) );
-        delete pEntry;
+    Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
+    Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry.get() ) );
+    pEntry.reset();
 
-        ImplSetModified( true );
-        ImplBroadcast( nPos );
-    }
+    ImplSetModified( true );
+    ImplBroadcast( nPos );
 }
 
 bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
@@ -481,17 +457,14 @@ bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
     if (nOldPos == nNewPos || nOldPos >= aObjectList.size())
         return false;
 
-    GalleryObject* pEntry = aObjectList[nOldPos];
+    std::unique_ptr<GalleryObject> pEntry = std::move(aObjectList[nOldPos]);
 
-    GalleryObjectList::iterator it = aObjectList.begin();
-    ::std::advance(it, nNewPos);
-    aObjectList.insert(it, pEntry);
+    aObjectList.insert(aObjectList.begin() + nNewPos, std::move(pEntry));
 
     if (nNewPos < nOldPos)
         nOldPos++;
 
-    it = aObjectList.begin();
-    ::std::advance(it, nOldPos);
+    auto it = aObjectList.begin() + nOldPos;
     aObjectList.erase(it);
 
     ImplSetModified(true);
@@ -507,7 +480,6 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
 
     Graphic         aGraphic;
     OUString        aFormat;
-    GalleryObject*  pEntry;
     const sal_uInt32 nCount = aObjectList.size();
 
     LockBroadcaster();
@@ -522,7 +494,7 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
         if( pProgress )
             pProgress->Update( i, nCount - 1 );
 
-        pEntry = aObjectList[ i ];
+        GalleryObject* pEntry = aObjectList[ i ].get();
 
         const INetURLObject aURL( pEntry->aURL );
 
@@ -585,16 +557,16 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
     }
 
     // remove all entries with set flag
-    for ( GalleryObjectList::iterator it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */)
+    for ( auto it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */)
     {
         if( (*it)->mbDelete )
         {
-            Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), *it ) );
-            Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), *it ) );
-            delete *it;
+            Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), it->get() ) );
+            Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), it->get() ) );
             it = aObjectList.erase( it );
         }
-        else ++it;
+        else
+            ++it;
     }
 
     // update theme
@@ -610,9 +582,9 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
 
     if( pIStm && pTmpStm )
     {
-        for (GalleryObject* i : aObjectList)
+        for (auto & i : aObjectList)
         {
-            pEntry = i;
+            GalleryObject* pEntry = i.get();
             std::unique_ptr<SgaObject> pObj;
 
             switch( pEntry->eObjKind )
@@ -1371,24 +1343,23 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm )
 
     if( nCount <= ( 1 << 14 ) )
     {
-        GalleryObject*  pObj;
         INetURLObject   aRelURL1( GetParent()->GetRelativeURL() );
         INetURLObject   aRelURL2( GetParent()->GetUserURL() );
         sal_uInt32      nId1, nId2;
         bool            bRel;
 
-        for(GalleryObject* i : aObjectList)
+        for(auto & i : aObjectList)
         {
-            pObj = i;
+            GalleryObject* pObj = i.get();
             Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pObj ) );
             Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pObj ) );
-            delete pObj;
+            i.reset();
         }
         aObjectList.clear();
 
         for( sal_uInt32 i = 0; i < nCount; i++ )
         {
-            pObj = new GalleryObject;
+            std::unique_ptr<GalleryObject> pObj(new GalleryObject);
 
             OUString    aFileName;
             OUString    aPath;
@@ -1446,7 +1417,7 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm )
                     }
                 }
             }
-            aObjectList.push_back( pObj );
+            aObjectList.push_back( std::move(pObj) );
         }
 
         rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 );


More information about the Libreoffice-commits mailing list