Kaydet (Commit) e06afb0c authored tarafından Arkadiy Illarionov's avatar Arkadiy Illarionov Kaydeden (comit) Noel Grandin

Simplify containers iterations in ucb, ucbhelper

Use range-based loop or replace with STL functions.

Change-Id: I3cdb0f89523008199af1550de164a52b75c52ba5
Reviewed-on: https://gerrit.libreoffice.org/62088
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 8959bb30
......@@ -464,16 +464,10 @@ void SAL_CALL UniversalContentBroker::deregisterContentProvider(
{
ProviderList_Impl & rList = aMapIt->getValue();
ProviderList_Impl::iterator aListEnd(rList.end());
for (ProviderList_Impl::iterator aListIt(rList.begin());
aListIt != aListEnd; ++aListIt)
{
if ((*aListIt).getProvider() == Provider)
{
rList.erase(aListIt);
break;
}
}
auto aListIt = std::find_if(rList.begin(), rList.end(),
[&Provider](const ProviderListEntry_Impl& rEntry) { return rEntry.getProvider() == Provider; });
if (aListIt != rList.end())
rList.erase(aListIt);
if (rList.empty())
m_aProviders.erase(aMapIt);
......@@ -810,20 +804,18 @@ void UniversalContentBroker::configureUcb()
void UniversalContentBroker::prepareAndRegister(
const ContentProviderDataList& rData)
{
ContentProviderDataList::const_iterator aEnd(rData.end());
for (ContentProviderDataList::const_iterator aIt(rData.begin());
aIt != aEnd; ++aIt)
for (const auto& rContentProviderData : rData)
{
OUString aProviderArguments;
if (fillPlaceholders(aIt->Arguments,
if (fillPlaceholders(rContentProviderData.Arguments,
m_aArguments,
&aProviderArguments))
{
registerAtUcb(this,
m_xContext,
aIt->ServiceName,
rContentProviderData.ServiceName,
aProviderArguments,
aIt->URLTemplate);
rContentProviderData.URLTemplate);
}
else
......
......@@ -38,16 +38,15 @@ namespace cmis
std::vector< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( );
// Loop over the results and filter them
for ( std::vector< uno::Reference< ucb::XContent > >::iterator it = aChildren.begin();
it != aChildren.end(); ++it )
for ( const auto& rChild : aChildren )
{
OUString sContentType = ( *it )->getContentType( );
OUString sContentType = rChild->getContentType( );
bool bIsFolder = sContentType != CMIS_FILE_TYPE;
if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) ||
( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) ||
( mnOpenMode == ucb::OpenMode::ALL ) )
{
maResults.emplace_back( *it );
maResults.emplace_back( rChild );
}
}
mbCountFinal = true;
......
......@@ -243,12 +243,10 @@ namespace cmis
if ( !m_sRepositoryId.isEmpty() )
{
for ( std::vector< libcmis::RepositoryPtr >::iterator it = m_aRepositories.begin( );
it != m_aRepositories.end( ) && nullptr == repo.get( ); ++it )
{
if ( STD_TO_OUSTR( ( *it )->getId( ) ) == m_sRepositoryId )
repo = *it;
}
auto it = std::find_if(m_aRepositories.begin(), m_aRepositories.end(),
[&](const libcmis::RepositoryPtr& rRepo) { return STD_TO_OUSTR(rRepo->getId()) == m_sRepositoryId; });
if (it != m_aRepositories.end())
repo = *it;
}
else
repo = m_aRepositories.front( );
......@@ -405,11 +403,10 @@ namespace cmis
if ( m_sRepositoryId.isEmpty( ) )
{
for ( std::vector< libcmis::RepositoryPtr >::iterator it = m_aRepositories.begin( );
it != m_aRepositories.end(); ++it )
for ( const auto& rRepo : m_aRepositories )
{
URL aUrl( m_aURL );
aUrl.setObjectPath( STD_TO_OUSTR( ( *it )->getId( ) ) );
aUrl.setObjectPath( STD_TO_OUSTR( rRepo->getId( ) ) );
uno::Reference< ucb::XContentIdentifier > xId = new ucbhelper::ContentIdentifier( aUrl.asString( ) );
uno::Reference< ucb::XContent > xContent = new RepoContent( m_xContext, m_pProvider, xId, m_aRepositories );
......
......@@ -45,18 +45,16 @@ XPropertySetInfo_impl::XPropertySetInfo_impl( TaskManager* pMyShell,const OUStri
TaskManager::ContentMap::iterator it = m_pMyShell->m_aContent.find( aUnqPath );
TaskManager::PropertySet& properties = *(it->second.properties);
TaskManager::PropertySet::iterator it1 = properties.begin();
m_seq.realloc( properties.size() );
sal_Int32 count = 0;
while( it1 != properties.end() )
for( const auto& rProp : properties )
{
m_seq[ count++ ] = beans::Property( it1->getPropertyName(),
it1->getHandle(),
it1->getType(),
it1->getAttributes() );
++it1;
m_seq[ count++ ] = beans::Property( rProp.getPropertyName(),
rProp.getHandle(),
rProp.getType(),
rProp.getAttributes() );
}
}
......
......@@ -512,11 +512,10 @@ TaskManager::registerNotifier( const OUString& aUnqPath, Notifier* pNotifier )
std::vector< Notifier* >& nlist = *( it->second.notifier );
std::vector<Notifier*>::iterator it1 = nlist.begin();
while( it1 != nlist.end() ) // Every "Notifier" only once
std::vector<Notifier*>::iterator it1 = std::find(nlist.begin(), nlist.end(), pNotifier);
if( it1 != nlist.end() ) // Every "Notifier" only once
{
if( *it1 == pNotifier ) return;
++it1;
return;
}
nlist.push_back( pNotifier );
}
......@@ -2761,11 +2760,9 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix,
// However, these may be in status BaseContent::Deleted
if( copyList != nullptr )
{
std::vector< Notifier* >::iterator copyIt = copyList->begin();
while( copyIt != copyList->end() )
for( const auto& rCopyPtr : *copyList )
{
itnew->second.notifier->push_back( *copyIt );
++copyIt;
itnew->second.notifier->push_back( rCopyPtr );
}
}
}
......
......@@ -571,12 +571,9 @@ void Content::queryChildren( ContentRefList& rChildren )
sal_Int32 nLen = aURL.getLength();
ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
while ( it != end )
for ( const auto& rContent : aAllContents )
{
ucbhelper::ContentImplHelperRef xChild = (*it);
ucbhelper::ContentImplHelperRef xChild = rContent;
OUString aChildURL = xChild->getIdentifier()->getContentIdentifier();
// Is aURL a prefix of aChildURL?
......@@ -591,7 +588,6 @@ void Content::queryChildren( ContentRefList& rChildren )
rChildren.emplace_back(static_cast< ::gio::Content * >(xChild.get() ) );
}
}
++it;
}
}
......@@ -617,12 +613,9 @@ bool Content::exchangeIdentity( const uno::Reference< ucb::XContentIdentifier >&
ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( const auto& rChild : aChildren )
{
ContentRef xChild = (*it);
ContentRef xChild = rChild;
// Create new content identifier for the child...
uno::Reference< ucb::XContentIdentifier > xOldChildId = xChild->getIdentifier();
......@@ -635,10 +628,8 @@ bool Content::exchangeIdentity( const uno::Reference< ucb::XContentIdentifier >&
if ( !xChild->exchangeIdentity( xNewChildId ) )
return false;
++it;
}
return true;
}
return true;
}
return false;
......@@ -1011,13 +1002,9 @@ void Content::destroy( bool bDeletePhysical )
::gio::Content::ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( auto& rChild : aChildren )
{
(*it)->destroy( bDeletePhysical );
++it;
rChild->destroy( bDeletePhysical );
}
}
......
......@@ -741,12 +741,9 @@ void HierarchyContent::queryChildren( HierarchyContentRefVector& rChildren )
sal_Int32 nLen = aURL.getLength();
::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
while ( it != end )
for ( const auto& rContent : aAllContents )
{
::ucbhelper::ContentImplHelperRef xChild = (*it);
::ucbhelper::ContentImplHelperRef xChild = rContent;
OUString aChildURL
= xChild->getIdentifier()->getContentIdentifier();
......@@ -765,7 +762,6 @@ void HierarchyContent::queryChildren( HierarchyContentRefVector& rChildren )
static_cast< HierarchyContent * >( xChild.get() ) );
}
}
++it;
}
}
......@@ -812,11 +808,9 @@ bool HierarchyContent::exchangeIdentity(
HierarchyContentRefVector aChildren;
queryChildren( aChildren );
HierarchyContentRefVector::const_iterator it = aChildren.begin();
while ( it != aChildren.end() )
for ( const auto& rChild : aChildren )
{
HierarchyContentRef xChild = (*it);
HierarchyContentRef xChild = rChild;
// Create new content identifier for the child...
uno::Reference< ucb::XContentIdentifier > xOldChildId
......@@ -833,8 +827,6 @@ bool HierarchyContent::exchangeIdentity(
if ( !xChild->exchangeIdentity( xNewChildId ) )
return false;
++it;
}
}
return true;
......
......@@ -1677,13 +1677,9 @@ void Content::destroy(
ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( auto& rChild : aChildren )
{
(*it)->destroy( bDeletePhysical, xEnv );
++it;
rChild->destroy( bDeletePhysical, xEnv );
}
}
}
......@@ -2003,12 +1999,9 @@ bool Content::exchangeIdentity(
ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( const auto& rChild : aChildren )
{
ContentRef xChild = (*it);
ContentRef xChild = rChild;
// Create new content identifier for the child...
uno::Reference< ucb::XContentIdentifier > xOldChildId
......@@ -2025,8 +2018,6 @@ bool Content::exchangeIdentity(
if ( !xChild->exchangeIdentity( xNewChildId ) )
return false;
++it;
}
}
return true;
......@@ -2056,12 +2047,9 @@ void Content::queryChildren( ContentRefList& rChildren )
sal_Int32 nLen = aURL.getLength();
::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
while ( it != end )
for ( const auto& rContent : aAllContents )
{
::ucbhelper::ContentImplHelperRef xChild = (*it);
::ucbhelper::ContentImplHelperRef xChild = rContent;
OUString aChildURL
= xChild->getIdentifier()->getContentIdentifier();
......@@ -2076,7 +2064,6 @@ void Content::queryChildren( ContentRefList& rChildren )
static_cast< Content * >( xChild.get() ) );
}
}
++it;
}
}
......
......@@ -724,12 +724,9 @@ void Content::queryChildren( ContentRefList& rChildren )
sal_Int32 nLen = aURL.getLength();
::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
while ( it != end )
for ( const auto& rContent : aAllContents )
{
::ucbhelper::ContentImplHelperRef xChild = (*it);
::ucbhelper::ContentImplHelperRef xChild = rContent;
OUString aChildURL
= xChild->getIdentifier()->getContentIdentifier();
......@@ -748,7 +745,6 @@ void Content::queryChildren( ContentRefList& rChildren )
static_cast< Content * >( xChild.get() ) );
}
}
++it;
}
}
......@@ -796,12 +792,9 @@ bool Content::exchangeIdentity(
ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( const auto& rChild : aChildren )
{
ContentRef xChild = (*it);
ContentRef xChild = rChild;
// Create new content identifier for the child...
uno::Reference< ucb::XContentIdentifier > xOldChildId
......@@ -818,8 +811,6 @@ bool Content::exchangeIdentity(
if ( !xChild->exchangeIdentity( xNewChildId ) )
return false;
++it;
}
}
return true;
......@@ -1701,13 +1692,9 @@ void Content::destroy( bool bDeletePhysical,
ContentRefList aChildren;
queryChildren( aChildren );
ContentRefList::const_iterator it = aChildren.begin();
ContentRefList::const_iterator end = aChildren.end();
while ( it != end )
for ( auto& rChild : aChildren )
{
(*it)->destroy( bDeletePhysical, xEnv );
++it;
rChild->destroy( bDeletePhysical, xEnv );
}
}
}
......
......@@ -181,17 +181,8 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured(
{
osl::MutexGuard aGuard( m_aMtx );
DocumentList::const_iterator it = m_aDocs.begin();
while ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
// already known.
found = true;
break;
}
++it;
}
found = std::any_of(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
}
if (!found)
......@@ -257,15 +248,13 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured(
{
osl::MutexGuard aGuard( m_aMtx );
for (auto it = m_aDocs.begin(); it != m_aDocs.end(); ++it)
auto it = std::find_if(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
if ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
aDocId = (*it).first;
found = true;
m_aDocs.erase( it );
break;
}
aDocId = (*it).first;
found = true;
m_aDocs.erase( it );
}
}
......@@ -309,19 +298,15 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured(
osl::MutexGuard aGuard( m_aMtx );
DocumentList::iterator it = m_aDocs.begin();
while ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
(*it).second.xStorage = xStorage;
break;
}
++it;
}
DocumentList::iterator it = std::find_if(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
OSL_ENSURE( it != m_aDocs.end(),
"OnSaveDone event notified for unknown document!" );
if ( it != m_aDocs.end() )
{
(*it).second.xStorage = xStorage;
}
}
}
else if ( Event.EventName == "OnSaveAsDone" )
......@@ -345,22 +330,18 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured(
osl::MutexGuard aGuard( m_aMtx );
DocumentList::iterator it = m_aDocs.begin();
while ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
(*it).second.xStorage = xStorage;
// Adjust title.
(*it).second.aTitle = title;
break;
}
++it;
}
DocumentList::iterator it = std::find_if(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
OSL_ENSURE( it != m_aDocs.end(),
"OnSaveAsDone event notified for unknown document!" );
if ( it != m_aDocs.end() )
{
(*it).second.xStorage = xStorage;
// Adjust title.
(*it).second.aTitle = title;
}
}
}
else if ( Event.EventName == "OnTitleChanged"
......@@ -387,18 +368,14 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured(
osl::MutexGuard aGuard( m_aMtx );
DocumentList::iterator it = m_aDocs.begin();
while ( it != m_aDocs.end() )
DocumentList::iterator it = std::find_if(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
if ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
// Adjust title.
(*it).second.aTitle = aTitle;
// Adjust title.
(*it).second.aTitle = aTitle;
m_aDocs[ aDocId ] = StorageInfo( aTitle, xStorage, xModel );
break;
}
++it;
m_aDocs[ aDocId ] = StorageInfo( aTitle, xStorage, xModel );
}
// OSL_ENSURE( it != m_aDocs.end(),
......@@ -450,17 +427,8 @@ void OfficeDocumentsManager::buildDocumentsList()
{
osl::MutexGuard aGuard( m_aMtx );
DocumentList::const_iterator it = m_aDocs.begin();
while ( it != m_aDocs.end() )
{
if ( (*it).second.xModel == xModel )
{
// already known.
found = true;
break;
}
++it;
}
found = std::any_of(m_aDocs.begin(), m_aDocs.end(),
[&xModel](const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
}
if (!found)
......
......@@ -231,17 +231,14 @@ void ContentProvider::notifyDocumentClosed( const OUString & rDocId )
::ucbhelper::ContentRefList aAllContents;
queryExistingContents( aAllContents );
::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
// Notify all content objects related to the closed doc.
bool bFoundDocumentContent = false;
rtl::Reference< Content > xRoot;
while ( it != end )
for ( const auto& rContent : aAllContents )
{
Uri aUri( (*it)->getIdentifier()->getContentIdentifier() );
Uri aUri( rContent->getIdentifier()->getContentIdentifier() );
OSL_ENSURE( aUri.isValid(),
"ContentProvider::notifyDocumentClosed - Invalid URI!" );
......@@ -249,7 +246,7 @@ void ContentProvider::notifyDocumentClosed( const OUString & rDocId )
{
if ( aUri.isRoot() )
{
xRoot = static_cast< Content * >( (*it).get() );
xRoot = static_cast< Content * >( rContent.get() );
}
else if ( aUri.isDocument() )
{
......@@ -268,12 +265,10 @@ void ContentProvider::notifyDocumentClosed( const OUString & rDocId )
{
// Inform content.
rtl::Reference< Content > xContent
= static_cast< Content * >( (*it).get() );
= static_cast< Content * >( rContent.get() );
xContent->notifyDocumentClosed();
}
++it;
}
if ( xRoot.is() )
......@@ -294,28 +289,23 @@ void ContentProvider::notifyDocumentOpened( const OUString & rDocId )
::ucbhelper::ContentRefList aAllContents;
queryExistingContents( aAllContents );
::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
// Find root content. If instantiated let it propagate document insertion.
while ( it != end )
for ( const auto& rContent : aAllContents )
{
Uri aUri( (*it)->getIdentifier()->getContentIdentifier() );
Uri aUri( rContent->getIdentifier()->getContentIdentifier() );
OSL_ENSURE( aUri.isValid(),
"ContentProvider::notifyDocumentOpened - Invalid URI!" );
if ( aUri.isRoot() )
{
rtl::Reference< Content > xRoot
= static_cast< Content * >( (*it).get() );
= static_cast< Content * >( rContent.get() );
xRoot->notifyChildInserted( rDocId );
// Done.
break;
}
++it;
}
}
......
......@@ -112,15 +112,9 @@ ContentProperties::ContentProperties( const DAVResource& rResource )
true );
}
std::vector< DAVPropertyValue >::const_iterator it
= rResource.properties.begin();
std::vector< DAVPropertyValue >::const_iterator end
= rResource.properties.end();
while ( it != end )
for ( const auto& rProp : rResource.properties )
{
addProperty( *it );
++it;
addProperty( rProp );
}
if ( rResource.uri.endsWith("/") )
......@@ -190,14 +184,13 @@ const PropertyValue * ContentProperties::get(
if ( it == end )
{
it = m_xProps->begin();
while ( it != end )
{
if ( (*it).first.equalsIgnoreAsciiCase( rName ) )
return &(*it).second;
it = std::find_if(m_xProps->cbegin(), end,
[&rName](const PropertyValueMap::value_type& rEntry) {
return rEntry.first.equalsIgnoreAsciiCase( rName );
});
if ( it != end )
return &(*it).second;
++it;
}
return nullptr;
}
else
......@@ -355,13 +348,8 @@ void ContentProperties::addProperties(
const std::vector< OUString > & rProps,
const ContentProperties & rContentProps )
{
std::vector< OUString >::const_iterator it = rProps.begin();
std::vector< OUString >::const_iterator end = rProps.end();
while ( it != end )
for ( const OUString & rName : rProps )
{
const OUString & rName = (*it);
if ( !contains( rName ) ) // ignore duplicates
{
const PropertyValue * pProp = rContentProps.get( rName );
......@@ -375,7 +363,6 @@ void ContentProperties::addProperties(
addProperty( rName, uno::Any(), false );
}
}
++it;
}
}
......@@ -558,17 +545,12 @@ void CachableContentProperties::addProperties(
{
const std::unique_ptr< PropertyValueMap > & props = rProps.getProperties();
PropertyValueMap::const_iterator it = props->begin();
const PropertyValueMap::const_iterator end = props->end();
while ( it != end )
for ( const auto& rProp : *props )
{
if ( isCachable( (*it).first, (*it).second.isCaseSensitive() ) )
m_aProps.addProperty( (*it).first,
(*it).second.value(),
(*it).second.isCaseSensitive() );
++it;
if ( isCachable( rProp.first, rProp.second.isCaseSensitive() ) )
m_aProps.addProperty( rProp.first,
rProp.second.value(),
rProp.second.isCaseSensitive() );
}
}
......@@ -576,15 +558,10 @@ void CachableContentProperties::addProperties(
void CachableContentProperties::addProperties(
const std::vector< DAVPropertyValue > & rProps )
{