From 2e0cf814671e99a1d1a902a5828768c620c4674c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 12 Apr 2018 15:39:25 +0200 Subject: loplugin:useuniqueptr in ProgressMonitor Change-Id: Ic66e49037c04501a2c39a69f3f8a2a03cb10b5fc Reviewed-on: https://gerrit.libreoffice.org/52884 Tested-by: Jenkins Reviewed-by: Noel Grandin --- UnoControls/source/controls/progressmonitor.cxx | 38 ++++++++++--------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'UnoControls/source/controls') diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx index 4d513ee26b2f..b43afd5d6e73 100644 --- a/UnoControls/source/controls/progressmonitor.cxx +++ b/UnoControls/source/controls/progressmonitor.cxx @@ -197,7 +197,7 @@ void SAL_CALL ProgressMonitor::addText( } // Else ... take memory for new item ... - IMPL_TextlistItem* pTextItem = new IMPL_TextlistItem; + std::unique_ptr pTextItem(new IMPL_TextlistItem); // Set values ... pTextItem->sTopic = rTopic; @@ -209,11 +209,11 @@ void SAL_CALL ProgressMonitor::addText( // ... and insert it in right list. if ( bbeforeProgress ) { - maTextlist_Top.push_back( pTextItem ); + maTextlist_Top.push_back( std::move(pTextItem) ); } else { - maTextlist_Bottom.push_back( pTextItem ); + maTextlist_Bottom.push_back( std::move(pTextItem) ); } // ... update window @@ -239,15 +239,17 @@ void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbe // ... delete item from right list ... if ( bbeforeProgress ) { - vector< IMPL_TextlistItem* >::iterator - itr = find( maTextlist_Top.begin(), maTextlist_Top.end(), pSearchItem ); + auto itr = std::find_if( maTextlist_Top.begin(), maTextlist_Top.end(), + [&] (std::unique_ptr const &p) + { return p.get() == pSearchItem; } ); if (itr != maTextlist_Top.end()) maTextlist_Top.erase(itr); } else { - vector< IMPL_TextlistItem* >::iterator - itr = find( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), pSearchItem ); + auto itr = std::find_if( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), + [&] (std::unique_ptr const &p) + { return p.get() == pSearchItem; } ); if (itr != maTextlist_Bottom.end()) maTextlist_Bottom.erase(itr); } @@ -723,7 +725,7 @@ void ProgressMonitor::impl_rebuildFixedText () // Collect all topics from list and format text. // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! - for (IMPL_TextlistItem* pSearchItem : maTextlist_Top) + for (auto const & pSearchItem : maTextlist_Top) { aCollectString += pSearchItem->sTopic + "\n"; } @@ -738,7 +740,7 @@ void ProgressMonitor::impl_rebuildFixedText () // Collect all topics from list and format text. // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! - for (IMPL_TextlistItem* pSearchItem : maTextlist_Top) + for (auto const & pSearchItem : maTextlist_Top) { aCollectString += pSearchItem->sText + "\n"; } @@ -755,7 +757,7 @@ void ProgressMonitor::impl_rebuildFixedText () // Collect all topics from list and format text. // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! - for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom) + for (auto const & pSearchItem : maTextlist_Bottom) { aCollectString += pSearchItem->sTopic + "\n"; } @@ -770,7 +772,7 @@ void ProgressMonitor::impl_rebuildFixedText () // Collect all topics from list and format text. // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! - for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom) + for (auto const & pSearchItem : maTextlist_Bottom) { aCollectString += pSearchItem->sText + "\n"; } @@ -786,17 +788,7 @@ void ProgressMonitor::impl_cleanMemory () MutexGuard aGuard ( m_aMutex ); // Delete all of lists. - - for (IMPL_TextlistItem* pSearchItem : maTextlist_Top) - { - delete pSearchItem; - } maTextlist_Top.clear(); - - for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom) - { - delete pSearchItem; - } maTextlist_Bottom.clear(); } @@ -804,7 +796,7 @@ void ProgressMonitor::impl_cleanMemory () IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, bool bbeforeProgress ) { // Get right textlist for following operations. - ::std::vector< IMPL_TextlistItem* >* pTextList; + ::std::vector< std::unique_ptr >* pTextList; // Ready for multithreading ClearableMutexGuard aGuard ( m_aMutex ); @@ -827,7 +819,7 @@ IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, b for ( nPosition = 0; nPosition < nCount; ++nPosition ) { - IMPL_TextlistItem* pSearchItem = pTextList->at( nPosition ); + auto pSearchItem = pTextList->at( nPosition ).get(); if ( pSearchItem->sTopic == rTopic ) { -- cgit