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

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 177747c4
......@@ -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;
}
......
......@@ -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 );
}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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() );
pPage->importProperty( XML_Caption, *itCaption );
maControls.push_back( iter->second );
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 );
}
++itCaption;
}
}
}
......
......@@ -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;
......
......@@ -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();
......
......@@ -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;
}
}
......
......@@ -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<