diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2017-12-30 16:03:22 +0100 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2018-01-11 09:42:40 +0100 |
commit | 5cebf6fa1ca6d2d4b5daacf412ccccc3bf12f193 (patch) | |
tree | f31732c10613c8a72df03f4aecb2a6400e1584fc /svtools | |
parent | 62c8ed2520c2daa94d3d47b275db636cddfbf048 (diff) |
Modernize a bit svtools
by using for-range loops and std::find_if
Change-Id: I57f26828ed66cbdfc41857d9105b6694a02a4cf8
Reviewed-on: https://gerrit.libreoffice.org/47198
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/contnr/foldertree.cxx | 7 | ||||
-rw-r--r-- | svtools/source/contnr/treelist.cxx | 32 | ||||
-rw-r--r-- | svtools/source/contnr/treelistbox.cxx | 20 | ||||
-rw-r--r-- | svtools/source/misc/transfer.cxx | 82 | ||||
-rw-r--r-- | svtools/source/misc/transfer2.cxx | 15 | ||||
-rw-r--r-- | svtools/source/uno/framestatuslistener.cxx | 26 |
6 files changed, 60 insertions, 122 deletions
diff --git a/svtools/source/contnr/foldertree.cxx b/svtools/source/contnr/foldertree.cxx index cc62de2a363a..d14906a657a6 100644 --- a/svtools/source/contnr/foldertree.cxx +++ b/svtools/source/contnr/foldertree.cxx @@ -100,11 +100,10 @@ void FolderTree::FillTreeEntry( const OUString & rUrl, const ::std::vector< std: GetModel()->Remove(pChild); } - - for(::std::vector< std::pair< OUString, OUString > >::const_iterator it = rFolders.begin(); it != rFolders.end() ; ++it) + for (auto const& folder : rFolders) { - SvTreeListEntry* pNewEntry = InsertEntry( it->first, pParent, true ); - OUString* sData = new OUString( it->second ); + SvTreeListEntry* pNewEntry = InsertEntry( folder.first, pParent, true ); + OUString* sData = new OUString( folder.second ); pNewEntry->SetUserData( static_cast< void* >( sData ) ); } diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index e4b501fa0c4d..ff6e9b8adf6a 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -78,36 +78,29 @@ void SvTreeList::Broadcast( SvTreeListEntry* pEntry2, sal_uLong nPos ) { - sal_uLong nViewCount = aViewList.size(); - for( sal_uLong nCurView = 0; nCurView < nViewCount; nCurView++ ) + for (auto const& view : aViewList) { - SvListView* pView = aViewList[ nCurView ]; - if( pView ) - pView->ModelNotification( nActionId, pEntry1, pEntry2, nPos ); + if(view) + view->ModelNotification(nActionId, pEntry1, pEntry2, nPos); } } void SvTreeList::InsertView( SvListView* pView ) { - for (SvListView* i : aViewList) { - if ( i == pView ) { - return; - } - } + if (std::find(aViewList.begin(), aViewList.end(), pView) != aViewList.end()) + return; + aViewList.push_back( pView ); nRefCount++; } void SvTreeList::RemoveView( SvListView const * pView ) { - for ( ListViewsType::iterator it = aViewList.begin(); it != aViewList.end(); ++it ) + auto viewFound = std::find(aViewList.begin(), aViewList.end(), pView); + if (viewFound != aViewList.end()) { - if ( *it == pView ) - { - aViewList.erase( it ); - --nRefCount; - break; - } + aViewList.erase( viewFound ); + --nRefCount; } } @@ -407,10 +400,9 @@ void SvTreeList::CloneChildren( SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const { SvTreeListEntries aClone; - SvTreeListEntries::iterator it = rSrc.begin(), itEnd = rSrc.end(); - for (; it != itEnd; ++it) + for (auto const& elem : rSrc) { - SvTreeListEntry& rEntry = **it; + SvTreeListEntry& rEntry = *elem; std::unique_ptr<SvTreeListEntry> pNewEntry(CloneEntry(&rEntry)); ++rCloneCount; pNewEntry->pParent = &rNewParent; diff --git a/svtools/source/contnr/treelistbox.cxx b/svtools/source/contnr/treelistbox.cxx index 563679879cbb..02e5d0416c91 100644 --- a/svtools/source/contnr/treelistbox.cxx +++ b/svtools/source/contnr/treelistbox.cxx @@ -562,10 +562,9 @@ bool SvTreeListBox::CopySelection( SvTreeListBox* pSource, SvTreeListEntry* pTar pSourceEntry = pSource->NextSelected( pSourceEntry ); } - std::vector<SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end(); - for (; it != itEnd; ++it) + for (auto const& elem : aList) { - pSourceEntry = *it; + pSourceEntry = elem; SvTreeListEntry* pNewParent = nullptr; sal_uLong nInsertionPos = TREELIST_APPEND; TriState nOk = NotifyCopying(pTarget,pSourceEntry,pNewParent,nInsertionPos); @@ -613,11 +612,9 @@ bool SvTreeListBox::MoveSelectionCopyFallbackPossible( SvTreeListBox* pSource, S pSourceEntry = pSource->NextSelected( pSourceEntry ); } - std::vector<SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end(); - for (; it != itEnd; ++it) + for (auto const& elem : aList) { - pSourceEntry = *it; - + pSourceEntry = elem; SvTreeListEntry* pNewParent = nullptr; sal_uLong nInsertionPos = TREELIST_APPEND; TriState nOk = NotifyMoving(pTarget,pSourceEntry,pNewParent,nInsertionPos); @@ -669,9 +666,8 @@ void SvTreeListBox::RemoveSelection() pEntry = NextSelected( pEntry ); } - std::vector<const SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end(); - for (; it != itEnd; ++it) - pModel->Remove(*it); + for (auto const& elem : aList) + pModel->Remove(elem); } void SvTreeListBox::RemoveEntry(SvTreeListEntry const * pEntry) @@ -730,9 +726,9 @@ SvTreeListEntry* SvTreeListBox::GetEntryFromPath( const ::std::deque< sal_Int32 SvTreeListEntry* pEntry = nullptr; SvTreeListEntry* pParent = nullptr; - for( ::std::deque< sal_Int32 >::const_iterator pItem = _rPath.begin(); pItem != _rPath.end(); ++pItem ) + for (auto const& elem : _rPath) { - pEntry = GetEntry( pParent, *pItem ); + pEntry = GetEntry( pParent, elem ); if ( !pEntry ) break; pParent = pEntry; diff --git a/svtools/source/misc/transfer.cxx b/svtools/source/misc/transfer.cxx index 15510d87bc58..17624b8917e5 100644 --- a/svtools/source/misc/transfer.cxx +++ b/svtools/source/misc/transfer.cxx @@ -408,7 +408,6 @@ Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) { const SolarMutexGuard aGuard; - bool bRet = false; try { @@ -419,16 +418,15 @@ sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& r { } - for (DataFlavorExVector::const_iterator aIter(maFormats.begin() ), aEnd(maFormats.end()); aIter != aEnd ; ++aIter) + for (auto const& format : maFormats) { - if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) + if( TransferableDataHelper::IsEqual( format, rFlavor ) ) { - bRet = true; - break; + return true; } } - return bRet; + return false; } @@ -543,18 +541,18 @@ void TransferableHelper::AddFormat( const DataFlavor& rFlavor ) { bool bAdd = true; - for (DataFlavorExVector::iterator aIter(maFormats.begin()), aEnd(maFormats.end()); aIter != aEnd ; ++aIter) + for (auto & format : maFormats) { - if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) + if( TransferableDataHelper::IsEqual( format, rFlavor ) ) { // update MimeType for SotClipboardFormatId::OBJECTDESCRIPTOR in every case - if ((SotClipboardFormatId::OBJECTDESCRIPTOR == aIter->mnSotId) && mxObjDesc) + if ((SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId) && mxObjDesc) { DataFlavor aObjDescFlavor; SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDescFlavor ); - aIter->MimeType = aObjDescFlavor.MimeType; - aIter->MimeType += ::ImplGetParameterString(*mxObjDesc); + format.MimeType = aObjDescFlavor.MimeType; + format.MimeType += ::ImplGetParameterString(*mxObjDesc); } bAdd = false; @@ -615,18 +613,8 @@ void TransferableHelper::RemoveFormat( const DataFlavor& rFlavor ) bool TransferableHelper::HasFormat( SotClipboardFormatId nFormat ) { - bool bRet = false; - - for (DataFlavorExVector::const_iterator aIter(maFormats.begin()), aEnd(maFormats.end()); aIter != aEnd; ++aIter) - { - if( nFormat == (*aIter).mnSotId ) - { - bRet = true; - break; - } - } - - return bRet; + return (std::find_if(maFormats.begin(), maFormats.end(), + [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }) != maFormats.end()); } @@ -1216,9 +1204,8 @@ void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor const OUString aCharsetStr( "charset" ); - for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ ) + for (auto const& rFlavor : rDataFlavorSeq) { - const DataFlavor& rFlavor = rDataFlavorSeq[ i ]; Reference< XMimeContentType > xMimeType; try @@ -1314,11 +1301,11 @@ void TransferableDataHelper::InitFormats() TransferableDataHelper::FillDataFlavorExVector(mxTransfer->getTransferDataFlavors(), maFormats); - for (DataFlavorExVector::const_iterator aIter(maFormats.begin()), aEnd(maFormats.end()); aIter != aEnd; ++aIter) + for (auto const& format : maFormats) { - if( SotClipboardFormatId::OBJECTDESCRIPTOR == aIter->mnSotId ) + if( SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId ) { - ImplSetParameterString(*mxObjDesc, *aIter); + ImplSetParameterString(*mxObjDesc, format); break; } } @@ -1328,39 +1315,20 @@ void TransferableDataHelper::InitFormats() bool TransferableDataHelper::HasFormat( SotClipboardFormatId nFormat ) const { ::osl::MutexGuard aGuard(mxImpl->maMutex); - - DataFlavorExVector::const_iterator aIter(maFormats.cbegin()), aEnd(maFormats.cend()); - bool bRet = false; - - while( aIter != aEnd ) - { - if( nFormat == (*aIter++).mnSotId ) - { - aIter = aEnd; - bRet = true; - } - } - - return bRet; + return (std::find_if(maFormats.begin(), maFormats.end(), + [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }) != maFormats.end()); } bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const { ::osl::MutexGuard aGuard(mxImpl->maMutex); - - DataFlavorExVector::const_iterator aIter(maFormats.cbegin()), aEnd(maFormats.cend()); - bool bRet = false; - - while( aIter != aEnd ) + for (auto const& format : maFormats) { - if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) ) - { - aIter = aEnd; - bRet = true; - } + if( TransferableDataHelper::IsEqual( rFlavor, format ) ) + return true; } - return bRet; + return false; } sal_uInt32 TransferableDataHelper::GetFormatCount() const @@ -1441,14 +1409,14 @@ Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor, const OUString& r if( nRequestFormat != SotClipboardFormatId::NONE ) { // try to get alien format first - for (DataFlavorExVector::const_iterator aIter(maFormats.begin()), aEnd(maFormats.end()); aIter != aEnd; ++aIter) + for (auto const& format : maFormats) { - if( ( nRequestFormat == (*aIter).mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( (*aIter).MimeType ) ) + if( ( nRequestFormat == format.mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( format.MimeType ) ) { if (xTransfer2.is()) - aRet = xTransfer2->getTransferData2(*aIter, rDestDoc); + aRet = xTransfer2->getTransferData2(format, rDestDoc); else - aRet = mxTransfer->getTransferData(*aIter); + aRet = mxTransfer->getTransferData(format); } if( aRet.hasValue() ) diff --git a/svtools/source/misc/transfer2.cxx b/svtools/source/misc/transfer2.cxx index 5fdb1a226e10..680cb5fa60c9 100644 --- a/svtools/source/misc/transfer2.cxx +++ b/svtools/source/misc/transfer2.cxx @@ -298,19 +298,8 @@ sal_Int8 DropTargetHelper::ExecuteDrop( const ExecuteDropEvent& ) bool DropTargetHelper::IsDropFormatSupported( SotClipboardFormatId nFormat ) { - DataFlavorExVector::iterator aIter( maFormats.begin() ), aEnd( maFormats.end() ); - bool bRet = false; - - while( aIter != aEnd ) - { - if( nFormat == (*aIter++).mnSotId ) - { - bRet = true; - aIter = aEnd; - } - } - - return bRet; + return (std::find_if(maFormats.begin(), maFormats.end(), + [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }) != maFormats.end()); } diff --git a/svtools/source/uno/framestatuslistener.cxx b/svtools/source/uno/framestatuslistener.cxx index 0de8644bbc5c..ceaf3ae4a22c 100644 --- a/svtools/source/uno/framestatuslistener.cxx +++ b/svtools/source/uno/framestatuslistener.cxx @@ -87,15 +87,14 @@ void SAL_CALL FrameStatusListener::dispose() throw DisposedException(); Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); - URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); - while ( pIter != m_aListenerMap.end() ) + for (auto const& listener : m_aListenerMap) { try { - Reference< XDispatch > xDispatch( pIter->second ); + Reference< XDispatch > xDispatch( listener.second ); Reference< XURLTransformer > xURLTransformer( css::util::URLTransformer::create( m_xContext ) ); css::util::URL aTargetURL; - aTargetURL.Complete = pIter->first; + aTargetURL.Complete = listener.first; xURLTransformer->parseStrict( aTargetURL ); if ( xDispatch.is() && xStatusListener.is() ) @@ -104,8 +103,6 @@ void SAL_CALL FrameStatusListener::dispose() catch (const Exception&) { } - - ++pIter; } m_bDisposed = true; @@ -128,13 +125,12 @@ void SAL_CALL FrameStatusListener::disposing( const EventObject& Source ) SolarMutexGuard aSolarMutexGuard; - URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); - while ( pIter != m_aListenerMap.end() ) + for (auto & listener : m_aListenerMap) { // Compare references and release dispatch references if they are equal. - Reference< XInterface > xIfac( pIter->second, UNO_QUERY ); + Reference< XInterface > xIfac( listener.second, UNO_QUERY ); if ( xSource == xIfac ) - pIter->second.clear(); + listener.second.clear(); } Reference< XInterface > xIfac( m_xFrame, UNO_QUERY ); @@ -216,15 +212,14 @@ void FrameStatusListener::bindListener() if ( m_xContext.is() && xDispatchProvider.is() ) { xStatusListener.set( static_cast< OWeakObject* >( this ), UNO_QUERY ); - URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); - while ( pIter != m_aListenerMap.end() ) + for (auto & listener : m_aListenerMap) { Reference< XURLTransformer > xURLTransformer( css::util::URLTransformer::create( m_xContext ) ); css::util::URL aTargetURL; - aTargetURL.Complete = pIter->first; + aTargetURL.Complete = listener.first; xURLTransformer->parseStrict( aTargetURL ); - Reference< XDispatch > xDispatch( pIter->second ); + Reference< XDispatch > xDispatch( listener.second ); if ( xDispatch.is() ) { // We already have a dispatch object => we have to requery. @@ -246,11 +241,10 @@ void FrameStatusListener::bindListener() catch (const Exception&) { } - pIter->second = xDispatch; + listener.second = xDispatch; Listener aListener( aTargetURL, xDispatch ); aDispatchVector.push_back( aListener ); - ++pIter; } } } |