summaryrefslogtreecommitdiff
path: root/ucb/source/ucp/cmis
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-10-20 22:15:25 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-22 09:47:59 +0200
commite06afb0c9546ddcde1cedd75f59001396ac6fdf2 (patch)
treec5e60976b74bd102bff3e58381e53bb949c6ea22 /ucb/source/ucp/cmis
parent8959bb300b05be9fafbf30e553b35fb517bdf786 (diff)
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: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'ucb/source/ucp/cmis')
-rw-r--r--ucb/source/ucp/cmis/cmis_content.cxx93
-rw-r--r--ucb/source/ucp/cmis/cmis_datasupplier.cxx7
-rw-r--r--ucb/source/ucp/cmis/cmis_repo_content.cxx15
3 files changed, 48 insertions, 67 deletions
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
index 65cb142f67bd..8a680d6193bb 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -44,6 +44,7 @@
#endif
#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <config_oauth2.h>
#include <o3tl/runtimetooustring.hxx>
@@ -106,11 +107,9 @@ namespace
uno::Sequence< OUString > aStrings( aCmisStrings.size( ) );
OUString* aStringsArr = aStrings.getArray( );
sal_Int32 i = 0;
- for ( vector< string >::iterator it = aCmisStrings.begin( );
- it != aCmisStrings.end( ); ++it, ++i )
+ for ( const auto& rCmisStr : aCmisStrings )
{
- string str = *it;
- aStringsArr[i] = STD_TO_OUSTR( str );
+ aStringsArr[i++] = STD_TO_OUSTR( rCmisStr );
}
aValue <<= aStrings;
}
@@ -121,10 +120,9 @@ namespace
uno::Sequence< sal_Int64 > aLongs( aCmisLongs.size( ) );
sal_Int64* aLongsArr = aLongs.getArray( );
sal_Int32 i = 0;
- for ( vector< long >::iterator it = aCmisLongs.begin( );
- it != aCmisLongs.end( ); ++it, ++i )
+ for ( const auto& rCmisLong : aCmisLongs )
{
- aLongsArr[i] = *it;
+ aLongsArr[i++] = rCmisLong;
}
aValue <<= aLongs;
}
@@ -132,14 +130,7 @@ namespace
case libcmis::PropertyType::Decimal:
{
vector< double > aCmisDoubles = pProperty->getDoubles( );
- uno::Sequence< double > aDoubles( aCmisDoubles.size( ) );
- double* aDoublesArr = aDoubles.getArray( );
- sal_Int32 i = 0;
- for ( vector< double >::iterator it = aCmisDoubles.begin( );
- it != aCmisDoubles.end( ); ++it, ++i )
- {
- aDoublesArr[i] = *it;
- }
+ uno::Sequence< double > aDoubles = comphelper::containerToSequence(aCmisDoubles);
aValue <<= aDoubles;
}
break;
@@ -149,10 +140,9 @@ namespace
uno::Sequence< sal_Bool > aBools( aCmisBools.size( ) );
sal_Bool* aBoolsArr = aBools.getArray( );
sal_Int32 i = 0;
- for ( vector< bool >::iterator it = aCmisBools.begin( );
- it != aCmisBools.end( ); ++it, ++i )
+ for ( const auto& rCmisBool : aCmisBools )
{
- aBoolsArr[i] = *it;
+ aBoolsArr[i++] = rCmisBool;
}
aValue <<= aBools;
}
@@ -163,10 +153,9 @@ namespace
uno::Sequence< util::DateTime > aTimes( aCmisTimes.size( ) );
util::DateTime* aTimesArr = aTimes.getArray( );
sal_Int32 i = 0;
- for ( vector< boost::posix_time::ptime >::iterator it = aCmisTimes.begin( );
- it != aCmisTimes.end( ); ++it, ++i )
+ for ( const auto& rCmisTime : aCmisTimes )
{
- aTimesArr[i] = lcl_boostToUnoTime( *it );
+ aTimesArr[i++] = lcl_boostToUnoTime( rCmisTime );
}
aValue <<= aTimes;
}
@@ -479,15 +468,17 @@ namespace cmis
if ( pProperty )
{
vector< string > typesIds = pProperty->getStrings( );
- for ( vector< string >::iterator typeIt = typesIds.begin();
- typeIt != typesIds.end() && !m_pObjectType; ++typeIt )
+ for ( const auto& rType : typesIds )
{
bTypeRestricted = true;
- libcmis::ObjectTypePtr type = getSession( xEnv )->getType( *typeIt );
+ libcmis::ObjectTypePtr type = getSession( xEnv )->getType( rType );
// FIXME Improve performances by adding getBaseTypeId( ) method to libcmis
if ( type->getBaseType( )->getId( ) == typeId )
+ {
m_pObjectType = type;
+ break;
+ }
}
}
}
@@ -550,12 +541,10 @@ namespace cmis
if (pParentFolder)
{
vector< libcmis::ObjectPtr > children = pParentFolder->getChildren();
- for (vector< libcmis::ObjectPtr >::iterator it = children.begin();
- it != children.end() && !m_pObject; ++it)
- {
- if ((*it)->getName() == sName)
- m_pObject = *it;
- }
+ auto it = std::find_if(children.begin(), children.end(),
+ [&sName](const libcmis::ObjectPtr& rChild) { return rChild->getName() == sName; });
+ if (it != children.end())
+ m_pObject = *it;
}
}
@@ -851,15 +840,14 @@ namespace cmis
uno::Sequence< document::CmisProperty > aCmisProperties( aProperties.size( ) );
document::CmisProperty* pCmisProps = aCmisProperties.getArray( );
sal_Int32 i = 0;
- for ( map< string, libcmis::PropertyPtr >::iterator it = aProperties.begin();
- it != aProperties.end( ); ++it, ++i )
+ for ( const auto& rProperty : aProperties )
{
- string sId = it->first;
- string sDisplayName = it->second->getPropertyType()->getDisplayName( );
- bool bUpdatable = it->second->getPropertyType()->isUpdatable( );
- bool bRequired = it->second->getPropertyType()->isRequired( );
- bool bMultiValued = it->second->getPropertyType()->isMultiValued();
- bool bOpenChoice = it->second->getPropertyType()->isOpenChoice();
+ string sId = rProperty.first;
+ string sDisplayName = rProperty.second->getPropertyType()->getDisplayName( );
+ bool bUpdatable = rProperty.second->getPropertyType()->isUpdatable( );
+ bool bRequired = rProperty.second->getPropertyType()->isRequired( );
+ bool bMultiValued = rProperty.second->getPropertyType()->isMultiValued();
+ bool bOpenChoice = rProperty.second->getPropertyType()->isOpenChoice();
pCmisProps[i].Id = STD_TO_OUSTR( sId );
pCmisProps[i].Name = STD_TO_OUSTR( sDisplayName );
@@ -867,8 +855,8 @@ namespace cmis
pCmisProps[i].Required = bRequired;
pCmisProps[i].MultiValued = bMultiValued;
pCmisProps[i].OpenChoice = bOpenChoice;
- pCmisProps[i].Value = lcl_cmisPropertyToUno( it->second );
- switch ( it->second->getPropertyType( )->getType( ) )
+ pCmisProps[i].Value = lcl_cmisPropertyToUno( rProperty.second );
+ switch ( rProperty.second->getPropertyType( )->getType( ) )
{
default:
case libcmis::PropertyType::String:
@@ -887,7 +875,7 @@ namespace cmis
pCmisProps[i].Type = CMIS_TYPE_DATETIME;
break;
}
-
+ ++i;
}
xRow->appendObject( rProp.Name, uno::makeAny( aCmisProperties ) );
}
@@ -1177,11 +1165,9 @@ namespace cmis
// Get the Original document (latest version)
vector< libcmis::DocumentPtr > aVersions = pPwc->getAllVersions( );
- bool bFound = false;
- for ( vector< libcmis::DocumentPtr >::iterator it = aVersions.begin();
- it != aVersions.end( ) && !bFound; ++it )
+ for ( const auto& rVersion : aVersions )
{
- libcmis::DocumentPtr pVersion = *it;
+ libcmis::DocumentPtr pVersion = rVersion;
map< string, libcmis::PropertyPtr > aProps = pVersion->getProperties( );
bool bIsLatestVersion = false;
map< string, libcmis::PropertyPtr >::iterator propIt = aProps.find( string( "cmis:isLatestVersion" ) );
@@ -1192,7 +1178,6 @@ namespace cmis
if ( bIsLatestVersion )
{
- bFound = true;
// Compute the URL of the Document
URL aCmisUrl( m_sURL );
vector< string > aPaths = pVersion->getPaths( );
@@ -1209,6 +1194,7 @@ namespace cmis
aCmisUrl.setObjectId( STD_TO_OUSTR( sId ) );
}
aRet = aCmisUrl.asString( );
+ break;
}
}
}
@@ -1241,14 +1227,14 @@ namespace cmis
vector< libcmis::DocumentPtr > aCmisVersions = pDoc->getAllVersions( );
uno::Sequence< document::CmisVersion > aVersions( aCmisVersions.size( ) );
int i = 0;
- for ( vector< libcmis::DocumentPtr >::iterator it = aCmisVersions.begin();
- it != aCmisVersions.end( ); ++it, ++i )
+ for ( const auto& rVersion : aCmisVersions )
{
- libcmis::DocumentPtr pVersion = *it;
+ libcmis::DocumentPtr pVersion = rVersion;
aVersions[i].Id = STD_TO_OUSTR( pVersion->getId( ) );
aVersions[i].Author = STD_TO_OUSTR( pVersion->getCreatedBy( ) );
aVersions[i].TimeStamp = lcl_boostToUnoTime( pVersion->getLastModificationDate( ) );
aVersions[i].Comment = STD_TO_OUSTR( pVersion->getStringProperty("cmis:checkinComment") );
+ ++i;
}
return aVersions;
}
@@ -2049,8 +2035,7 @@ namespace cmis
vector< libcmis::ObjectPtr > children = pFolder->getChildren( );
// Loop over the results
- for ( vector< libcmis::ObjectPtr >::iterator it = children.begin();
- it != children.end(); ++it )
+ for ( const auto& rChild : children )
{
// TODO Cache the objects
@@ -2061,15 +2046,15 @@ namespace cmis
OUString sPath( m_sObjectPath );
if ( !sPath.endsWith("/") )
sPath += "/";
- sPath += STD_TO_OUSTR( ( *it )->getName( ) );
- OUString sId = STD_TO_OUSTR( ( *it )->getId( ) );
+ sPath += STD_TO_OUSTR( rChild->getName( ) );
+ OUString sId = STD_TO_OUSTR( rChild->getId( ) );
aUrl.setObjectId( sId );
aUrl.setObjectPath( sPath );
aUrl.setUsername( sUser );
uno::Reference< ucb::XContentIdentifier > xId = new ucbhelper::ContentIdentifier( aUrl.asString( ) );
- uno::Reference< ucb::XContent > xContent = new Content( m_xContext, m_pProvider, xId, *it );
+ uno::Reference< ucb::XContent > xContent = new Content( m_xContext, m_pProvider, xId, rChild );
results.push_back( xContent );
}
diff --git a/ucb/source/ucp/cmis/cmis_datasupplier.cxx b/ucb/source/ucp/cmis/cmis_datasupplier.cxx
index 83baa3ba37aa..dead6a2d6203 100644
--- a/ucb/source/ucp/cmis/cmis_datasupplier.cxx
+++ b/ucb/source/ucp/cmis/cmis_datasupplier.cxx
@@ -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;
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index ca5333493c54..0e6174831e6f 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -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 );