Kaydet (Commit) 9d6e774f authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in Gallery

Change-Id: Ia12805bff0403fe260786360233be677ef91f710
Reviewed-on: https://gerrit.libreoffice.org/49208Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 748167da
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <cstdio> #include <cstdio>
#include <memory>
#include <vector> #include <vector>
class SvStream; class SvStream;
...@@ -78,8 +79,6 @@ public: ...@@ -78,8 +79,6 @@ public:
void SetId( sal_uInt32 nNewId, bool bResetThemeName ); void SetId( sal_uInt32 nNewId, bool bResetThemeName );
}; };
typedef ::std::vector< GalleryThemeEntry* > GalleryThemeList;
class SfxListener; class SfxListener;
class GalleryTheme; class GalleryTheme;
class GalleryThemeCacheEntry; class GalleryThemeCacheEntry;
...@@ -95,7 +94,7 @@ class SVX_DLLPUBLIC Gallery : public SfxBroadcaster ...@@ -95,7 +94,7 @@ class SVX_DLLPUBLIC Gallery : public SfxBroadcaster
private: private:
GalleryThemeList aThemeList; std::vector< std::unique_ptr<GalleryThemeEntry> > aThemeList;
GalleryCacheThemeList aThemeCache; GalleryCacheThemeList aThemeCache;
INetURLObject aRelURL; INetURLObject aRelURL;
INetURLObject aUserURL; INetURLObject aUserURL;
...@@ -111,6 +110,8 @@ private: ...@@ -111,6 +110,8 @@ private:
Gallery( const OUString& rMultiPath ); Gallery( const OUString& rMultiPath );
virtual ~Gallery() override; virtual ~Gallery() override;
Gallery& operator=( Gallery const & ) = delete; // MSVC2015 workaround
Gallery( Gallery const & ) = delete; // MSVC2015 workaround
public: public:
...@@ -118,7 +119,7 @@ public: ...@@ -118,7 +119,7 @@ public:
SAL_DLLPRIVATE size_t GetThemeCount() const { return aThemeList.size(); } SAL_DLLPRIVATE size_t GetThemeCount() const { return aThemeList.size(); }
SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( size_t nPos ) SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( size_t nPos )
{ return nPos < aThemeList.size() ? aThemeList[ nPos ] : nullptr; } { return nPos < aThemeList.size() ? aThemeList[ nPos ].get() : nullptr; }
SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( const OUString& rThemeName ) { return ImplGetThemeEntry( rThemeName ); } SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( const OUString& rThemeName ) { return ImplGetThemeEntry( rThemeName ); }
bool HasTheme( const OUString& rThemeName ); bool HasTheme( const OUString& rThemeName );
......
...@@ -259,10 +259,6 @@ Gallery::Gallery( const OUString& rMultiPath ) ...@@ -259,10 +259,6 @@ Gallery::Gallery( const OUString& rMultiPath )
Gallery::~Gallery() Gallery::~Gallery()
{ {
// erase theme list
for (GalleryThemeEntry* p : aThemeList)
delete p;
aThemeList.clear();
} }
Gallery* Gallery::GetGalleryInstance() Gallery* Gallery::GetGalleryInstance()
...@@ -478,7 +474,7 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO ...@@ -478,7 +474,7 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO
GalleryThemeEntry* pEntry = GalleryTheme::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly ); GalleryThemeEntry* pEntry = GalleryTheme::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
if( pEntry ) if( pEntry )
aThemeList.push_back( pEntry ); aThemeList.emplace_back( pEntry );
} }
} }
catch( const ucb::ContentCreationException& ) catch( const ucb::ContentCreationException& )
...@@ -508,16 +504,14 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO ...@@ -508,16 +504,14 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO
GalleryThemeEntry* Gallery::ImplGetThemeEntry( const OUString& rThemeName ) GalleryThemeEntry* Gallery::ImplGetThemeEntry( const OUString& rThemeName )
{ {
GalleryThemeEntry* pFound = nullptr;
if( !rThemeName.isEmpty() ) if( !rThemeName.isEmpty() )
{ {
for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i ) for ( size_t i = 0, n = aThemeList.size(); i < n; ++i )
if( rThemeName == aThemeList[ i ]->GetThemeName() ) if( rThemeName == aThemeList[ i ]->GetThemeName() )
pFound = aThemeList[ i ]; return aThemeList[ i ].get();
} }
return pFound; return nullptr;
} }
OUString Gallery::GetThemeName( sal_uInt32 nThemeId ) const OUString Gallery::GetThemeName( sal_uInt32 nThemeId ) const
...@@ -526,7 +520,7 @@ OUString Gallery::GetThemeName( sal_uInt32 nThemeId ) const ...@@ -526,7 +520,7 @@ OUString Gallery::GetThemeName( sal_uInt32 nThemeId ) const
for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i ) for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
{ {
GalleryThemeEntry* pEntry = aThemeList[ i ]; GalleryThemeEntry* pEntry = aThemeList[ i ].get();
if( nThemeId == pEntry->GetId() ) if( nThemeId == pEntry->GetId() )
pFound = pEntry; pFound = pEntry;
} }
...@@ -616,7 +610,7 @@ bool Gallery::CreateTheme( const OUString& rThemeName ) ...@@ -616,7 +610,7 @@ bool Gallery::CreateTheme( const OUString& rThemeName )
true, aURL, rThemeName, true, aURL, rThemeName,
false, true, 0, false ); false, true, 0, false );
aThemeList.push_back( pNewEntry ); aThemeList.emplace_back( pNewEntry );
delete new GalleryTheme( this, pNewEntry ); delete new GalleryTheme( this, pNewEntry );
Broadcast( GalleryHint( GalleryHintType::THEME_CREATED, rThemeName ) ); Broadcast( GalleryHint( GalleryHintType::THEME_CREATED, rThemeName ) );
bRet = true; bRet = true;
...@@ -673,11 +667,10 @@ bool Gallery::RemoveTheme( const OUString& rThemeName ) ...@@ -673,11 +667,10 @@ bool Gallery::RemoveTheme( const OUString& rThemeName )
KillFile( aStrURL ); KillFile( aStrURL );
} }
GalleryThemeList::const_iterator aEnd = aThemeList.end(); auto aEnd = aThemeList.end();
for ( GalleryThemeList::iterator it = aThemeList.begin(); it != aEnd; ++it ) for ( auto it = aThemeList.begin(); it != aEnd; ++it )
{ {
if ( pThemeEntry == *it ) { if ( pThemeEntry == it->get() ) {
delete pThemeEntry;
aThemeList.erase( it ); aThemeList.erase( it );
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment