Simplify containers iterations in oox, opencl, package

Use range-based loop or replace with STL functions

Change-Id: I91405920d91383bc6cf13b9497d262b1f6f0a84d
Reviewed-on: https://gerrit.libreoffice.org/67848
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Arkadiy Illarionov 2019-02-15 00:08:43 +03:00 committed by Noel Grandin
parent 177747c445
commit 9d7620613d
14 changed files with 200 additions and 245 deletions

View File

@ -66,10 +66,10 @@ sal_Int32 ContextHandler2Helper::getCurrentElementWithMce() const
sal_Int32 ContextHandler2Helper::getCurrentElement() const
{
for ( ContextStack::reverse_iterator It = mxContextStack->rbegin();
It != mxContextStack->rend(); ++It )
if( getNamespace( It->mnElement ) != NMSP_mce )
return It->mnElement;
auto It = std::find_if(mxContextStack->rbegin(), mxContextStack->rend(),
[](const ElementInfo& rItem) { return getNamespace(rItem.mnElement) != NMSP_mce; });
if (It != mxContextStack->rend())
return It->mnElement;
return XML_ROOT_CONTEXT;
}

View File

@ -782,30 +782,31 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie
FSNS( XML_xmlns, XML_vt ), OUStringToOString(rSelf.getNamespaceURL(OOX_NS(officeDocPropsVT)), RTL_TEXTENCODING_UTF8).getStr(),
FSEND );
for (auto aIt = aprop.begin(); aIt != aprop.end(); ++aIt)
size_t nIndex = 0;
for (const auto& rProp : aprop)
{
if ( !aIt->Name.isEmpty() )
if ( !rProp.Name.isEmpty() )
{
OString aName = OUStringToOString( aIt->Name, RTL_TEXTENCODING_ASCII_US );
OString aName = OUStringToOString( rProp.Name, RTL_TEXTENCODING_ASCII_US );
// pid starts from 2 not from 1 as MS supports pid from 2
pAppProps->startElement( XML_property ,
XML_fmtid, "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
XML_pid, OString::number((aIt - aprop.begin()) + 2),
XML_pid, OString::number(nIndex + 2),
XML_name, aName,
FSEND);
switch ( aIt->Value.getValueTypeClass() )
switch ( rProp.Value.getValueTypeClass() )
{
case TypeClass_STRING:
{
OUString aValue;
aIt->Value >>= aValue;
rProp.Value >>= aValue;
writeElement( pAppProps, FSNS( XML_vt, XML_lpwstr ), aValue );
}
break;
case TypeClass_BOOLEAN:
{
bool val = *o3tl::forceAccess<bool>(aIt->Value);
bool val = *o3tl::forceAccess<bool>(rProp.Value);
writeElement( pAppProps, FSNS( XML_vt, XML_bool ), val ? 1 : 0);
}
break;
@ -815,23 +816,23 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie
util::Date aDate;
util::Duration aDuration;
util::DateTime aDateTime;
if ( ( aIt->Value ) >>= num )
if ( rProp.Value >>= num )
{
writeElement( pAppProps, FSNS( XML_vt, XML_i4 ), num );
}
else if ( ( aIt->Value ) >>= aDate )
else if ( rProp.Value >>= aDate )
{
aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Year, aDate.Month, aDate.Day, true );
writeElement( pAppProps, FSNS( XML_vt, XML_filetime ), aDateTime);
}
else if ( ( aIt->Value ) >>= aDuration )
else if ( rProp.Value >>= aDuration )
{
OUStringBuffer buf;
::sax::Converter::convertDuration( buf, aDuration );
OUString aDurationStr = buf.makeStringAndClear();
writeElement( pAppProps, FSNS( XML_vt, XML_lpwstr ), aDurationStr );
}
else if ( ( aIt->Value ) >>= aDateTime )
else if ( rProp.Value >>= aDateTime )
writeElement( pAppProps, FSNS( XML_vt, XML_filetime ), aDateTime );
else
//no other options
@ -841,6 +842,7 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie
}
pAppProps->endElement( XML_property );
}
++nIndex;
}
pAppProps->endElement( XML_Properties );
}

View File

@ -371,7 +371,7 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra
::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec;
OSL_ENSURE( aSeries.size() >= 3, "TypeGroupConverter::convertFromModel - too few stock chart series" );
int nRoleIdx = (aSeries.size() == 3) ? 1 : 0;
for( SeriesConvVector::iterator aIt = aSeries.begin(), aEnd = aSeries.end(); (nRoleIdx < 4) && (aIt != aEnd); ++nRoleIdx, ++aIt )
for( auto& rxSeriesConv : aSeries )
{
// create a data sequence with a specific role
OUString aRole;
@ -382,9 +382,13 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra
case 2: aRole = "values-min"; break;
case 3: aRole = "values-last"; break;
}
Reference< XLabeledDataSequence > xDataSeq = (*aIt)->createValueSequence( aRole );
Reference< XLabeledDataSequence > xDataSeq = rxSeriesConv->createValueSequence( aRole );
if( xDataSeq.is() )
aLabeledSeqVec.push_back( xDataSeq );
++nRoleIdx;
if (nRoleIdx >= 4)
break;
}
// attach labeled data sequences to series and insert series into chart type

View File

@ -150,10 +150,8 @@ void calculateHierChildOffsetScale(const oox::drawingml::ShapePtr& pShape,
{
const oox::drawingml::ShapePtr& pParentShape = rParents[nParent];
const std::vector<oox::drawingml::ShapePtr>& rChildren = pParentShape->getChildren();
auto it = std::find_if(
rChildren.begin(), rChildren.end(),
[pShape](const oox::drawingml::ShapePtr& pChild) { return pChild == pShape; });
if (it == rChildren.end())
if (std::none_of(rChildren.begin(), rChildren.end(),
[pShape](const oox::drawingml::ShapePtr& pChild) { return pChild == pShape; }))
// This is not our parent.
continue;
@ -1152,23 +1150,20 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
pPresNode->msModelId);
if( aNodeName != mrDgm.getData()->getPresOfNameMap().end() )
{
DiagramData::StringMap::value_type::second_type::const_iterator aVecIter=aNodeName->second.begin();
const DiagramData::StringMap::value_type::second_type::const_iterator aVecEnd=aNodeName->second.end();
while( aVecIter != aVecEnd )
for( const auto& rItem : aNodeName->second )
{
DiagramData::PointNameMap& rMap = mrDgm.getData()->getPointNameMap();
// pPresNode is the presentation node of the aDataNode2 data node.
DiagramData::PointNameMap::const_iterator aDataNode2 = rMap.find(aVecIter->first);
DiagramData::PointNameMap::const_iterator aDataNode2 = rMap.find(rItem.first);
if (aDataNode2 == rMap.end())
{
//busted, skip it
++aVecIter;
continue;
}
rShape->setDataNodeType(aDataNode2->second->mnType);
if( aVecIter->second == 0 )
if( rItem.second == 0 )
{
// grab shape attr from topmost element(s)
rShape->getShapeProperties() = aDataNode2->second->mpShape->getShapeProperties();
@ -1210,8 +1205,8 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
for (const auto& pSourceParagraph : rSourceParagraphs)
{
TextParagraph& rPara = pTextBody->addParagraph();
if (aVecIter->second != -1)
rPara.getProperties().setLevel(aVecIter->second);
if (rItem.second != -1)
rPara.getProperties().setLevel(rItem.second);
for (const auto& pRun : pSourceParagraph->getRuns())
rPara.addRun(pRun);
@ -1219,8 +1214,6 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
rPara.getProperties().apply(rBody->getParagraphs().front()->getProperties());
}
}
++aVecIter;
}
}
else

View File

@ -1190,35 +1190,35 @@ Reference< XShape > const & Shape::createAndInsert(
if( aShapeProps.hasProperty( PROP_FillGradient ) )
{
std::vector<beans::PropertyValue> aGradientStops;
auto aIt = aFillProperties.maGradientProps.maGradientStops.begin();
for( size_t i = 0; i < aFillProperties.maGradientProps.maGradientStops.size(); ++i )
size_t i = 0;
for( const auto& [rPos, rColor] : aFillProperties.maGradientProps.maGradientStops )
{ // for each stop in the gradient definition:
// save position
std::vector<beans::PropertyValue> aGradientStop;
aGradientStop.push_back(comphelper::makePropertyValue("Pos", aIt->first));
aGradientStop.push_back(comphelper::makePropertyValue("Pos", rPos));
OUString sStopColorScheme = aIt->second.getSchemeName();
OUString sStopColorScheme = rColor.getSchemeName();
if( sStopColorScheme.isEmpty() )
{
// save RGB color
aGradientStop.push_back(comphelper::makePropertyValue("RgbClr", aIt->second.getColor(rGraphicHelper, nFillPhClr)));
aGradientStop.push_back(comphelper::makePropertyValue("RgbClr", rColor.getColor(rGraphicHelper, nFillPhClr)));
// in the case of a RGB color, transformations are already applied to
// the color with the exception of alpha transformations. We only need
// to keep the transparency value to calculate the alpha value later.
if( aIt->second.hasTransparency() )
aGradientStop.push_back(comphelper::makePropertyValue("Transparency", aIt->second.getTransparency()));
if( rColor.hasTransparency() )
aGradientStop.push_back(comphelper::makePropertyValue("Transparency", rColor.getTransparency()));
}
else
{
// save color with scheme name
aGradientStop.push_back(comphelper::makePropertyValue("SchemeClr", sStopColorScheme));
// save all color transformations
aGradientStop.push_back(comphelper::makePropertyValue("Transformations", aIt->second.getTransformations()));
aGradientStop.push_back(comphelper::makePropertyValue("Transformations", rColor.getTransformations()));
}
aGradientStops.push_back(comphelper::makePropertyValue(OUString::number(i), comphelper::containerToSequence(aGradientStop)));
++aIt;
++i;
}
// If getFillProperties.moFillType is unused that means gradient is defined by a theme
// which is already saved into StyleFillRef property, so no need to save the explicit values too

View File

@ -450,21 +450,23 @@ void VbaFormControl::importStorage( StorageBase& rStrg, const AxClassTable& rCla
}
}
// apply caption/titles to pages
auto itCtrlId = pMultiPage->mnIDs.begin();
auto itCtrlId_end = pMultiPage->mnIDs.end();
AxArrayString::iterator itCaption = sCaptions.begin();
maControls.clear();
// need to sort the controls according to the order of the ids
for ( sal_Int32 index = 1 ; ( sCaptions.size() == idToPage.size() ) && itCtrlId != itCtrlId_end; ++itCtrlId, ++itCaption, ++index )
if ( sCaptions.size() == idToPage.size() )
{
IdToPageMap::iterator iter = idToPage.find( *itCtrlId );
if ( iter != idToPage.end() )
AxArrayString::iterator itCaption = sCaptions.begin();
for ( const auto& rCtrlId : pMultiPage->mnIDs )
{
AxPageModel* pPage = static_cast<AxPageModel*> ( iter->second->mxCtrlModel.get() );
IdToPageMap::iterator iter = idToPage.find( rCtrlId );
if ( iter != idToPage.end() )
{
AxPageModel* pPage = static_cast<AxPageModel*> ( iter->second->mxCtrlModel.get() );
pPage->importProperty( XML_Caption, *itCaption );
maControls.push_back( iter->second );
pPage->importProperty( XML_Caption, *itCaption );
maControls.push_back( iter->second );
}
++itCaption;
}
}
}

View File

@ -58,14 +58,14 @@ css::uno::Sequence<OUString> SetOfImplMatcherToStringSequence(const OpenCLConfig
css::uno::Sequence<OUString> result(rSet.size());
size_t n(0);
for (auto i = rSet.cbegin(); i != rSet.cend(); ++i)
for (const auto& rItem : rSet)
{
result[n++] =
(*i).maOS.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
(*i).maOSVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
(*i).maPlatformVendor.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
(*i).maDevice.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
(*i).maDriverVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B");
rItem.maOS.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
rItem.maOSVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
rItem.maPlatformVendor.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
rItem.maDevice.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" +
rItem.maDriverVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B");
}
return result;
@ -100,15 +100,15 @@ OpenCLConfig::ImplMatcherSet StringSequenceToSetOfImplMatcher(const css::uno::Se
{
OpenCLConfig::ImplMatcherSet result;
for (auto i = rSequence.begin(); i != rSequence.end(); ++i)
for (const auto& rItem : rSequence)
{
OpenCLConfig::ImplMatcher m;
sal_Int32 index(0);
m.maOS = getToken(*i, index);
m.maOSVersion = getToken(*i, index);
m.maPlatformVendor = getToken(*i, index);
m.maDevice = getToken(*i, index);
m.maDriverVersion = getToken(*i, index);
m.maOS = getToken(rItem, index);
m.maOSVersion = getToken(rItem, index);
m.maPlatformVendor = getToken(rItem, index);
m.maDevice = getToken(rItem, index);
m.maDriverVersion = getToken(rItem, index);
result.insert(m);
}
@ -158,12 +158,12 @@ bool match(const OpenCLConfig::ImplMatcher& rListEntry, const OpenCLPlatformInfo
bool match(const OpenCLConfig::ImplMatcherSet& rList, const OpenCLPlatformInfo& rPlatform, const OpenCLDeviceInfo& rDevice, const char* sKindOfList)
{
for (auto i = rList.cbegin(); i != rList.end(); ++i)
for (const auto& rListEntry : rList)
{
SAL_INFO("opencl", "Looking for match for platform=" << rPlatform << ", device=" << rDevice <<
" in " << sKindOfList << " entry=" << *i);
" in " << sKindOfList << " entry=" << rListEntry);
if (match(*i, rPlatform, rDevice))
if (match(rListEntry, rPlatform, rDevice))
{
SAL_INFO("opencl", "Match!");
return true;

View File

@ -264,18 +264,10 @@ void SAL_CALL OHierarchyElement_Impl::disposing( const lang::EventObject& Source
::osl::ClearableMutexGuard aGuard( m_aMutex );
uno::Reference< embed::XExtendedStorageStream > xStream( Source.Source, uno::UNO_QUERY );
for ( OWeakStorRefList_Impl::iterator pStorageIter = m_aOpenStreams.begin();
pStorageIter != m_aOpenStreams.end(); )
{
if ( !pStorageIter->get().is() || pStorageIter->get() == xStream )
{
pStorageIter = m_aOpenStreams.erase(pStorageIter);
}
else
{
++pStorageIter;
}
}
m_aOpenStreams.erase(std::remove_if(m_aOpenStreams.begin(), m_aOpenStreams.end(),
[&xStream](const OWeakStorRefList_Impl::value_type& rxStorage) {
return !rxStorage.get().is() || rxStorage.get() == xStream; }),
m_aOpenStreams.end());
aGuard.clear();

View File

@ -481,13 +481,12 @@ void OWriteStream_Impl::DisposeWrappers()
if ( !m_aInputStreamsVector.empty() )
{
for ( InputStreamsVector_Impl::iterator pStreamIter = m_aInputStreamsVector.begin();
pStreamIter != m_aInputStreamsVector.end(); ++pStreamIter )
for ( auto& pStream : m_aInputStreamsVector )
{
if ( *pStreamIter )
if ( pStream )
{
(*pStreamIter)->InternalDispose();
(*pStreamIter) = nullptr;
pStream->InternalDispose();
pStream = nullptr;
}
}

View File

@ -303,13 +303,12 @@ OStorage_Impl::~OStorage_Impl()
}
else if ( !m_aReadOnlyWrapVector.empty() )
{
for ( StorageHoldersType::iterator pStorageIter = m_aReadOnlyWrapVector.begin();
pStorageIter != m_aReadOnlyWrapVector.end(); ++pStorageIter )
for ( auto& rStorage : m_aReadOnlyWrapVector )
{
uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
uno::Reference< embed::XStorage > xTmp = rStorage.m_xWeakRef;
if ( xTmp.is() )
try {
pStorageIter->m_pPointer->InternalDispose( false );
rStorage.m_pPointer->InternalDispose( false );
} catch( const uno::Exception& rException )
{
SAL_INFO("package.xstor", "Quiet exception: " << rException);
@ -652,11 +651,10 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes
if ( !m_xPackageFolder.is() )
throw embed::InvalidStorageException( THROW_WHERE );
for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenVector.end(); ++pElementIter )
for ( auto& pElement : m_aChildrenVector )
{
if ( !(*pElementIter)->m_bIsRemoved )
CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect );
if ( !pElement->m_bIsRemoved )
CopyStorageElement( pElement, xDest, pElement->m_aName, bDirect );
}
// move storage properties to the destination one ( means changeable properties )
@ -1007,19 +1005,17 @@ void OStorage_Impl::Commit()
xNewPackageFolder = m_xPackageFolder;
// remove replaced removed elements
for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin();
pDeletedIter != m_aDeletedVector.end();
++pDeletedIter )
for ( auto& pDeleted : m_aDeletedVector )
{
if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage )
RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName );
if ( m_nStorageType == embed::StorageFormats::OFOPXML && !pDeleted->m_bIsStorage )
RemoveStreamRelInfo( pDeleted->m_aOriginalName );
// the removed elements are not in new temporary storage
if ( m_bCommited || m_bIsRoot )
xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName );
delete *pDeletedIter;
*pDeletedIter = nullptr;
xNewPackageFolder->removeByName( pDeleted->m_aOriginalName );
delete pDeleted;
pDeleted = nullptr;
}
m_aDeletedVector.clear();
@ -1047,116 +1043,116 @@ void OStorage_Impl::Commit()
}
// there should be no more deleted elements
for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter )
for ( auto& pElement : m_aChildrenVector )
{
// if it is a 'duplicate commit' inserted elements must be really inserted to package later
// since thay can conflict with renamed elements
if ( !(*pElementIter)->m_bIsInserted )
if ( !pElement->m_bIsInserted )
{
// for now stream is opened in direct mode that means that in case
// storage is committed all the streams from it are committed in current state.
// following two steps are separated to allow easily implement transacted mode
// for streams if we need it in future.
// Only hierarchical access uses transacted streams currently
if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream
&& !(*pElementIter)->m_xStream->IsTransacted() )
(*pElementIter)->m_xStream->Commit();
if ( !pElement->m_bIsStorage && pElement->m_xStream
&& !pElement->m_xStream->IsTransacted() )
pElement->m_xStream->Commit();
// if the storage was not open, there is no need to commit it ???
// the storage should be checked that it is committed
if ((*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStorage && (*pElementIter)->m_xStorage->m_bCommited)
if (pElement->m_bIsStorage && pElement->m_xStorage && pElement->m_xStorage->m_bCommited)
{
// it's temporary PackageFolder should be inserted instead of current one
// also the new copy of PackageFolder should be used by the children storages
// the renamed elements are not in new temporary storage
if ( m_bCommited || m_bIsRoot )
xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
xNewPackageFolder->removeByName( pElement->m_aOriginalName );
(*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
pElement->m_xStorage->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder);
}
else if (!(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream && (*pElementIter)->m_xStream->m_bFlushed)
else if (!pElement->m_bIsStorage && pElement->m_xStream && pElement->m_xStream->m_bFlushed)
{
if ( m_nStorageType == embed::StorageFormats::OFOPXML )
CommitStreamRelInfo( *pElementIter );
CommitStreamRelInfo( pElement );
// the renamed elements are not in new temporary storage
if ( m_bCommited || m_bIsRoot )
xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
xNewPackageFolder->removeByName( pElement->m_aOriginalName );
(*pElementIter)->m_xStream->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
pElement->m_xStream->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder);
}
else if ( !m_bCommited && !m_bIsRoot )
{
// the element must be just copied to the new temporary package folder
// the connection with the original package should not be lost just because
// the element is still referred by the folder in the original hierarchy
uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
uno::Any aPackageElement = m_xPackageFolder->getByName( pElement->m_aOriginalName );
xNewPackageFolder->insertByName( pElement->m_aName, aPackageElement );
}
else if ( (*pElementIter)->m_aName != (*pElementIter)->m_aOriginalName )
else if ( pElement->m_aName != pElement->m_aOriginalName )
{
// this is the case when xNewPackageFolder refers to m_xPackageFolder
// in case the name was changed and it is not a changed storage - rename the element
uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
uno::Any aPackageElement = xNewPackageFolder->getByName( pElement->m_aOriginalName );
xNewPackageFolder->removeByName( pElement->m_aOriginalName );
xNewPackageFolder->insertByName( pElement->m_aName, aPackageElement );
if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
if ( m_nStorageType == embed::StorageFormats::OFOPXML && !pElement->m_bIsStorage )
{
if (!(*pElementIter)->m_xStream)
if (!pElement->m_xStream)
{
OpenSubStream( *pElementIter );
if (!(*pElementIter)->m_xStream)
OpenSubStream( pElement );
if (!pElement->m_xStream)
throw uno::RuntimeException( THROW_WHERE );
}
CommitStreamRelInfo( *pElementIter );
CommitStreamRelInfo( pElement );
}
}
(*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
pElement->m_aOriginalName = pElement->m_aName;
}
}
for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter )
for ( auto& pElement : m_aChildrenVector )
{
// now inserted elements can be inserted to the package
if ( (*pElementIter)->m_bIsInserted )
if ( pElement->m_bIsInserted )
{
(*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
pElement->m_aOriginalName = pElement->m_aName;
if ( (*pElementIter)->m_bIsStorage )
if ( pElement->m_bIsStorage )
{
if ((*pElementIter)->m_xStorage->m_bCommited)
if (pElement->m_xStorage->m_bCommited)
{
OSL_ENSURE((*pElementIter)->m_xStorage, "An inserted storage is incomplete!");
if (!(*pElementIter)->m_xStorage)
OSL_ENSURE(pElement->m_xStorage, "An inserted storage is incomplete!");
if (!pElement->m_xStorage)
throw uno::RuntimeException( THROW_WHERE );
(*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
pElement->m_xStorage->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder);
(*pElementIter)->m_bIsInserted = false;
pElement->m_bIsInserted = false;
}
}
else
{
OSL_ENSURE((*pElementIter)->m_xStream, "An inserted stream is incomplete!");
if (!(*pElementIter)->m_xStream)
OSL_ENSURE(pElement->m_xStream, "An inserted stream is incomplete!");
if (!pElement->m_xStream)
throw uno::RuntimeException( THROW_WHERE );
if (!(*pElementIter)->m_xStream->IsTransacted())
(*pElementIter)->m_xStream->Commit();
if (!pElement->m_xStream->IsTransacted())
pElement->m_xStream->Commit();
if ((*pElementIter)->m_xStream->m_bFlushed)
if (pElement->m_xStream->m_bFlushed)
{
if ( m_nStorageType == embed::StorageFormats::OFOPXML )
CommitStreamRelInfo( *pElementIter );
CommitStreamRelInfo( pElement );
(*pElementIter)->m_xStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
pElement->m_xStream->InsertIntoPackageFolder( pElement->m_aName, xNewPackageFolder );
(*pElementIter)->m_bIsInserted = false;
pElement->m_bIsInserted = false;
}
}
}
@ -1235,16 +1231,14 @@ void OStorage_Impl::Revert()
}
// return replaced removed elements
for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin();
pDeletedIter != m_aDeletedVector.end();
++pDeletedIter )
for ( auto& pDeleted : m_aDeletedVector )
{
m_aChildrenVector.push_back( *pDeletedIter );
m_aChildrenVector.push_back( pDeleted );
ClearElement( *pDeletedIter );
ClearElement( pDeleted );
(*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName;
(*pDeletedIter)->m_bIsRemoved = false;
pDeleted->m_aName = pDeleted->m_aOriginalName;
pDeleted->m_bIsRemoved = false;
}
m_aDeletedVector.clear();
@ -1293,12 +1287,10 @@ SotElement_Impl* OStorage_Impl::FindElement( const OUString& rName )
ReadContents();
for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenVector.end(); ++pElementIter )
{
if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved )
return *pElementIter;
}
auto pElementIter = std::find_if(m_aChildrenVector.begin(), m_aChildrenVector.end(),
[&rName](const SotElement_Impl* pElement) { return pElement->m_aName == rName && !pElement->m_bIsRemoved; });
if (pElementIter != m_aChildrenVector.end())
return *pElementIter;
return nullptr;
}
@ -1414,16 +1406,15 @@ SotElement_Impl* OStorage_Impl::InsertElement( const OUString& aName, bool bIsSt
SotElement_Impl* pDeletedElm = nullptr;
for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenVector.end(); ++pElementIter )
for ( const auto& pElement : m_aChildrenVector )
{
if ( (*pElementIter)->m_aName == aName )
if ( pElement->m_aName == aName )
{
SAL_WARN_IF( !(*pElementIter)->m_bIsRemoved, "package.xstor", "Try to insert an element instead of existing one!" );
if ( (*pElementIter)->m_bIsRemoved )
SAL_WARN_IF( !pElement->m_bIsRemoved, "package.xstor", "Try to insert an element instead of existing one!" );
if ( pElement->m_bIsRemoved )
{
SAL_WARN_IF( (*pElementIter)->m_bIsInserted, "package.xstor", "Inserted elements must be deleted immediately!" );
pDeletedElm = *pElementIter;
SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted elements must be deleted immediately!" );
pDeletedElm = pElement;
break;
}
}
@ -1500,11 +1491,10 @@ uno::Sequence< OUString > OStorage_Impl::GetElementNames()
uno::Sequence< OUString > aElementNames( nSize );
sal_uInt32 nInd = 0;
for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenVector.end(); ++pElementIter )
for ( const auto& pElement : m_aChildrenVector )
{
if ( !(*pElementIter)->m_bIsRemoved )
aElementNames[nInd++] = (*pElementIter)->m_aName;
if ( !pElement->m_bIsRemoved )
aElementNames[nInd++] = pElement->m_aName;
}
aElementNames.realloc( nInd );
@ -1847,10 +1837,9 @@ void OStorage::InternalDispose( bool bNotifyImpl )
// deregister m_pData->m_pSubElDispListener and dispose all of them
if ( !m_pData->m_aOpenSubComponentsVector.empty() )
{
for ( WeakComponentVector::iterator pCompIter = m_pData->m_aOpenSubComponentsVector.begin();
pCompIter != m_pData->m_aOpenSubComponentsVector.end(); ++pCompIter )
for ( auto& pComp : m_pData->m_aOpenSubComponentsVector )
{
uno::Reference< lang::XComponent > xTmp = *pCompIter;
uno::Reference< lang::XComponent > xTmp = pComp;
if ( xTmp.is() )
{
xTmp->removeEventListener( uno::Reference< lang::XEventListener >(
@ -1898,17 +1887,12 @@ void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild
// this method must not contain any locking
// the locking is done in the listener
for ( WeakComponentVector::iterator pCompIter = m_pData->m_aOpenSubComponentsVector.begin();
pCompIter != m_pData->m_aOpenSubComponentsVector.end(); )
{
uno::Reference< lang::XComponent > xTmp = *pCompIter;
if ( !xTmp.is() || xTmp == xChild )
{
pCompIter = m_pData->m_aOpenSubComponentsVector.erase(pCompIter);
}
else
++pCompIter;
}
auto& rVec = m_pData->m_aOpenSubComponentsVector;
rVec.erase(std::remove_if(rVec.begin(), rVec.end(),
[&xChild](const uno::Reference<lang::XComponent>& xTmp) {
return !xTmp.is() || xTmp == xChild;
}),
rVec.end());
}
void OStorage::BroadcastModifiedIfNecessary()
@ -2399,12 +2383,8 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
if ( nStorageMode & embed::ElementModes::TRUNCATE )
{
for ( SotElementVector_Impl::iterator pElementIter = pElement->m_xStorage->m_aChildrenVector.begin();
pElementIter != pElement->m_xStorage->m_aChildrenVector.end(); )
for ( SotElement_Impl* pElementToDel : pElement->m_xStorage->m_aChildrenVector )
{
SotElement_Impl* pElementToDel = *pElementIter;
++pElementIter;
m_pImpl->RemoveElement( pElementToDel );
}
}
@ -3616,15 +3596,13 @@ void SAL_CALL OStorage::revert()
throw lang::DisposedException( THROW_WHERE );
}
for ( SotElementVector_Impl::iterator pElementIter = m_pImpl->m_aChildrenVector.begin();
pElementIter != m_pImpl->m_aChildrenVector.end(); ++pElementIter )
{
if ( ((*pElementIter)->m_xStorage
&& ( (*pElementIter)->m_xStorage->m_pAntiImpl || !(*pElementIter)->m_xStorage->m_aReadOnlyWrapVector.empty() ))
|| ((*pElementIter)->m_xStream
&& ( (*pElementIter)->m_xStream->m_pAntiImpl || !(*pElementIter)->m_xStream->m_aInputStreamsVector.empty()) ) )
throw io::IOException( THROW_WHERE ); // TODO: access denied
}
bool bThrow = std::any_of(m_pImpl->m_aChildrenVector.begin(), m_pImpl->m_aChildrenVector.end(), [](const SotElement_Impl* pElement) {
return (pElement->m_xStorage
&& (pElement->m_xStorage->m_pAntiImpl || !pElement->m_xStorage->m_aReadOnlyWrapVector.empty()))
|| (pElement->m_xStream
&& (pElement->m_xStream->m_pAntiImpl || !pElement->m_xStream->m_aInputStreamsVector.empty())); });
if (bThrow)
throw io::IOException( THROW_WHERE ); // TODO: access denied
if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated )
return; // nothing to do

View File

@ -1086,18 +1086,18 @@ void ZipFile::recover()
nCompressedSize = nCompressedSize32;
nSize = nSize32;
for( EntryHash::iterator aIter = aEntries.begin(); aIter != aEntries.end(); ++aIter )
for( auto& rEntry : aEntries )
{
ZipEntry aTmp = (*aIter).second;
ZipEntry aTmp = rEntry.second;
// this is a broken package, accept this block not only for DEFLATED streams
if( (*aIter).second.nFlag & 8 )
if( rEntry.second.nFlag & 8 )
{
sal_Int64 nStreamOffset = nGenPos + nPos - nCompressedSize;
if ( nStreamOffset == (*aIter).second.nOffset && nCompressedSize > (*aIter).second.nCompressedSize )
if ( nStreamOffset == rEntry.second.nOffset && nCompressedSize > rEntry.second.nCompressedSize )
{
// only DEFLATED blocks need to be checked
bool bAcceptBlock = ( (*aIter).second.nMethod == STORED && nCompressedSize == nSize );
bool bAcceptBlock = ( rEntry.second.nMethod == STORED && nCompressedSize == nSize );
if ( !bAcceptBlock )
{
@ -1109,19 +1109,19 @@ void ZipFile::recover()
if ( bAcceptBlock )
{
(*aIter).second.nCrc = nCRC32;
(*aIter).second.nCompressedSize = nCompressedSize;
(*aIter).second.nSize = nSize;
rEntry.second.nCrc = nCRC32;
rEntry.second.nCompressedSize = nCompressedSize;
rEntry.second.nSize = nSize;
}
}
#if 0
// for now ignore clearly broken streams
else if( !(*aIter).second.nCompressedSize )
else if( !rEntry.second.nCompressedSize )
{
(*aIter).second.nCrc = nCRC32;
sal_Int32 nRealStreamSize = nGenPos + nPos - (*aIter).second.nOffset;
(*aIter).second.nCompressedSize = nGenPos + nPos - (*aIter).second.nOffset;
(*aIter).second.nSize = nSize;
rEntry.second.nCrc = nCRC32;
sal_Int32 nRealStreamSize = nGenPos + nPos - rEntry.second.nOffset;
rEntry.second.nCompressedSize = nRealStreamSize;
rEntry.second.nSize = nSize;
}
#endif
}

View File

@ -1103,20 +1103,17 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
uno::Sequence< beans::StringPair > aOverridesSequence(aManList.size());
sal_Int32 nOverSeqLength = 0;
for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(),
aEnd = aManList.end();
aIter != aEnd;
++aIter)
for (const auto& rMan : aManList)
{
OUString aPath;
OUString aType;
OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name == "MediaType" && ( *aIter )[PKG_MNFST_FULLPATH].Name == "FullPath",
OSL_ENSURE( rMan[PKG_MNFST_MEDIATYPE].Name == "MediaType" && rMan[PKG_MNFST_FULLPATH].Name == "FullPath",
"The mediatype sequence format is wrong!" );
( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType;
rMan[PKG_MNFST_MEDIATYPE].Value >>= aType;
if ( !aType.isEmpty() )
{
// only nonempty type makes sense here
( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath;
rMan[PKG_MNFST_FULLPATH].Value >>= aPath;
//FIXME: For now we have no way of differentiating defaults from others.
aOverridesSequence[nOverSeqLength].First = "/" + aPath;
aOverridesSequence[nOverSeqLength].Second = aType;

View File

@ -27,6 +27,7 @@
#include "ZipPackageFolderEnumeration.hxx"
#include <com/sun/star/packages/zip/ZipConstants.hpp>
#include <com/sun/star/embed/StorageFormats.hpp>
#include <comphelper/sequence.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <osl/diagnose.h>
@ -81,12 +82,9 @@ bool ZipPackageFolder::LookForUnexpectedODF12Streams( const OUString& aPath )
{
bool bHasUnexpected = false;
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
!bHasUnexpected && aCI != aEnd;
++aCI)
for (const auto& [rShortName, rxInfo] : maContents)
{
const OUString &rShortName = (*aCI).first;
const ZipContentInfo &rInfo = *(*aCI).second;
const ZipContentInfo &rInfo = *rxInfo;
if ( rInfo.bFolder )
{
@ -125,6 +123,9 @@ bool ZipPackageFolder::LookForUnexpectedODF12Streams( const OUString& aPath )
}
}
}
if (bHasUnexpected)
break;
}
return bHasUnexpected;
@ -138,12 +139,9 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair&
else
aExt = "." + aPair.First;
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
aCI != aEnd;
++aCI)
for (const auto& [rShortName, rxInfo] : maContents)
{
const OUString &rShortName = (*aCI).first;
const ZipContentInfo &rInfo = *(*aCI).second;
const ZipContentInfo &rInfo = *rxInfo;
if ( rInfo.bFolder )
rInfo.pFolder->setChildStreamsTypeByExtension( aPair );
@ -229,13 +227,7 @@ uno::Any SAL_CALL ZipPackageFolder::getByName( const OUString& aName )
}
uno::Sequence< OUString > SAL_CALL ZipPackageFolder::getElementNames( )
{
sal_uInt32 i=0, nSize = maContents.size();
uno::Sequence < OUString > aSequence ( nSize );
for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end();
aIterator != aEnd;
++i, ++aIterator)
aSequence[i] = (*aIterator).first;
return aSequence;
return comphelper::mapKeysToSequence(maContents);
}
sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName )
{
@ -335,12 +327,9 @@ void ZipPackageFolder::saveContents(
}
}
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
aCI != aEnd;
++aCI)
for (const auto& [rShortName, rxInfo] : maContents)
{
const OUString &rShortName = (*aCI).first;
const ZipContentInfo &rInfo = *(*aCI).second;
const ZipContentInfo &rInfo = *rxInfo;
if ( !bMimeTypeStreamStored || rShortName != aMimeTypeStreamName )
{

View File

@ -309,7 +309,7 @@ uno::Sequence< OUString > SAL_CALL OZipFileAccess::getElementNames()
uno::Sequence< OUString > aNames( m_pZipFile->GetEntryHash().size() );
sal_Int32 nLen = 0;
for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter )
for ( const auto& rEntry : m_pZipFile->GetEntryHash() )
{
if ( aNames.getLength() < ++nLen )
{
@ -317,7 +317,7 @@ uno::Sequence< OUString > SAL_CALL OZipFileAccess::getElementNames()
aNames.realloc( nLen );
}
aNames[nLen-1] = (*aIter).second.sPath;
aNames[nLen-1] = rEntry.second.sPath;
}
if ( aNames.getLength() != nLen )
@ -384,19 +384,18 @@ uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern(
// Code to compare strings by patterns
uno::Sequence< OUString > aPattern = GetPatternsFromString_Impl( aPatternString );
for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter )
auto aIter = std::find_if(m_pZipFile->GetEntryHash().begin(), m_pZipFile->GetEntryHash().end(),
[&aPattern](const EntryHash::value_type& rEntry) { return StringGoodForPattern_Impl(rEntry.second.sPath, aPattern); });
if (aIter != m_pZipFile->GetEntryHash().end())
{
if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) )
{
uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second,
::rtl::Reference< EncryptionData >(),
false,
m_aMutexHolder ) );
uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second,
::rtl::Reference< EncryptionData >(),
false,
m_aMutexHolder ) );
if ( !xEntryStream.is() )
throw uno::RuntimeException(THROW_WHERE );
return xEntryStream;
}
if ( !xEntryStream.is() )
throw uno::RuntimeException(THROW_WHERE );
return xEntryStream;
}
throw container::NoSuchElementException(THROW_WHERE );