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

loplugin:useuniqueptr in SvtFileView_Impl

Change-Id: I18f812354dcd6eed7e2fa6400401d40feea80d85
Reviewed-on: https://gerrit.libreoffice.org/53597Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 85409aa4
...@@ -194,7 +194,6 @@ namespace svt ...@@ -194,7 +194,6 @@ namespace svt
try try
{ {
SortingData_Impl* pData;
DateTime aDT; DateTime aDT;
bool bCancelled = false; bool bCancelled = false;
...@@ -204,8 +203,6 @@ namespace svt ...@@ -204,8 +203,6 @@ namespace svt
// don't show hidden files // don't show hidden files
if ( !bIsHidden || xRow->wasNull() ) if ( !bIsHidden || xRow->wasNull() )
{ {
pData = nullptr;
aDT = xRow->getTimestamp( ROW_DATE_MOD ); aDT = xRow->getTimestamp( ROW_DATE_MOD );
bool bContainsDate = !xRow->wasNull(); bool bContainsDate = !xRow->wasNull();
if ( !bContainsDate ) if ( !bContainsDate )
...@@ -227,7 +224,7 @@ namespace svt ...@@ -227,7 +224,7 @@ namespace svt
continue; continue;
} }
pData = new SortingData_Impl; std::unique_ptr<SortingData_Impl> pData(new SortingData_Impl);
pData->maTargetURL = sRealURL; pData->maTargetURL = sRealURL;
pData->mbIsFolder = xRow->getBoolean( ROW_IS_FOLDER ) && !xRow->wasNull(); pData->mbIsFolder = xRow->getBoolean( ROW_IS_FOLDER ) && !xRow->wasNull();
...@@ -288,7 +285,7 @@ namespace svt ...@@ -288,7 +285,7 @@ namespace svt
{ {
::osl::MutexGuard aGuard( m_rContentMutex ); ::osl::MutexGuard aGuard( m_rContentMutex );
m_rContent.push_back( pData ); m_rContent.push_back( std::move(pData) );
} }
} }
......
...@@ -177,7 +177,7 @@ namespace svt ...@@ -177,7 +177,7 @@ namespace svt
class FileViewContentEnumerator: public salhelper::Thread class FileViewContentEnumerator: public salhelper::Thread
{ {
public: public:
typedef ::std::vector< SortingData_Impl* > ContentData; typedef ::std::vector< std::unique_ptr<SortingData_Impl> > ContentData;
private: private:
ContentData& m_rContent; ContentData& m_rContent;
......
...@@ -322,13 +322,13 @@ protected: ...@@ -322,13 +322,13 @@ protected:
public: public:
::std::vector< SortingData_Impl* > maContent; ::std::vector< std::unique_ptr<SortingData_Impl> > maContent;
::osl::Mutex maMutex; ::osl::Mutex maMutex;
VclPtr<SvTreeListBox> mpCurView; VclPtr<SvTreeListBox> mpCurView;
VclPtr<ViewTabListBox_Impl> mpView; VclPtr<ViewTabListBox_Impl> mpView;
VclPtr<IconView> mpIconView; VclPtr<IconView> mpIconView;
NameTranslator_Impl* mpNameTrans; std::unique_ptr<NameTranslator_Impl> mpNameTrans;
sal_uInt16 mnSortColumn; sal_uInt16 mnSortColumn;
bool mbAscending : 1; bool mbAscending : 1;
bool mbOnlyFolder : 1; bool mbOnlyFolder : 1;
...@@ -1439,7 +1439,6 @@ SvtFileView_Impl::SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommand ...@@ -1439,7 +1439,6 @@ SvtFileView_Impl::SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommand
,m_eAsyncActionResult ( ::svt::EnumerationResult::ERROR ) ,m_eAsyncActionResult ( ::svt::EnumerationResult::ERROR )
,m_bRunningAsyncAction ( false ) ,m_bRunningAsyncAction ( false )
,m_bAsyncActionCancelled ( false ) ,m_bAsyncActionCancelled ( false )
,mpNameTrans ( nullptr )
,mnSortColumn ( COLUMN_TITLE ) ,mnSortColumn ( COLUMN_TITLE )
,mbAscending ( true ) ,mbAscending ( true )
,mbOnlyFolder ( bOnlyFolder ) ,mbOnlyFolder ( bOnlyFolder )
...@@ -1474,13 +1473,8 @@ void SvtFileView_Impl::Clear() ...@@ -1474,13 +1473,8 @@ void SvtFileView_Impl::Clear()
{ {
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
for (auto const& elem : maContent)
delete elem;
maContent.clear(); maContent.clear();
mpNameTrans.reset();
if( mpNameTrans )
DELETEZ( mpNameTrans );
} }
...@@ -1513,7 +1507,7 @@ FileViewResult SvtFileView_Impl::GetFolderContent_Impl( ...@@ -1513,7 +1507,7 @@ FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
OSL_ENSURE( !m_xContentEnumerator.is(), "SvtFileView_Impl::GetFolderContent_Impl: still running another enumeration!" ); OSL_ENSURE( !m_xContentEnumerator.is(), "SvtFileView_Impl::GetFolderContent_Impl: still running another enumeration!" );
m_xContentEnumerator.set(new ::svt::FileViewContentEnumerator( m_xContentEnumerator.set(new ::svt::FileViewContentEnumerator(
mpView->GetCommandEnvironment(), maContent, maMutex, mbReplaceNames ? mpNameTrans : nullptr)); mpView->GetCommandEnvironment(), maContent, maMutex, mbReplaceNames ? mpNameTrans.get() : nullptr));
// TODO: should we cache and re-use this thread? // TODO: should we cache and re-use this thread?
if ( !pAsyncDescriptor ) if ( !pAsyncDescriptor )
...@@ -1643,7 +1637,7 @@ void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter ) ...@@ -1643,7 +1637,7 @@ void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter )
// do the filtering // do the filtering
::std::vector< SortingData_Impl* >::iterator aContentLoop = maContent.begin(); auto aContentLoop = maContent.begin();
OUString sCompareString; OUString sCompareString;
do do
{ {
...@@ -1667,7 +1661,6 @@ void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter ) ...@@ -1667,7 +1661,6 @@ void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter )
if( bDelete ) if( bDelete )
{ {
// none of the filters did match // none of the filters did match
delete *aContentLoop;
aContentLoop = maContent.erase(aContentLoop); aContentLoop = maContent.erase(aContentLoop);
} }
else else
...@@ -1936,7 +1929,7 @@ static const CollatorWrapper* pCollatorWrapper = nullptr; ...@@ -1936,7 +1929,7 @@ static const CollatorWrapper* pCollatorWrapper = nullptr;
/* this function returns true, if aOne is less then aTwo /* this function returns true, if aOne is less then aTwo
*/ */
bool CompareSortingData_Impl( SortingData_Impl* const aOne, SortingData_Impl const * aTwo ) bool CompareSortingData_Impl( std::unique_ptr<SortingData_Impl> const & aOne, std::unique_ptr<SortingData_Impl> const & aTwo )
{ {
DBG_ASSERT( pCollatorWrapper, "*CompareSortingData_Impl(): Can't work this way!" ); DBG_ASSERT( pCollatorWrapper, "*CompareSortingData_Impl(): Can't work this way!" );
...@@ -2032,7 +2025,7 @@ void SvtFileView_Impl::EntryRemoved( const OUString& rURL ) ...@@ -2032,7 +2025,7 @@ void SvtFileView_Impl::EntryRemoved( const OUString& rURL )
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
maContent.erase(std::find_if(maContent.begin(), maContent.end(), maContent.erase(std::find_if(maContent.begin(), maContent.end(),
[&](const SortingData_Impl* data) { return data->maTargetURL == rURL; })); [&](const std::unique_ptr<SortingData_Impl> & data) { return data->maTargetURL == rURL; }));
} }
...@@ -2042,7 +2035,7 @@ void SvtFileView_Impl::EntryRenamed( OUString& rURL, ...@@ -2042,7 +2035,7 @@ void SvtFileView_Impl::EntryRenamed( OUString& rURL,
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
auto aFoundElem = std::find_if(maContent.begin(), maContent.end(), auto aFoundElem = std::find_if(maContent.begin(), maContent.end(),
[&](const SortingData_Impl* data) { return data->maTargetURL == rURL; }); [&](const std::unique_ptr<SortingData_Impl> & data) { return data->maTargetURL == rURL; });
if (aFoundElem != maContent.end()) if (aFoundElem != maContent.end())
{ {
(*aFoundElem)->SetNewTitle( rTitle ); (*aFoundElem)->SetNewTitle( rTitle );
...@@ -2066,7 +2059,7 @@ OUString SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString& ...@@ -2066,7 +2059,7 @@ OUString SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString&
{ {
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
SortingData_Impl* pData = new SortingData_Impl; std::unique_ptr<SortingData_Impl> pData(new SortingData_Impl);
pData->SetNewTitle( rTitle ); pData->SetNewTitle( rTitle );
pData->maSize = 0; pData->maSize = 0;
...@@ -2095,7 +2088,7 @@ OUString SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString& ...@@ -2095,7 +2088,7 @@ OUString SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString&
+ rLocaleData.getTime( pData->maModDate ); + rLocaleData.getTime( pData->maModDate );
pData->maDisplayText = aValue; pData->maDisplayText = aValue;
maContent.push_back( pData ); maContent.push_back( std::move(pData) );
return aValue; return aValue;
} }
...@@ -2106,7 +2099,7 @@ sal_uLong SvtFileView_Impl::GetEntryPos( const OUString& rURL ) ...@@ -2106,7 +2099,7 @@ sal_uLong SvtFileView_Impl::GetEntryPos( const OUString& rURL )
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
auto aFoundElem = std::find_if(maContent.begin(), maContent.end(), auto aFoundElem = std::find_if(maContent.begin(), maContent.end(),
[&](const SortingData_Impl* data) { return data->maTargetURL == rURL; }); [&](const std::unique_ptr<SortingData_Impl> & data) { return data->maTargetURL == rURL; });
return aFoundElem != maContent.end()?std::distance(maContent.begin(), aFoundElem):0; return aFoundElem != maContent.end()?std::distance(maContent.begin(), aFoundElem):0;
} }
...@@ -2146,7 +2139,7 @@ bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTit ...@@ -2146,7 +2139,7 @@ bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTit
sal_uInt32 nStart = nIndex; sal_uInt32 nStart = nIndex;
while ( nIndex < nEnd ) while ( nIndex < nEnd )
{ {
SortingData_Impl* pData = maContent[ nIndex ]; SortingData_Impl* pData = maContent[ nIndex ].get();
if ( pData->GetLowerTitle().startsWith( rTitle ) ) if ( pData->GetLowerTitle().startsWith( rTitle ) )
return true; return true;
++nIndex; ++nIndex;
...@@ -2157,7 +2150,7 @@ bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTit ...@@ -2157,7 +2150,7 @@ bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTit
nIndex = 0; nIndex = 0;
while ( nIndex < nEnd && nIndex <= nStart ) while ( nIndex < nEnd && nIndex <= nStart )
{ {
SortingData_Impl* pData = maContent[ nIndex ]; SortingData_Impl* pData = maContent[ nIndex ].get();
if ( pData->GetLowerTitle().startsWith( rTitle ) ) if ( pData->GetLowerTitle().startsWith( rTitle ) )
return true; return true;
++nIndex; ++nIndex;
...@@ -2175,7 +2168,7 @@ void SvtFileView_Impl::SetActualFolder( const INetURLObject& rActualFolder ) ...@@ -2175,7 +2168,7 @@ void SvtFileView_Impl::SetActualFolder( const INetURLObject& rActualFolder )
if( mpNameTrans ) if( mpNameTrans )
mpNameTrans->SetActualFolder( rActualFolder ); mpNameTrans->SetActualFolder( rActualFolder );
else else
mpNameTrans = new NameTranslator_Impl( rActualFolder ); mpNameTrans.reset(new NameTranslator_Impl( rActualFolder ));
} }
} }
......
...@@ -53,7 +53,7 @@ void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry ) ...@@ -53,7 +53,7 @@ void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry )
GetModel()->Remove(pChild); GetModel()->Remove(pChild);
} }
::std::vector< SortingData_Impl* > aContent; ::std::vector< std::unique_ptr<SortingData_Impl> > aContent;
::rtl::Reference< ::svt::FileViewContentEnumerator > ::rtl::Reference< ::svt::FileViewContentEnumerator >
xContentEnumerator(new FileViewContentEnumerator( xContentEnumerator(new FileViewContentEnumerator(
...@@ -66,7 +66,7 @@ void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry ) ...@@ -66,7 +66,7 @@ void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry )
if ( EnumerationResult::SUCCESS == eResult ) if ( EnumerationResult::SUCCESS == eResult )
{ {
for(SortingData_Impl* i : aContent) for(auto & i : aContent)
{ {
if( i->mbIsFolder ) if( i->mbIsFolder )
{ {
......
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