[Libreoffice-commits] core.git: sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Feb 9 16:37:20 UTC 2019
sc/source/core/data/bcaslot.cxx | 35 +--
sc/source/core/data/cellvalues.cxx | 77 +++-----
sc/source/core/data/colorscale.cxx | 4
sc/source/core/data/column.cxx | 33 +--
sc/source/core/data/column2.cxx | 127 ++++---------
sc/source/core/data/column3.cxx | 45 ++--
sc/source/core/data/column4.cxx | 78 +++-----
sc/source/core/data/columnspanset.cxx | 17 -
sc/source/core/data/conditio.cxx | 163 ++++++++--------
sc/source/core/data/dociter.cxx | 19 -
sc/source/core/data/documen2.cxx | 8
sc/source/core/data/documen3.cxx | 65 +++---
sc/source/core/data/documen4.cxx | 85 ++++----
sc/source/core/data/documen7.cxx | 24 +-
sc/source/core/data/documen8.cxx | 11 -
sc/source/core/data/documen9.cxx | 25 +-
sc/source/core/data/document.cxx | 327 ++++++++++++++++++++--------------
sc/source/core/data/document10.cxx | 53 +----
18 files changed, 581 insertions(+), 615 deletions(-)
New commits:
commit 4192288e67333fe0ba78611f3809d8dccdce33de
Author: Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Feb 9 17:17:23 2019 +0300
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Feb 9 17:36:59 2019 +0100
Simplify containers iterations in sc/source/core/data/[b-d].cxx
Use range-based loop or replace with STL functions
Change-Id: Ifb3c6a2fdcd32122a6fd371191b058117015c3ed
Reviewed-on: https://gerrit.libreoffice.org/67588
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index bf94a3b6b397..b3af7fd0b5ed 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -471,10 +471,9 @@ void ScBroadcastAreaSlot::UpdateInsert( ScBroadcastArea* pArea )
{
SvtBroadcaster& rTarget = pTarget->GetBroadcaster();
SvtBroadcaster::ListenersType& rListeners = pArea->GetBroadcaster().GetAllListeners();
- SvtBroadcaster::ListenersType::iterator it = rListeners.begin(), itEnd = rListeners.end();
- for (; it != itEnd; ++it)
+ for (auto& pListener : rListeners)
{
- SvtListener& rListener = **it;
+ SvtListener& rListener = *pListener;
rListener.StartListening(rTarget);
}
}
@@ -557,13 +556,12 @@ void ScBroadcastAreaSlot::GetAllListeners(
}
SvtBroadcaster::ListenersType& rLst = pArea->GetBroadcaster().GetAllListeners();
- SvtBroadcaster::ListenersType::iterator itLst = rLst.begin(), itLstEnd = rLst.end();
- for (; itLst != itLstEnd; ++itLst)
+ for (const auto& pListener : rLst)
{
sc::AreaListener aEntry;
aEntry.maArea = rAreaRange;
aEntry.mbGroupListening = pArea->IsGroupListening();
- aEntry.mpListener = *itLst;
+ aEntry.mpListener = pListener;
rListeners.push_back(aEntry);
}
}
@@ -572,10 +570,8 @@ void ScBroadcastAreaSlot::GetAllListeners(
#if DEBUG_AREA_BROADCASTER
void ScBroadcastAreaSlot::Dump() const
{
- ScBroadcastAreas::const_iterator it = aBroadcastAreaTbl.begin(), itEnd = aBroadcastAreaTbl.end();
- for (; it != itEnd; ++it)
+ for (const ScBroadcastAreaEntry& rEntry : aBroadcastAreaTbl)
{
- const ScBroadcastAreaEntry& rEntry = *it;
const ScBroadcastArea* pArea = rEntry.mpArea;
const SvtBroadcaster& rBC = pArea->GetBroadcaster();
const SvtBroadcaster::ListenersType& rListeners = rBC.GetAllListeners();
@@ -1110,10 +1106,8 @@ bool ScBroadcastAreaSlotMachine::BulkBroadcastGroupAreas( SfxHintId nHintId )
sc::BulkDataHint aHint( *pDoc, nHintId);
bool bBroadcasted = false;
- BulkGroupAreasType::iterator it = m_BulkGroupAreas.begin(), itEnd = m_BulkGroupAreas.end();
- for (; it != itEnd; ++it)
+ for (const auto& [pArea, rxSpans] : m_BulkGroupAreas)
{
- ScBroadcastArea* pArea = it->first;
assert(pArea);
SvtBroadcaster& rBC = pArea->GetBroadcaster();
if (!rBC.HasListeners())
@@ -1124,7 +1118,7 @@ bool ScBroadcastAreaSlotMachine::BulkBroadcastGroupAreas( SfxHintId nHintId )
}
else
{
- const sc::ColumnSpanSet *const pSpans = it->second.get();
+ const sc::ColumnSpanSet *const pSpans = rxSpans.get();
assert(pSpans);
aHint.setSpans(pSpans);
rBC.Broadcast(aHint);
@@ -1164,13 +1158,12 @@ void ScBroadcastAreaSlotMachine::FinallyEraseAreas( ScBroadcastAreaSlot* pSlot )
// invalidate iterators and would be inefficient anyway. Instead, copy
// elements to be preserved (usually none!) to temporary vector and swap.
AreasToBeErased aCopy;
- for (AreasToBeErased::iterator aIt( maAreasToBeErased.begin());
- aIt != maAreasToBeErased.end(); ++aIt)
+ for (auto& rArea : maAreasToBeErased)
{
- if ((*aIt).first == pSlot)
- pSlot->EraseArea( (*aIt).second);
+ if (rArea.first == pSlot)
+ pSlot->EraseArea( rArea.second);
else
- aCopy.push_back( *aIt);
+ aCopy.push_back( rArea);
}
maAreasToBeErased.swap( aCopy);
}
@@ -1206,12 +1199,10 @@ std::vector<sc::AreaListener> ScBroadcastAreaSlotMachine::GetAllListeners(
void ScBroadcastAreaSlotMachine::Dump() const
{
cout << "slot distribution count: " << nBcaSlots << endl;
- TableSlotsMap::const_iterator it = aTableSlotsMap.begin(), itEnd = aTableSlotsMap.end();
- for (; it != itEnd; ++it)
+ for (const auto& [rIndex, pTabSlots] : aTableSlotsMap)
{
- cout << "-- sheet (index: " << it->first << ")" << endl;
+ cout << "-- sheet (index: " << rIndex << ")" << endl;
- TableSlots* pTabSlots = it->second;
assert(pTabSlots);
ScBroadcastAreaSlot** ppSlots = pTabSlots->getSlots();
for (SCSIZE i = 0; i < nBcaSlots; ++i)
diff --git a/sc/source/core/data/cellvalues.cxx b/sc/source/core/data/cellvalues.cxx
index 5b065e1ff3b3..83c01a9080ca 100644
--- a/sc/source/core/data/cellvalues.cxx
+++ b/sc/source/core/data/cellvalues.cxx
@@ -67,27 +67,23 @@ void CellValues::swapNonEmpty( ScColumn& rCol )
{
std::vector<BlockPos> aBlocksToSwap;
+ // Go through static value blocks and record their positions and sizes.
+ for (const auto& rCell : mpImpl->maCells)
{
- // Go through static value blocks and record their positions and sizes.
- sc::CellStoreType::const_iterator it = mpImpl->maCells.begin(), itEnd = mpImpl->maCells.end();
- for (; it != itEnd; ++it)
- {
- if (it->type == sc::element_type_empty)
- continue;
+ if (rCell.type == sc::element_type_empty)
+ continue;
- BlockPos aPos;
- aPos.mnStart = it->position;
- aPos.mnEnd = aPos.mnStart + it->size - 1;
- aBlocksToSwap.push_back(aPos);
- }
+ BlockPos aPos;
+ aPos.mnStart = rCell.position;
+ aPos.mnEnd = aPos.mnStart + rCell.size - 1;
+ aBlocksToSwap.push_back(aPos);
}
// Do the swapping. The undo storage will store the replaced formula cells after this.
- std::vector<BlockPos>::const_iterator it = aBlocksToSwap.begin(), itEnd = aBlocksToSwap.end();
- for (; it != itEnd; ++it)
+ for (const auto& rBlock : aBlocksToSwap)
{
- rCol.maCells.swap(it->mnStart, it->mnEnd, mpImpl->maCells, it->mnStart);
- rCol.maCellTextAttrs.swap(it->mnStart, it->mnEnd, mpImpl->maCellTextAttrs, it->mnStart);
+ rCol.maCells.swap(rBlock.mnStart, rBlock.mnEnd, mpImpl->maCells, rBlock.mnStart);
+ rCol.maCellTextAttrs.swap(rBlock.mnStart, rBlock.mnEnd, mpImpl->maCellTextAttrs, rBlock.mnStart);
}
}
@@ -139,14 +135,13 @@ void CellValues::swap( CellValues& r )
std::vector<CellValueSpan> CellValues::getNonEmptySpans() const
{
std::vector<CellValueSpan> aRet;
- CellStoreType::const_iterator it = mpImpl->maCells.begin(), itEnd = mpImpl->maCells.end();
- for (; it != itEnd; ++it)
+ for (const auto& rCell : mpImpl->maCells)
{
- if (it->type != element_type_empty)
+ if (rCell.type != element_type_empty)
{
// Record this span.
- size_t nRow1 = it->position;
- size_t nRow2 = nRow1 + it->size - 1;
+ size_t nRow1 = rCell.position;
+ size_t nRow2 = nRow1 + rCell.size - 1;
aRet.emplace_back(nRow1, nRow2);
}
}
@@ -164,31 +159,30 @@ void CellValues::copyCellsTo( ScColumn& rCol, SCROW nRow ) const
SCROW nCurRow = nRow;
CellStoreType::iterator itPos = rDest.begin();
- CellStoreType::const_iterator itBlk = rSrc.begin(), itBlkEnd = rSrc.end();
- for (; itBlk != itBlkEnd; ++itBlk)
+ for (const auto& rBlk : rSrc)
{
- switch (itBlk->type)
+ switch (rBlk.type)
{
case element_type_numeric:
{
- numeric_block::const_iterator it = numeric_block::begin(*itBlk->data);
- numeric_block::const_iterator itEnd = numeric_block::end(*itBlk->data);
+ numeric_block::const_iterator it = numeric_block::begin(*rBlk.data);
+ numeric_block::const_iterator itEnd = numeric_block::end(*rBlk.data);
itPos = rDest.set(itPos, nCurRow, it, itEnd);
}
break;
case element_type_string:
{
- string_block::const_iterator it = string_block::begin(*itBlk->data);
- string_block::const_iterator itEnd = string_block::end(*itBlk->data);
+ string_block::const_iterator it = string_block::begin(*rBlk.data);
+ string_block::const_iterator itEnd = string_block::end(*rBlk.data);
itPos = rDest.set(itPos, nCurRow, it, itEnd);
}
break;
case element_type_edittext:
{
- edittext_block::const_iterator it = edittext_block::begin(*itBlk->data);
- edittext_block::const_iterator itEnd = edittext_block::end(*itBlk->data);
+ edittext_block::const_iterator it = edittext_block::begin(*rBlk.data);
+ edittext_block::const_iterator itEnd = edittext_block::end(*rBlk.data);
std::vector<EditTextObject*> aVals;
- aVals.reserve(itBlk->size);
+ aVals.reserve(rBlk.size);
for (; it != itEnd; ++it)
{
const EditTextObject* p = *it;
@@ -199,10 +193,10 @@ void CellValues::copyCellsTo( ScColumn& rCol, SCROW nRow ) const
break;
case element_type_formula:
{
- formula_block::const_iterator it = formula_block::begin(*itBlk->data);
- formula_block::const_iterator itEnd = formula_block::end(*itBlk->data);
+ formula_block::const_iterator it = formula_block::begin(*rBlk.data);
+ formula_block::const_iterator itEnd = formula_block::end(*rBlk.data);
std::vector<ScFormulaCell*> aVals;
- aVals.reserve(itBlk->size);
+ aVals.reserve(rBlk.size);
for (; it != itEnd; ++it)
{
const ScFormulaCell* p = *it;
@@ -212,10 +206,10 @@ void CellValues::copyCellsTo( ScColumn& rCol, SCROW nRow ) const
}
break;
default:
- itPos = rDest.set_empty(itPos, nCurRow, nCurRow+itBlk->size-1);
+ itPos = rDest.set_empty(itPos, nCurRow, nCurRow+rBlk.size-1);
}
- nCurRow += itBlk->size;
+ nCurRow += rBlk.size;
}
}
@@ -230,23 +224,22 @@ void CellValues::copyCellTextAttrsTo( ScColumn& rCol, SCROW nRow ) const
SCROW nCurRow = nRow;
CellTextAttrStoreType::iterator itPos = rDest.begin();
- CellTextAttrStoreType::const_iterator itBlk = rSrc.begin(), itBlkEnd = rSrc.end();
- for (; itBlk != itBlkEnd; ++itBlk)
+ for (const auto& rBlk : rSrc)
{
- switch (itBlk->type)
+ switch (rBlk.type)
{
case element_type_celltextattr:
{
- celltextattr_block::const_iterator it = celltextattr_block::begin(*itBlk->data);
- celltextattr_block::const_iterator itEnd = celltextattr_block::end(*itBlk->data);
+ celltextattr_block::const_iterator it = celltextattr_block::begin(*rBlk.data);
+ celltextattr_block::const_iterator itEnd = celltextattr_block::end(*rBlk.data);
itPos = rDest.set(itPos, nCurRow, it, itEnd);
}
break;
default:
- itPos = rDest.set_empty(itPos, nCurRow, nCurRow+itBlk->size-1);
+ itPos = rDest.set_empty(itPos, nCurRow, nCurRow+rBlk.size-1);
}
- nCurRow += itBlk->size;
+ nCurRow += rBlk.size;
}
}
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index a991cc05a79f..53e4d82eeb8b 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -374,9 +374,9 @@ ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc):
ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat):
ScColorFormat(pDoc)
{
- for(ScColorScaleEntries::const_iterator itr = rFormat.begin(); itr != rFormat.end(); ++itr)
+ for(const auto& rxEntry : rFormat)
{
- maColorScales.push_back(std::make_unique<ScColorScaleEntry>(pDoc, **itr));
+ maColorScales.push_back(std::make_unique<ScColorScaleEntry>(pDoc, *rxEntry));
}
}
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 2b0dc678a5fa..1c9174d5d5bd 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1753,9 +1753,8 @@ void ScColumn::CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const
CopyToClipHandler aFunc(*this, rDestCol, nullptr);
sc::CellStoreType::const_iterator itPos = maCells.begin();
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aRanges.begin(), itEnd = aRanges.end();
- for (; it != itEnd; ++it)
- itPos = sc::ParseBlock(itPos, maCells, aFunc, it->mnRow1, it->mnRow2);
+ for (const auto& rRange : aRanges)
+ itPos = sc::ParseBlock(itPos, maCells, aFunc, rRange.mnRow1, rRange.mnRow2);
rDestCol.CellStorageModified();
}
@@ -1856,14 +1855,13 @@ namespace {
void resetColumnPosition(sc::CellStoreType& rCells, SCCOL nCol)
{
- sc::CellStoreType::iterator it = rCells.begin(), itEnd = rCells.end();
- for (; it != itEnd; ++it)
+ for (auto& rCellItem : rCells)
{
- if (it->type != sc::element_type_formula)
+ if (rCellItem.type != sc::element_type_formula)
continue;
- sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data);
- sc::formula_block::iterator itCellEnd = sc::formula_block::end(*it->data);
+ sc::formula_block::iterator itCell = sc::formula_block::begin(*rCellItem.data);
+ sc::formula_block::iterator itCellEnd = sc::formula_block::end(*rCellItem.data);
for (; itCell != itCellEnd; ++itCell)
{
ScFormulaCell& rCell = **itCell;
@@ -2011,10 +2009,9 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
ScDocument* pDocument = GetDoc();
ScHint aHint(SfxHintId::ScDataChanged, ScAddress(nCol, 0, nTab));
ScAddress& rPos = aHint.GetAddress();
- sc::SingleColumnSpanSet::SpansType::const_iterator itRange = aRanges.begin(), itRangeEnd = aRanges.end();
- for (; itRange != itRangeEnd; ++itRange)
+ for (const auto& rRange : aRanges)
{
- for (SCROW nRow = itRange->mnRow1; nRow <= itRange->mnRow2; ++nRow)
+ for (SCROW nRow = rRange.mnRow1; nRow <= rRange.mnRow2; ++nRow)
{
rPos.SetRow(nRow);
pDocument->AreaBroadcast(aHint);
@@ -2814,9 +2811,8 @@ public:
sc::SingleColumnSpanSet::SpansType aSpans;
maValueRanges.getSpans(aSpans);
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
- for (; it != itEnd; ++it)
- rBroadcastSpans.set(nTab, nCol, it->mnRow1, it->mnRow2, true);
+ for (const auto& rSpan : aSpans)
+ rBroadcastSpans.set(nTab, nCol, rSpan.mnRow1, rSpan.mnRow2, true);
}
};
@@ -3434,11 +3430,8 @@ void ScColumn::TransferListeners(
// Re-register listeners with their destination broadcasters.
sc::BroadcasterStoreType::iterator itDestPos = rDestCol.maBroadcasters.begin();
- TransferListenersHandler::ListenerListType::iterator it = aListenerList.begin(), itEnd = aListenerList.end();
- for (; it != itEnd; ++it)
+ for (TransferListenersHandler::Entry& rEntry : aListenerList)
{
- TransferListenersHandler::Entry& rEntry = *it;
-
SCROW nDestRow = rEntry.mnRow + nRowDelta;
sc::BroadcasterStoreType::position_type aPos =
@@ -3460,10 +3453,8 @@ void ScColumn::TransferListeners(
}
// Transfer all listeners from the source to the destination.
- SvtBroadcaster::ListenersType::iterator it2 = rEntry.maListeners.begin(), it2End = rEntry.maListeners.end();
- for (; it2 != it2End; ++it2)
+ for (SvtListener* pLis : rEntry.maListeners)
{
- SvtListener* pLis = *it2;
pLis->StartListening(*pDestBrd);
}
}
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 8d2702980fba..09950a7825d7 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -61,6 +61,7 @@
#include <algorithm>
#include <memory>
+#include <numeric>
#include <math.h>
@@ -667,9 +668,8 @@ sal_uInt16 ScColumn::GetOptimalColWidth(
// Go though all non-empty cells within selection.
MaxStrLenFinder aFunc(*pDocument, nFormat);
sc::CellStoreType::const_iterator itPos = maCells.begin();
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aMarkedSpans.begin(), itEnd = aMarkedSpans.end();
- for (; it != itEnd; ++it)
- itPos = sc::ParseAllNonEmpty(itPos, maCells, it->mnRow1, it->mnRow2, aFunc);
+ for (const auto& rMarkedSpan : aMarkedSpans)
+ itPos = sc::ParseAllNonEmpty(itPos, maCells, rMarkedSpan.mnRow1, rMarkedSpan.mnRow2, aFunc);
aLongStr = aFunc.getMaxLenStr();
}
@@ -688,10 +688,9 @@ sal_uInt16 ScColumn::GetOptimalColWidth(
// Go though all non-empty cells within selection.
sc::CellStoreType::const_iterator itPos = maCells.begin();
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aMarkedSpans.begin(), itEnd = aMarkedSpans.end();
- for (; it != itEnd; ++it)
+ for (const auto& rMarkedSpan : aMarkedSpans)
{
- SCROW nRow1 = it->mnRow1, nRow2 = it->mnRow2;
+ SCROW nRow1 = rMarkedSpan.mnRow1, nRow2 = rMarkedSpan.mnRow2;
SCROW nRow = nRow1;
while (nRow <= nRow2)
{
@@ -879,11 +878,10 @@ void ScColumn::GetOptimalHeight(
// if cells are not handled individually below,
// check for cells with different script type
sc::CellTextAttrStoreType::iterator itAttr = maCellTextAttrs.begin();
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
sc::CellStoreType::iterator itCells = maCells.begin();
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
- for (SCROW nRow = it->mnRow1; nRow <= it->mnRow2; ++nRow)
+ for (SCROW nRow = rSpan.mnRow1; nRow <= rSpan.mnRow2; ++nRow)
{
SvtScriptType nScript = GetRangeScriptType(itAttr, nRow, nRow, itCells);
if (nScript == nDefScript)
@@ -919,10 +917,9 @@ void ScColumn::GetOptimalHeight(
{
ScNeededSizeOptions aOptions;
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
- for (SCROW nRow = it->mnRow1; nRow <= it->mnRow2; ++nRow)
+ for (SCROW nRow = rSpan.mnRow1; nRow <= rSpan.mnRow2; ++nRow)
{
// only calculate the cell height when it's used later (#37928#)
@@ -1038,9 +1035,8 @@ public:
{
svl::SharedStringPool& rPool = mpDoc->GetSharedStringPool();
sc::CellStoreType::iterator it = mrCells.begin();
- std::vector<StrEntry>::iterator itStr = maStrEntries.begin(), itStrEnd = maStrEntries.end();
- for (; itStr != itStrEnd; ++itStr)
- it = mrCells.set(it, itStr->mnRow, rPool.intern(itStr->maStr));
+ for (const auto& rStrEntry : maStrEntries)
+ it = mrCells.set(it, rStrEntry.mnRow, rPool.intern(rStrEntry.maStr));
}
};
@@ -1569,15 +1565,10 @@ void ScColumn::CellStorageModified()
}
// Make sure that these two containers are synchronized wrt empty segments.
- sc::CellStoreType::const_iterator itCell = maCells.begin();
- sc::CellTextAttrStoreType::const_iterator itAttr = maCellTextAttrs.begin();
-
+ auto lIsEmptyType = [](const auto& rElement) { return rElement.type == sc::element_type_empty; };
// Move to the first empty blocks.
- while (itCell != maCells.end() && itCell->type != sc::element_type_empty)
- ++itCell;
-
- while (itAttr != maCellTextAttrs.end() && itAttr->type != sc::element_type_empty)
- ++itAttr;
+ auto itCell = std::find_if(maCells.begin(), maCells.end(), lIsEmptyType);
+ auto itAttr = std::find_if(maCellTextAttrs.begin(), maCellTextAttrs.end(), lIsEmptyType);
while (itCell != maCells.end())
{
@@ -1594,12 +1585,10 @@ void ScColumn::CellStorageModified()
// Move to the next empty blocks.
++itCell;
- while (itCell != maCells.end() && itCell->type != sc::element_type_empty)
- ++itCell;
+ itCell = std::find_if(itCell, maCells.end(), lIsEmptyType);
++itAttr;
- while (itAttr != maCellTextAttrs.end() && itAttr->type != sc::element_type_empty)
- ++itAttr;
+ itAttr = std::find_if(itAttr, maCellTextAttrs.end(), lIsEmptyType);
}
#endif
}
@@ -1736,23 +1725,17 @@ void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& r
sc::CellTextAttrStoreType::const_iterator itBlk = maCellTextAttrs.begin(), itBlkEnd = maCellTextAttrs.end();
// Locate the top row position.
- size_t nOffsetInBlock = 0;
- size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
- for (; itBlk != itBlkEnd; ++itBlk)
- {
- nBlockEnd = nBlockStart + itBlk->size;
- if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
- {
- // Found.
- nOffsetInBlock = nRowPos - nBlockStart;
- break;
- }
- }
+ size_t nBlockStart = 0, nRowPos = static_cast<size_t>(nRow1);
+ itBlk = std::find_if(itBlk, itBlkEnd, [&nRowPos, &nBlockStart](const auto& rAttr) {
+ return nBlockStart <= nRowPos && nRowPos < nBlockStart + rAttr.size; });
if (itBlk == itBlkEnd)
// Specified range not found. Bail out.
return;
+ size_t nBlockEnd = nBlockStart + itBlk->size;
+ size_t nOffsetInBlock = nRowPos - nBlockStart;
+
nRowPos = static_cast<size_t>(nRow2); // End row position.
// Keep copying until we hit the end row position.
@@ -1878,13 +1861,12 @@ void ScColumn::DeleteBroadcasters( sc::ColumnBlockPosition& rBlockPos, SCROW nRo
void ScColumn::PrepareBroadcastersForDestruction()
{
- sc::BroadcasterStoreType::iterator itPos = maBroadcasters.begin(), itPosEnd = maBroadcasters.end();
- for (; itPos != itPosEnd; ++itPos)
+ for (auto& rBroadcaster : maBroadcasters)
{
- if (itPos->type == sc::element_type_broadcaster)
+ if (rBroadcaster.type == sc::element_type_broadcaster)
{
- sc::broadcaster_block::iterator it = sc::broadcaster_block::begin(*itPos->data);
- sc::broadcaster_block::iterator itEnd = sc::broadcaster_block::end(*itPos->data);
+ sc::broadcaster_block::iterator it = sc::broadcaster_block::begin(*rBroadcaster.data);
+ sc::broadcaster_block::iterator itEnd = sc::broadcaster_block::end(*rBroadcaster.data);
for (; it != itEnd; ++it)
(*it)->PrepareForDestruction();
}
@@ -1962,25 +1944,20 @@ void ScColumn::DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1,
bool ScColumn::HasCellNotes() const
{
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
- for (; it != itEnd; ++it)
- {
- if (it->type == sc::element_type_cellnote)
+ return std::any_of(maCellNotes.begin(), maCellNotes.end(),
+ [](const auto& rCellNote) {
// Having a cellnote block automatically means there is at least one cell note.
- return true;
- }
- return false;
+ return rCellNote.type == sc::element_type_cellnote; });
}
SCROW ScColumn::GetCellNotesMaxRow() const
{
// hypothesis : the column has cell notes (should be checked before)
SCROW maxRow = 0;
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
- for (; it != itEnd; ++it)
+ for (const auto& rCellNote : maCellNotes)
{
- if (it->type == sc::element_type_cellnote)
- maxRow = it->position + it->size -1;
+ if (rCellNote.type == sc::element_type_cellnote)
+ maxRow = rCellNote.position + rCellNote.size -1;
}
return maxRow;
}
@@ -1988,16 +1965,10 @@ SCROW ScColumn::GetCellNotesMinRow() const
{
// hypothesis : the column has cell notes (should be checked before)
SCROW minRow = 0;
- bool bFound = false;
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
- for (; it != itEnd && !bFound; ++it)
- {
- if (it->type == sc::element_type_cellnote)
- {
- bFound = true;
- minRow = it->position;
- }
- }
+ sc::CellNoteStoreType::const_iterator it = std::find_if(maCellNotes.begin(), maCellNotes.end(),
+ [](const auto& rCellNote) { return rCellNote.type == sc::element_type_cellnote; });
+ if (it != maCellNotes.end())
+ minRow = it->position;
return minRow;
}
@@ -3400,15 +3371,13 @@ void ScColumn::UpdateSelectionFunction(
sc::SingleColumnSpanSet::SpansType aSpans;
aSpanSet.getSpans(aSpans);
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
-
switch (rData.getFunc())
{
case SUBTOTAL_FUNC_SELECTION_COUNT:
{
// Simply count selected rows regardless of cell contents.
- for (; it != itEnd; ++it)
- rData.update( it->mnRow2 - it->mnRow1 + 1);
+ for (const auto& rSpan : aSpans)
+ rData.update( rSpan.mnRow2 - rSpan.mnRow1 + 1);
}
break;
case SUBTOTAL_FUNC_CNT2:
@@ -3416,10 +3385,10 @@ void ScColumn::UpdateSelectionFunction(
// We need to parse all non-empty cells.
sc::CellStoreType::const_iterator itCellPos = maCells.begin();
UpdateSubTotalHandler aFunc(rData);
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
itCellPos = sc::ParseAllNonEmpty(
- itCellPos, maCells, it->mnRow1, it->mnRow2, aFunc);
+ itCellPos, maCells, rSpan.mnRow1, rSpan.mnRow2, aFunc);
}
}
break;
@@ -3428,10 +3397,10 @@ void ScColumn::UpdateSelectionFunction(
// We need to parse only numeric values.
sc::CellStoreType::const_iterator itCellPos = maCells.begin();
UpdateSubTotalHandler aFunc(rData);
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
itCellPos = sc::ParseFormulaNumeric(
- itCellPos, maCells, it->mnRow1, it->mnRow2, aFunc);
+ itCellPos, maCells, rSpan.mnRow1, rSpan.mnRow2, aFunc);
}
}
}
@@ -3460,17 +3429,9 @@ public:
break;
case sc::element_type_formula:
{
- size_t nCount = 0;
// Each formula cell is worth its code length plus 5.
- sc::formula_block::const_iterator it = sc::formula_block::begin(*node.data);
- sc::formula_block::const_iterator itEnd = sc::formula_block::end(*node.data);
- for (; it != itEnd; ++it)
- {
- const ScFormulaCell* p = *it;
- nCount += 5 + p->GetCode()->GetCodeLen();
- }
-
- return nCount;
+ return std::accumulate(sc::formula_block::begin(*node.data), sc::formula_block::end(*node.data), size_t(0),
+ [](const size_t& rCount, const ScFormulaCell* p) { return rCount + 5 + p->GetCode()->GetCodeLen(); });
}
break;
case sc::element_type_edittext:
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 295c93d03c8a..a5a6a4a0993a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -77,10 +77,9 @@ void ScColumn::BroadcastCells( const std::vector<SCROW>& rRows, SfxHintId nHint
// Broadcast the changes.
ScDocument* pDocument = GetDoc();
ScHint aHint(nHint, ScAddress(nCol, 0, nTab));
- std::vector<SCROW>::const_iterator itRow = rRows.begin(), itRowEnd = rRows.end();
- for (; itRow != itRowEnd; ++itRow)
+ for (const auto& rRow : rRows)
{
- aHint.GetAddress().SetRow(*itRow);
+ aHint.GetAddress().SetRow(rRow);
pDocument->Broadcast(aHint);
}
}
@@ -746,9 +745,8 @@ void ScColumn::DeleteArea(
{
sc::SingleColumnSpanSet::SpansType aSpans;
aDeletedRows.getSpans(aSpans);
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
- for (; it != itEnd; ++it)
- pBroadcastSpans->set(nTab, nCol, it->mnRow1, it->mnRow2, true);
+ for (const auto& rSpan : aSpans)
+ pBroadcastSpans->set(nTab, nCol, rSpan.mnRow1, rSpan.mnRow2, true);
}
}
@@ -1523,39 +1521,38 @@ public:
sc::CellStoreType::iterator& itDestPos = mrBlockPos.miCellPos;
sc::CellTextAttrStoreType::iterator& itDestAttrPos = mrBlockPos.miCellTextAttrPos;
- sc::CellStoreType::iterator it = maNewCells.begin(), itEnd = maNewCells.end();
- for (; it != itEnd; ++it)
+ for (const auto& rNewCell : maNewCells)
{
bool bHasContent = true;
- size_t nDestRow = mnRowOffset + it->position;
+ size_t nDestRow = mnRowOffset + rNewCell.position;
- switch (it->type)
+ switch (rNewCell.type)
{
case sc::element_type_numeric:
{
- sc::numeric_block::iterator itData = sc::numeric_block::begin(*it->data);
- sc::numeric_block::iterator itDataEnd = sc::numeric_block::end(*it->data);
+ sc::numeric_block::iterator itData = sc::numeric_block::begin(*rNewCell.data);
+ sc::numeric_block::iterator itDataEnd = sc::numeric_block::end(*rNewCell.data);
itDestPos = mrDestColumn.GetCellStore().set(itDestPos, nDestRow, itData, itDataEnd);
}
break;
case sc::element_type_string:
{
- sc::string_block::iterator itData = sc::string_block::begin(*it->data);
- sc::string_block::iterator itDataEnd = sc::string_block::end(*it->data);
+ sc::string_block::iterator itData = sc::string_block::begin(*rNewCell.data);
+ sc::string_block::iterator itDataEnd = sc::string_block::end(*rNewCell.data);
itDestPos = rDestCells.set(itDestPos, nDestRow, itData, itDataEnd);
}
break;
case sc::element_type_edittext:
{
- sc::edittext_block::iterator itData = sc::edittext_block::begin(*it->data);
- sc::edittext_block::iterator itDataEnd = sc::edittext_block::end(*it->data);
+ sc::edittext_block::iterator itData = sc::edittext_block::begin(*rNewCell.data);
+ sc::edittext_block::iterator itDataEnd = sc::edittext_block::end(*rNewCell.data);
itDestPos = rDestCells.set(itDestPos, nDestRow, itData, itDataEnd);
}
break;
case sc::element_type_formula:
{
- sc::formula_block::iterator itData = sc::formula_block::begin(*it->data);
- sc::formula_block::iterator itDataEnd = sc::formula_block::end(*it->data);
+ sc::formula_block::iterator itData = sc::formula_block::begin(*rNewCell.data);
+ sc::formula_block::iterator itDataEnd = sc::formula_block::end(*rNewCell.data);
// Group new formula cells before inserting them.
sc::SharedFormulaUtil::groupFormulaCells(itData, itDataEnd);
@@ -1568,7 +1565,7 @@ public:
sc::SharedFormulaUtil::joinFormulaCellAbove(aPos);
// Merge with the next formula group (if any).
- size_t nNextRow = nDestRow + it->size;
+ size_t nNextRow = nDestRow + rNewCell.size;
if (ValidRow(nNextRow))
{
aPos = rDestCells.position(aPos.first, nNextRow);
@@ -1578,7 +1575,7 @@ public:
break;
case sc::element_type_empty:
{
- itDestPos = rDestCells.set_empty(itDestPos, nDestRow, nDestRow+it->size-1);
+ itDestPos = rDestCells.set_empty(itDestPos, nDestRow, nDestRow+rNewCell.size-1);
bHasContent = false;
}
break;
@@ -1589,11 +1586,11 @@ public:
sc::CellTextAttrStoreType& rDestAttrs = mrDestColumn.GetCellAttrStore();
if (bHasContent)
{
- std::vector<sc::CellTextAttr> aAttrs(it->size, sc::CellTextAttr());
+ std::vector<sc::CellTextAttr> aAttrs(rNewCell.size, sc::CellTextAttr());
itDestAttrPos = rDestAttrs.set(itDestAttrPos, nDestRow, aAttrs.begin(), aAttrs.end());
}
else
- itDestAttrPos = rDestAttrs.set_empty(itDestAttrPos, nDestRow, nDestRow+it->size-1);
+ itDestAttrPos = rDestAttrs.set_empty(itDestAttrPos, nDestRow, nDestRow+rNewCell.size-1);
}
maNewCells.release();
@@ -2412,10 +2409,8 @@ public:
sc::ColumnBlockPosition aBlockPos;
rColumn.InitBlockPosition(aBlockPos);
- EntriesType::iterator it = maEntries.begin(), itEnd = maEntries.end();
- for (; it != itEnd; ++it)
+ for (const Entry& r : maEntries)
{
- Entry& r = *it;
switch (r.maValue.meType)
{
case CELLTYPE_VALUE:
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 4e04c3cca55b..11a06090ad9c 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -33,6 +33,7 @@
#include <svl/sharedstringpool.hxx>
#include <sal/log.hxx>
+#include <numeric>
#include <vector>
#include <cassert>
@@ -118,10 +119,8 @@ void ScColumn::DeleteBeforeCopyFromClip(
bool bContinue = true;
while (bContinue)
{
- sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
- for (; it != itEnd && bContinue; ++it)
+ for (const sc::RowSpan& r : aSpans)
{
- const sc::RowSpan& r = *it;
SCROW nDestRow1 = r.mnRow1 + nDestOffset;
SCROW nDestRow2 = r.mnRow2 + nDestOffset;
@@ -129,7 +128,7 @@ void ScColumn::DeleteBeforeCopyFromClip(
{
// We're done.
bContinue = false;
- continue;
+ break;
}
if (nDestRow2 > aRange.mnRow2)
@@ -140,6 +139,9 @@ void ScColumn::DeleteBeforeCopyFromClip(
}
aDestSpans.emplace_back(nDestRow1, nDestRow2);
+
+ if (!bContinue)
+ break;
}
nDestOffset += nClipRowLen;
@@ -149,11 +151,10 @@ void ScColumn::DeleteBeforeCopyFromClip(
sc::ColumnBlockPosition aBlockPos;
InitBlockPosition(aBlockPos);
- std::vector<sc::RowSpan>::const_iterator it = aDestSpans.begin(), itEnd = aDestSpans.end();
- for (; it != itEnd; ++it)
+ for (const auto& rDestSpan : aDestSpans)
{
- SCROW nRow1 = it->mnRow1;
- SCROW nRow2 = it->mnRow2;
+ SCROW nRow1 = rDestSpan.mnRow1;
+ SCROW nRow2 = rDestSpan.mnRow2;
if (nDelFlag & InsertDeleteFlags::CONTENTS)
{
@@ -501,12 +502,11 @@ void ScColumn::SwapNonEmpty(
// Detach formula cells within the spans (if any).
EndListeningHandler aEndLisFunc(rEndCxt);
- std::vector<sc::CellValueSpan>::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
sc::CellStoreType::iterator itPos = maCells.begin();
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
- SCROW nRow1 = it->mnRow1;
- SCROW nRow2 = it->mnRow2;
+ SCROW nRow1 = rSpan.mnRow1;
+ SCROW nRow2 = rSpan.mnRow2;
itPos = sc::ProcessFormula(itPos, maCells, nRow1, nRow2, aEndLisFunc);
}
@@ -515,12 +515,11 @@ void ScColumn::SwapNonEmpty(
// Attach formula cells within the spans (if any).
StartListeningHandler aStartLisFunc(rStartCxt);
- it = aSpans.begin();
itPos = maCells.begin();
- for (; it != itEnd; ++it)
+ for (const auto& rSpan : aSpans)
{
- SCROW nRow1 = it->mnRow1;
- SCROW nRow2 = it->mnRow2;
+ SCROW nRow1 = rSpan.mnRow1;
+ SCROW nRow2 = rSpan.mnRow2;
itPos = sc::ProcessFormula(itPos, maCells, nRow1, nRow2, aStartLisFunc);
}
@@ -529,9 +528,8 @@ void ScColumn::SwapNonEmpty(
void ScColumn::DeleteRanges( const std::vector<sc::RowSpan>& rRanges, InsertDeleteFlags nDelFlag )
{
- std::vector<sc::RowSpan>::const_iterator itSpan = rRanges.begin(), itSpanEnd = rRanges.end();
- for (; itSpan != itSpanEnd; ++itSpan)
- DeleteArea(itSpan->mnRow1, itSpan->mnRow2, nDelFlag, false/*bBroadcast*/);
+ for (const auto& rSpan : rRanges)
+ DeleteArea(rSpan.mnRow1, rSpan.mnRow2, nDelFlag, false/*bBroadcast*/);
}
void ScColumn::CloneFormulaCell(
@@ -553,10 +551,9 @@ void ScColumn::CloneFormulaCell(
ScDocument* pDocument = GetDoc();
std::vector<ScFormulaCell*> aFormulas;
- std::vector<sc::RowSpan>::const_iterator itSpan = rRanges.begin(), itSpanEnd = rRanges.end();
- for (; itSpan != itSpanEnd; ++itSpan)
+ for (const auto& rSpan : rRanges)
{
- SCROW nRow1 = itSpan->mnRow1, nRow2 = itSpan->mnRow2;
+ SCROW nRow1 = rSpan.mnRow1, nRow2 = rSpan.mnRow2;
size_t nLen = nRow2 - nRow1 + 1;
assert(nLen > 0);
aFormulas.clear();
@@ -623,17 +620,12 @@ std::unique_ptr<ScPostIt> ScColumn::ReleaseNote( SCROW nRow )
size_t ScColumn::GetNoteCount() const
{
- size_t nCount = 0;
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
- for (; it != itEnd; ++it)
- {
- if (it->type != sc::element_type_cellnote)
- continue;
-
- nCount += it->size;
- }
-
- return nCount;
+ return std::accumulate(maCellNotes.begin(), maCellNotes.end(), size_t(0),
+ [](const size_t& rCount, const auto& rCellNote) {
+ if (rCellNote.type != sc::element_type_cellnote)
+ return rCount;
+ return rCount + rCellNote.size;
+ });
}
namespace {
@@ -688,23 +680,21 @@ SCROW ScColumn::GetNotePosition( size_t nIndex ) const
{
// Return the row position of the nth note in the column.
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
-
size_t nCount = 0; // Number of notes encountered so far.
- for (; it != itEnd; ++it)
+ for (const auto& rCellNote : maCellNotes)
{
- if (it->type != sc::element_type_cellnote)
+ if (rCellNote.type != sc::element_type_cellnote)
// Skip the empty blocks.
continue;
- if (nIndex < nCount + it->size)
+ if (nIndex < nCount + rCellNote.size)
{
// Index falls within this block.
size_t nOffset = nIndex - nCount;
- return it->position + nOffset;
+ return rCellNote.position + nOffset;
}
- nCount += it->size;
+ nCount += rCellNote.size;
}
return -1;
@@ -1972,9 +1962,9 @@ void ScColumn::RestoreFromCache(SvStream& rStrm)
{
// nDataSize double values
std::vector<double> aValues(nDataSize);
- for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow)
+ for (auto& rValue : aValues)
{
- rStrm.ReadDouble(aValues[nRow]);
+ rStrm.ReadDouble(rValue);
}
maCells.set(nStartRow, aValues.begin(), aValues.end());
}
@@ -1983,7 +1973,7 @@ void ScColumn::RestoreFromCache(SvStream& rStrm)
{
std::vector<svl::SharedString> aStrings(nDataSize);
svl::SharedStringPool& rPool = pDocument->GetSharedStringPool();
- for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow)
+ for (auto& rString : aStrings)
{
sal_Int32 nStrLength = 0;
rStrm.ReadInt32(nStrLength);
@@ -1991,7 +1981,7 @@ void ScColumn::RestoreFromCache(SvStream& rStrm)
rStrm.ReadBytes(pStr.get(), nStrLength);
OString aOStr(pStr.get(), nStrLength);
OUString aStr = OStringToOUString(aOStr, RTL_TEXTENCODING_UTF8);
- aStrings[nRow] = rPool.intern(aStr);
+ rString = rPool.intern(aStr);
}
maCells.set(nStartRow, aStrings.begin(), aStrings.end());
diff --git a/sc/source/core/data/columnspanset.cxx b/sc/source/core/data/columnspanset.cxx
index 55b0f3e2ad01..1098ce30447e 100644
--- a/sc/source/core/data/columnspanset.cxx
+++ b/sc/source/core/data/columnspanset.cxx
@@ -114,9 +114,8 @@ void ColumnSpanSet::set( SCTAB nTab, SCCOL nCol, const SingleColumnSpanSet& rSin
{
SingleColumnSpanSet::SpansType aSpans;
rSingleSet.getSpans(aSpans);
- SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
- for (; it != itEnd; ++it)
- set(nTab, nCol, it->mnRow1, it->mnRow2, bVal);
+ for (const auto& rSpan : aSpans)
+ set(nTab, nCol, rSpan.mnRow1, rSpan.mnRow2, bVal);
}
void ColumnSpanSet::scan(
@@ -243,12 +242,11 @@ SingleColumnSpanSet::SingleColumnSpanSet() : maSpans(0, MAXROWCOUNT, false) {}
void SingleColumnSpanSet::scan(const ScColumn& rColumn)
{
const CellStoreType& rCells = rColumn.maCells;
- sc::CellStoreType::const_iterator it = rCells.begin(), itEnd = rCells.end();
SCROW nCurRow = 0;
- for (;it != itEnd; ++it)
+ for (const auto& rCell : rCells)
{
- SCROW nEndRow = nCurRow + it->size; // Last row of current block plus 1.
- if (it->type != sc::element_type_empty)
+ SCROW nEndRow = nCurRow + rCell.size; // Last row of current block plus 1.
+ if (rCell.type != sc::element_type_empty)
maSpans.insert_back(nCurRow, nEndRow, true);
nCurRow = nEndRow;
@@ -307,10 +305,9 @@ void SingleColumnSpanSet::getRows(std::vector<SCROW> &rRows) const
SpansType aRanges;
getSpans(aRanges);
- SpansType::const_iterator it = aRanges.begin(), itEnd = aRanges.end();
- for (; it != itEnd; ++it)
+ for (const auto& rRange : aRanges)
{
- for (SCROW nRow = it->mnRow1; nRow <= it->mnRow2; ++nRow)
+ for (SCROW nRow = rRange.mnRow1; nRow <= rRange.mnRow2; ++nRow)
aRows.push_back(nRow);
}
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index d5bb968d5d50..81160bae754d 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -43,6 +43,7 @@
#include <svl/sharedstring.hxx>
#include <svl/sharedstringpool.hxx>
#include <memory>
+#include <numeric>
using namespace formula;
@@ -859,14 +860,13 @@ bool ScConditionEntry::IsBottomNElement( double nArg ) const
return true;
size_t nCells = 0;
- for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(),
- itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr)
+ for(const auto& [rVal, rCount] : mpCache->maValues)
{
if(nCells >= nVal1)
return false;
- if(itr->first >= nArg)
+ if(rVal >= nArg)
return true;
- nCells += itr->second;
+ nCells += rCount;
}
return true;
@@ -897,14 +897,13 @@ bool ScConditionEntry::IsBottomNPercent( double nArg ) const
size_t nCells = 0;
size_t nLimitCells = static_cast<size_t>(mpCache->nValueItems*nVal1/100);
- for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(),
- itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr)
+ for(const auto& [rVal, rCount] : mpCache->maValues)
{
if(nCells >= nLimitCells)
return false;
- if(itr->first >= nArg)
+ if(rVal >= nArg)
return true;
- nCells += itr->second;
+ nCells += rCount;
}
return true;
@@ -914,12 +913,9 @@ bool ScConditionEntry::IsBelowAverage( double nArg, bool bEqual ) const
{
FillCache();
- double nSum = 0;
- for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(),
- itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr)
- {
- nSum += itr->first * itr->second;
- }
+ double nSum = std::accumulate(mpCache->maValues.begin(), mpCache->maValues.end(), double(0),
+ [](const double& rSum, const ScConditionEntryCache::ValueCacheType::value_type& rEntry) {
+ return rSum + rEntry.first * rEntry.second; });
if(bEqual)
return (nArg <= nSum/mpCache->nValueItems);
@@ -931,12 +927,9 @@ bool ScConditionEntry::IsAboveAverage( double nArg, bool bEqual ) const
{
FillCache();
- double nSum = 0;
- for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(),
- itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr)
- {
- nSum += itr->first * itr->second;
- }
+ double nSum = std::accumulate(mpCache->maValues.begin(), mpCache->maValues.end(), double(0),
+ [](const double& rSum, const ScConditionEntryCache::ValueCacheType::value_type& rEntry) {
+ return rSum + rEntry.first * rEntry.second; });
if(bEqual)
return (nArg >= nSum/mpCache->nValueItems);
@@ -1711,9 +1704,9 @@ std::unique_ptr<ScConditionalFormat> ScConditionalFormat::Clone(ScDocument* pNew
std::unique_ptr<ScConditionalFormat> pNew(new ScConditionalFormat(nKey, pNewDoc));
pNew->SetRange( maRanges ); // prerequisite for listeners
- for (auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for (const auto& rxEntry : maEntries)
{
- ScFormatEntry* pNewEntry = (*itr)->Clone(pNewDoc);
+ ScFormatEntry* pNewEntry = rxEntry->Clone(pNewDoc);
pNew->maEntries.push_back( std::unique_ptr<ScFormatEntry>(pNewEntry) );
pNewEntry->SetParent(pNew.get());
}
@@ -1790,17 +1783,17 @@ const ScFormatEntry* ScConditionalFormat::GetEntry( sal_uInt16 nPos ) const
const OUString& ScConditionalFormat::GetCellStyle( ScRefCellValue& rCell, const ScAddress& rPos ) const
{
- for (auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for (const auto& rxEntry : maEntries)
{
- if((*itr)->GetType() == ScFormatEntry::Type::Condition)
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition)
{
- const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(**itr);
+ const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*rxEntry);
if (rEntry.IsCellValid(rCell, rPos))
return rEntry.GetStyle();
}
- else if((*itr)->GetType() == ScFormatEntry::Type::Date)
+ else if(rxEntry->GetType() == ScFormatEntry::Type::Date)
{
- const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(**itr);
+ const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(*rxEntry);
if (rEntry.IsValid( rPos ))
return rEntry.GetStyleName();
}
@@ -1812,32 +1805,32 @@ const OUString& ScConditionalFormat::GetCellStyle( ScRefCellValue& rCell, const
ScCondFormatData ScConditionalFormat::GetData( ScRefCellValue& rCell, const ScAddress& rPos ) const
{
ScCondFormatData aData;
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for(const auto& rxEntry : maEntries)
{
- if((*itr)->GetType() == ScFormatEntry::Type::Condition && aData.aStyleName.isEmpty())
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition && aData.aStyleName.isEmpty())
{
- const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(**itr);
+ const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*rxEntry);
if (rEntry.IsCellValid(rCell, rPos))
aData.aStyleName = rEntry.GetStyle();
}
- else if((*itr)->GetType() == ScFormatEntry::Type::Colorscale && !aData.mxColorScale)
+ else if(rxEntry->GetType() == ScFormatEntry::Type::Colorscale && !aData.mxColorScale)
{
- const ScColorScaleFormat& rEntry = static_cast<const ScColorScaleFormat&>(**itr);
+ const ScColorScaleFormat& rEntry = static_cast<const ScColorScaleFormat&>(*rxEntry);
aData.mxColorScale = rEntry.GetColor(rPos);
}
- else if((*itr)->GetType() == ScFormatEntry::Type::Databar && !aData.pDataBar)
+ else if(rxEntry->GetType() == ScFormatEntry::Type::Databar && !aData.pDataBar)
{
- const ScDataBarFormat& rEntry = static_cast<const ScDataBarFormat&>(**itr);
+ const ScDataBarFormat& rEntry = static_cast<const ScDataBarFormat&>(*rxEntry);
aData.pDataBar = rEntry.GetDataBarInfo(rPos);
}
- else if((*itr)->GetType() == ScFormatEntry::Type::Iconset && !aData.pIconSet)
+ else if(rxEntry->GetType() == ScFormatEntry::Type::Iconset && !aData.pIconSet)
{
- const ScIconSetFormat& rEntry = static_cast<const ScIconSetFormat&>(**itr);
+ const ScIconSetFormat& rEntry = static_cast<const ScIconSetFormat&>(*rxEntry);
aData.pIconSet = rEntry.GetIconSetInfo(rPos);
}
- else if((*itr)->GetType() == ScFormatEntry::Type::Date && aData.aStyleName.isEmpty())
+ else if(rxEntry->GetType() == ScFormatEntry::Type::Date && aData.aStyleName.isEmpty())
{
- const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(**itr);
+ const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(*rxEntry);
if ( rEntry.IsValid( rPos ) )
aData.aStyleName = rEntry.GetStyleName();
}
@@ -1853,22 +1846,22 @@ void ScConditionalFormat::DoRepaint()
void ScConditionalFormat::CompileAll()
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
- if((*itr)->GetType() == ScFormatEntry::Type::Condition)
- static_cast<ScCondFormatEntry&>(**itr).CompileAll();
+ for(auto& rxEntry : maEntries)
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition)
+ static_cast<ScCondFormatEntry&>(*rxEntry).CompileAll();
}
void ScConditionalFormat::CompileXML()
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
- if((*itr)->GetType() == ScFormatEntry::Type::Condition)
- static_cast<ScCondFormatEntry&>(**itr).CompileXML();
+ for(auto& rxEntry : maEntries)
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition)
+ static_cast<ScCondFormatEntry&>(*rxEntry).CompileXML();
}
void ScConditionalFormat::UpdateReference( sc::RefUpdateContext& rCxt, bool bCopyAsMove )
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
- (*itr)->UpdateReference(rCxt);
+ for(auto& rxEntry : maEntries)
+ rxEntry->UpdateReference(rCxt);
if (rCxt.meMode == URM_COPY && bCopyAsMove)
maRanges.UpdateReference(URM_MOVE, pDoc, rCxt.maRange, rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
@@ -1902,8 +1895,8 @@ void ScConditionalFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
rRange.aEnd.IncTab(rCxt.mnSheets);
}
- for (auto it = maEntries.cbegin(); it != maEntries.cend(); ++it)
- (*it)->UpdateInsertTab(rCxt);
+ for (auto& rxEntry : maEntries)
+ rxEntry->UpdateInsertTab(rCxt);
}
void ScConditionalFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
@@ -1931,8 +1924,8 @@ void ScConditionalFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
rRange.aEnd.IncTab(-1*rCxt.mnSheets);
}
- for (auto it = maEntries.cbegin(); it != maEntries.cend(); ++it)
- (*it)->UpdateDeleteTab(rCxt);
+ for (auto& rxEntry : maEntries)
+ rxEntry->UpdateDeleteTab(rCxt);
}
void ScConditionalFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
@@ -1968,8 +1961,8 @@ void ScConditionalFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
}
}
- for (auto it = maEntries.cbegin(); it != maEntries.cend(); ++it)
- (*it)->UpdateMoveTab(rCxt);
+ for (auto& rxEntry : maEntries)
+ rxEntry->UpdateMoveTab(rCxt);
}
void ScConditionalFormat::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
@@ -1983,10 +1976,10 @@ void ScConditionalFormat::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCR
void ScConditionalFormat::RenameCellStyle(const OUString& rOld, const OUString& rNew)
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
- if((*itr)->GetType() == ScFormatEntry::Type::Condition)
+ for(const auto& rxEntry : maEntries)
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition)
{
- ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(**itr);
+ ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(*rxEntry);
if(rFormat.GetStyle() == rOld)
rFormat.UpdateStyleName( rNew );
}
@@ -1995,11 +1988,13 @@ void ScConditionalFormat::RenameCellStyle(const OUString& rOld, const OUString&
bool ScConditionalFormat::MarkUsedExternalReferences() const
{
bool bAllMarked = false;
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend() && !bAllMarked; ++itr)
- if((*itr)->GetType() == ScFormatEntry::Type::Condition)
+ for(const auto& rxEntry : maEntries)
+ if(rxEntry->GetType() == ScFormatEntry::Type::Condition)
{
- const ScCondFormatEntry& rFormat = static_cast<const ScCondFormatEntry&>(**itr);
+ const ScCondFormatEntry& rFormat = static_cast<const ScCondFormatEntry&>(*rxEntry);
bAllMarked = rFormat.MarkUsedExternalReferences();
+ if (bAllMarked)
+ break;
}
return bAllMarked;
@@ -2007,27 +2002,27 @@ bool ScConditionalFormat::MarkUsedExternalReferences() const
void ScConditionalFormat::startRendering()
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for(auto& rxEntry : maEntries)
{
- (*itr)->startRendering();
+ rxEntry->startRendering();
}
}
void ScConditionalFormat::endRendering()
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for(auto& rxEntry : maEntries)
{
- (*itr)->endRendering();
+ rxEntry->endRendering();
}
}
void ScConditionalFormat::CalcAll()
{
- for(auto itr = maEntries.cbegin(); itr != maEntries.cend(); ++itr)
+ for(const auto& rxEntry : maEntries)
{
- if ((*itr)->GetType() == ScFormatEntry::Type::Condition)
+ if (rxEntry->GetType() == ScFormatEntry::Type::Condition)
{
- ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(**itr);
+ ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(*rxEntry);
rFormat.CalcAll();
}
}
@@ -2035,14 +2030,14 @@ void ScConditionalFormat::CalcAll()
ScConditionalFormatList::ScConditionalFormatList(const ScConditionalFormatList& rList)
{
- for(const_iterator itr = rList.begin(); itr != rList.end(); ++itr)
- InsertNew( (*itr)->Clone() );
+ for(const auto& rxFormat : rList)
+ InsertNew( rxFormat->Clone() );
}
ScConditionalFormatList::ScConditionalFormatList(ScDocument* pDoc, const ScConditionalFormatList& rList)
{
- for(const_iterator itr = rList.begin(); itr != rList.end(); ++itr)
- InsertNew( (*itr)->Clone(pDoc) );
+ for(const auto& rxFormat : rList)
+ InsertNew( rxFormat->Clone(pDoc) );
}
void ScConditionalFormatList::InsertNew( std::unique_ptr<ScConditionalFormat> pNew )
@@ -2053,9 +2048,10 @@ void ScConditionalFormatList::InsertNew( std::unique_ptr<ScConditionalFormat> pN
ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey )
{
//FIXME: Binary search
- for( iterator itr = begin(); itr != end(); ++itr)
- if ((*itr)->GetKey() == nKey)
- return itr->get();
+ iterator itr = std::find_if(begin(), end(),
+ [&nKey](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nKey; });
+ if (itr != end())
+ return itr->get();
SAL_WARN("sc", "ScConditionalFormatList: Entry not found");
return nullptr;
@@ -2064,9 +2060,10 @@ ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey )
const ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey ) const
{
//FIXME: Binary search
- for ( const_iterator itr = begin(); itr != end(); ++itr)
- if ((*itr)->GetKey() == nKey)
- return itr->get();
+ const_iterator itr = std::find_if(begin(), end(),
+ [&nKey](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nKey; });
+ if (itr != end())
+ return itr->get();
SAL_WARN("sc", "ScConditionalFormatList: Entry not found");
return nullptr;
@@ -2174,8 +2171,8 @@ bool ScConditionalFormatList::CheckAllEntries(const Link<ScConditionalFormat*,vo
void ScConditionalFormatList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
{
- for( iterator itr = begin(); itr != end(); ++itr)
- (*itr)->DeleteArea( nCol1, nRow1, nCol2, nRow2 );
+ for (auto& rxFormat : m_ConditionalFormats)
+ rxFormat->DeleteArea( nCol1, nRow1, nCol2, nRow2 );
CheckAllEntries();
}
@@ -2248,14 +2245,10 @@ bool ScConditionalFormatList::empty() const
void ScConditionalFormatList::erase( sal_uLong nIndex )
{
- for( iterator itr = begin(); itr != end(); ++itr )
- {
- if( (*itr)->GetKey() == nIndex )
- {
- m_ConditionalFormats.erase(itr);
- break;
- }
- }
+ iterator itr = std::find_if(begin(), end(),
+ [&nIndex](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nIndex; });
+ if (itr != end())
+ m_ConditionalFormats.erase(itr);
}
void ScConditionalFormatList::startRendering()
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 38b583fb02cf..5031caa5666b 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -2079,11 +2079,8 @@ SCROW ScHorizontalCellIterator::FindNextNonEmptyRow()
{
size_t nNextRow = MAXROW+1;
- for (std::vector<ColParam>::iterator it = maColPositions.begin();
- it != maColPositions.end(); ++it)
+ for (const ColParam& r : maColPositions)
{
- ColParam& r = *it;
-
assert(static_cast<size_t>(mnRow) <= r.maPos->position);
nNextRow = std::min (nNextRow, static_cast<size_t>(r.maPos->position));
}
@@ -2533,15 +2530,14 @@ void ScDocRowHeightUpdater::update()
}
sal_uLong nCellCount = 0;
- vector<TabRanges>::const_iterator itr = mpTabRangesArray->begin(), itrEnd = mpTabRangesArray->end();
- for (; itr != itrEnd; ++itr)
+ for (const auto& rTabRanges : *mpTabRangesArray)
{
- const SCTAB nTab = itr->mnTab;
+ const SCTAB nTab = rTabRanges.mnTab;
if (!ValidTab(nTab) || nTab >= mrDoc.GetTableCount() || !mrDoc.maTabs[nTab])
continue;
ScFlatBoolRowSegments::RangeData aData;
- ScFlatBoolRowSegments::RangeIterator aRangeItr(*itr->mpRanges);
+ ScFlatBoolRowSegments::RangeIterator aRangeItr(*rTabRanges.mpRanges);
for (bool bFound = aRangeItr.getFirst(aData); bFound; bFound = aRangeItr.getNext(aData))
{
if (!aData.mbValue)
@@ -2554,17 +2550,16 @@ void ScDocRowHeightUpdater::update()
ScProgress aProgress(mrDoc.GetDocumentShell(), ScResId(STR_PROGRESS_HEIGHTING), nCellCount, true);
Fraction aZoom(1, 1);
- itr = mpTabRangesArray->begin();
sal_uLong nProgressStart = 0;
- for (; itr != itrEnd; ++itr)
+ for (const auto& rTabRanges : *mpTabRangesArray)
{
- const SCTAB nTab = itr->mnTab;
+ const SCTAB nTab = rTabRanges.mnTab;
if (!ValidTab(nTab) || nTab >= mrDoc.GetTableCount() || !mrDoc.maTabs[nTab])
continue;
sc::RowHeightContext aCxt(mfPPTX, mfPPTY, aZoom, aZoom, mpOutDev);
ScFlatBoolRowSegments::RangeData aData;
- ScFlatBoolRowSegments::RangeIterator aRangeItr(*itr->mpRanges);
+ ScFlatBoolRowSegments::RangeIterator aRangeItr(*rTabRanges.mpRanges);
for (bool bFound = aRangeItr.getFirst(aData); bFound; bFound = aRangeItr.getNext(aData))
{
if (!aData.mbValue)
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 7dbab52dd3f0..50ccf9735889 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -703,14 +703,12 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
ScTableUniquePtr pSaveTab = std::move(maTabs[nOldPos]);
maTabs.erase(maTabs.begin()+nOldPos);
maTabs.insert(maTabs.begin()+nNewPos, std::move(pSaveTab));
- TableContainer::iterator it = maTabs.begin();
for (SCTAB i = 0; i < nTabCount; i++)
if (maTabs[i])
maTabs[i]->UpdateMoveTab(aCxt, i, pProgress);
- it = maTabs.begin();
- for (; it != maTabs.end(); ++it)
- if (*it)
- (*it)->UpdateCompile();
+ for (auto& rxTab : maTabs)
+ if (rxTab)
+ rxTab->UpdateCompile();
SetNoListening( false );
StartAllListeners();
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 633ca5835113..8f68d5015940 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -120,21 +120,20 @@ void ScDocument::GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rNames) const
void ScDocument::SetAllRangeNames(const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap)
{
- auto itr = rRangeMap.begin(), itrEnd = rRangeMap.end();
- for (; itr!=itrEnd; ++itr)
+ for (const auto& [rName, rxRangeName] : rRangeMap)
{
- if (itr->first == STR_GLOBAL_RANGE_NAME)
+ if (rName == STR_GLOBAL_RANGE_NAME)
{
pRangeName.reset();
- const ScRangeName *const pName = itr->second.get();
+ const ScRangeName *const pName = rxRangeName.get();
if (!pName->empty())
pRangeName.reset( new ScRangeName( *pName ) );
}
else
{
- const ScRangeName *const pName = itr->second.get();
+ const ScRangeName *const pName = rxRangeName.get();
SCTAB nTab;
- bool bFound = GetTable(itr->first, nTab);
+ bool bFound = GetTable(rName, nTab);
assert(bFound); (void)bFound; // fouled up?
if (pName->empty())
SetRangeName( nTab, nullptr );
@@ -205,11 +204,9 @@ bool ScDocument::IsAddressInRangeName( RangeNameScope eScope, const ScAddress& r
else
pRangeNames= GetRangeName(rAddress.Tab());
- ScRangeName::iterator itrBegin = pRangeNames->begin(), itrEnd = pRangeNames->end();
-
- for (ScRangeName::iterator itr = itrBegin; itr != itrEnd; ++itr)
+ for (auto& rEntry : *pRangeNames)
{
- if (itr->second->IsValidReference(aNameRange))
+ if (rEntry.second->IsValidReference(aNameRange))
{
if (aNameRange.In(rAddress))
return true;
@@ -265,10 +262,9 @@ void ScDocument::SetDBCollection( std::unique_ptr<ScDBCollection> pNewDBCollecti
// start position is also compared, so bRemoveAutoFilter must not be set from ref-undo!
ScDBCollection::NamedDBs& rNamedDBs = pDBCollection->getNamedDBs();
- ScDBCollection::NamedDBs::const_iterator itr = rNamedDBs.begin(), itrEnd = rNamedDBs.end();
- for (; itr != itrEnd; ++itr)
+ for (const auto& rxNamedDB : rNamedDBs)
{
- const ScDBData& rOldData = **itr;
+ const ScDBData& rOldData = *rxNamedDB;
if (!rOldData.HasAutoFilter())
continue;
@@ -1143,12 +1139,15 @@ void ScDocument::Fill(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScProg
PutInOrder( nCol1, nCol2 );
PutInOrder( nRow1, nRow2 );
SCTAB nMax = maTabs.size();
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->Fill(nCol1, nRow1, nCol2, nRow2,
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->Fill(nCol1, nRow1, nCol2, nRow2,
nFillCount, eFillDir, eFillCmd, eFillDateCmd,
nStepValue, nMaxValue, pProgress);
+ }
}
OUString ScDocument::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW nEndY )
@@ -1166,10 +1165,13 @@ void ScDocument::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SC
PutInOrder( nStartCol, nEndCol );
PutInOrder( nStartRow, nEndRow );
SCTAB nMax = maTabs.size();
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, nFormatNo );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, nFormatNo );
+ }
}
void ScDocument::GetAutoFormatData(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
@@ -1291,15 +1293,18 @@ bool ScDocument::SearchAndReplace(
nCommand == SvxSearchCmd::REPLACE_ALL )
{
SCTAB nMax = maTabs.size();
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
+ for (const auto& rMarkedTab : rMark)
+ {
+ if (rMarkedTab >= nMax)
+ break;
+ if (maTabs[rMarkedTab])
{
nCol = 0;
nRow = 0;
- bFound |= maTabs[*itr]->SearchAndReplace(
+ bFound |= maTabs[rMarkedTab]->SearchAndReplace(
rSearchItem, nCol, nRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
}
+ }
// Mark is set completely inside already
}
@@ -1621,18 +1626,16 @@ void ScDocument::GetFormulaEntries( ScTypedCaseStrSet& rStrings )
// Range name
if ( pRangeName )
{
- ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
- for (; itr != itrEnd; ++itr)
- rStrings.insert(ScTypedStrData(itr->second->GetName(), 0.0, ScTypedStrData::Name));
+ for (const auto& rEntry : *pRangeName)
+ rStrings.insert(ScTypedStrData(rEntry.second->GetName(), 0.0, ScTypedStrData::Name));
}
// Database collection
if ( pDBCollection )
{
const ScDBCollection::NamedDBs& rDBs = pDBCollection->getNamedDBs();
- ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
- for (; itr != itrEnd; ++itr)
- rStrings.insert(ScTypedStrData((*itr)->GetName(), 0.0, ScTypedStrData::DbName));
+ for (const auto& rxDB : rDBs)
+ rStrings.insert(ScTypedStrData(rxDB->GetName(), 0.0, ScTypedStrData::DbName));
}
// Content of name ranges
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index e5a759cea8d3..d99561497257 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -283,24 +283,26 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
else
pCell = new ScFormulaCell( this, aPos, rFormula, eGram, ScMatrixMode::Formula );
pCell->SetMatColsRows( nCol2 - nCol1 + 1, nRow2 - nRow1 + 1 );
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- for (; itr != itrEnd && *itr < nMax; ++itr)
+ for (const auto& rTab : rMark)
{
- if (!maTabs[*itr])
+ if (rTab >= nMax)
+ break;
+
+ if (!maTabs[rTab])
continue;
- if (*itr == nTab1)
+ if (rTab == nTab1)
{
- pCell = maTabs[*itr]->SetFormulaCell(nCol1, nRow1, pCell);
+ pCell = maTabs[rTab]->SetFormulaCell(nCol1, nRow1, pCell);
if (!pCell) //NULL if nCol1/nRow1 is invalid, which it can't be here
break;
}
else
- maTabs[*itr]->SetFormulaCell(
+ maTabs[rTab]->SetFormulaCell(
nCol1, nRow1,
new ScFormulaCell(
- *pCell, *this, ScAddress(nCol1, nRow1, *itr), ScCloneFlags::StartListening));
+ *pCell, *this, ScAddress(nCol1, nRow1, rTab), ScCloneFlags::StartListening));
}
ScAddress aBasePos(nCol1, nRow1, nTab1);
@@ -314,10 +316,11 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
ScTokenArray aArr; // consists only of one single reference token.
formula::FormulaToken* t = aArr.AddMatrixSingleReference( aRefData);
- itr = rMark.begin();
- for (; itr != itrEnd && *itr < nMax; ++itr)
+ for (const SCTAB& nTab : rMark)
{
- SCTAB nTab = *itr;
+ if (nTab >= nMax)
+ break;
+
ScTable* pTab = FetchTable(nTab);
if (!pTab)
continue;
@@ -362,12 +365,14 @@ void ScDocument::InsertTableOp(const ScTabOpParam& rParam, // multiple (repeate
i = 0;
bool bStop = false;
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
+ for (const auto& rTab : rMark)
{
- if (maTabs[*itr])
+ if (rTab >= nMax)
+ break;
+
+ if (maTabs[rTab])
{
- i = *itr;
+ i = rTab;
bStop = true;
break;
}
@@ -435,11 +440,14 @@ void ScDocument::InsertTableOp(const ScTabOpParam& rParam, // multiple (repeate
for( k = nRow1; k <= nRow2; k++ )
for (i = 0; i < static_cast<SCTAB>(maTabs.size()); i++)
{
- itr = rMark.begin();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if( maTabs[*itr] )
- maTabs[*itr]->SetFormulaCell(
- j, k, new ScFormulaCell(aRefCell, *this, ScAddress(j, k, *itr), ScCloneFlags::StartListening));
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if( maTabs[rTab] )
+ maTabs[rTab]->SetFormulaCell(
+ j, k, new ScFormulaCell(aRefCell, *this, ScAddress(j, k, rTab), ScCloneFlags::StartListening));
+ }
}
}
@@ -546,33 +554,32 @@ void ScDocument::ReplaceStyle(const SvxSearchItem& rSearchItem,
void ScDocument::CompileDBFormula()
{
sc::CompileFormulaContext aCxt(this);
- TableContainer::iterator it = maTabs.begin();
- for (;it != maTabs.end(); ++it)
+ for (auto& rxTab : maTabs)
{
- if (*it)
- (*it)->CompileDBFormula(aCxt);
+ if (rxTab)
+ rxTab->CompileDBFormula(aCxt);
}
}
void ScDocument::CompileColRowNameFormula()
{
sc::CompileFormulaContext aCxt(this);
- TableContainer::iterator it = maTabs.begin();
- for (;it != maTabs.end(); ++it)
+ for (auto& rxTab : maTabs)
{
- if (*it)
- (*it)->CompileColRowNameFormula(aCxt);
+ if (rxTab)
+ rxTab->CompileColRowNameFormula(aCxt);
}
}
void ScDocument::InvalidateTableArea()
{
- TableContainer::iterator it = maTabs.begin();
- for (;it != maTabs.end() && *it; ++it)
+ for (auto& rxTab : maTabs)
{
- (*it)->InvalidateTableArea();
- if ( (*it)->IsScenario() )
- (*it)->InvalidateScenarioRanges();
+ if (!rxTab)
+ break;
+ rxTab->InvalidateTableArea();
+ if ( rxTab->IsScenario() )
+ rxTab->InvalidateScenarioRanges();
}
}
@@ -715,9 +722,9 @@ sal_uLong ScDocument::AddValidationEntry( const ScValidationData& rNew )
}
sal_uLong nMax = 0;
- for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
+ for( const auto& rxData : *pValidationList )
{
- const ScValidationData* pData = it->get();
+ const ScValidationData* pData = rxData.get();
sal_uLong nKey = pData->GetKey();
if ( pData->EqualEntries( rNew ) )
return nKey;
@@ -749,10 +756,9 @@ const SfxPoolItem* ScDocument::GetEffItem(
ScConditionalFormatList* pCondFormList = GetCondFormList( nTab );
if (!rIndex.empty() && pCondFormList)
{
- for(std::vector<sal_uInt32>::const_iterator itr = rIndex.begin(), itrEnd = rIndex.end();
- itr != itrEnd; ++itr)
+ for(const auto& rItem : rIndex)
{
- const ScConditionalFormat* pForm = pCondFormList->GetFormat( *itr );
+ const ScConditionalFormat* pForm = pCondFormList->GetFormat( rItem );
if ( pForm )
{
ScAddress aPos(nCol, nRow, nTab);
@@ -795,10 +801,9 @@ const SfxItemSet* ScDocument::GetCondResult(
ScRefCellValue& rCell, const ScAddress& rPos, const ScConditionalFormatList& rList,
const std::vector<sal_uInt32>& rIndex ) const
{
- std::vector<sal_uInt32>::const_iterator itr = rIndex.begin(), itrEnd = rIndex.end();
- for (; itr != itrEnd; ++itr)
+ for (const auto& rItem : rIndex)
{
- const ScConditionalFormat* pForm = rList.GetFormat(*itr);
+ const ScConditionalFormat* pForm = rList.GetFormat(rItem);
if (!pForm)
continue;
diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx
index abd4ec3f762d..6fedfecc91e0 100644
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@ -215,11 +215,10 @@ void ScDocument::BroadcastRefMoved( const sc::RefMovedHint& rHint )
// Get all area listeners that listens on the old range, and end their listening.
std::vector<sc::AreaListener> aAreaListeners = pBASM->GetAllListeners(rSrcRange, sc::AreaInside);
{
- std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
- for (; it != itEnd; ++it)
+ for (auto& rAreaListener : aAreaListeners)
{
- pBASM->EndListeningArea(it->maArea, it->mbGroupListening, it->mpListener);
- it->mpListener->Notify(rHint); // Adjust the references.
+ pBASM->EndListeningArea(rAreaListener.maArea, rAreaListener.mbGroupListening, rAreaListener.mpListener);
+ rAreaListener.mpListener->Notify(rHint); // Adjust the references.
}
}
@@ -265,15 +264,14 @@ void ScDocument::BroadcastRefMoved( const sc::RefMovedHint& rHint )
// Re-start area listeners on the new range.
{
ScRange aErrorRange( ScAddress::UNINITIALIZED );
- std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
- for (; it != itEnd; ++it)
+ for (auto& rAreaListener : aAreaListeners)
{
- ScRange aNewRange = it->maArea;
+ ScRange aNewRange = rAreaListener.maArea;
if (!aNewRange.Move(rDelta.Col(), rDelta.Row(), rDelta.Tab(), aErrorRange))
{
assert(!"can't move AreaListener");
}
- pBASM->StartListeningArea(aNewRange, it->mbGroupListening, it->mpListener);
+ pBASM->StartListeningArea(aNewRange, rAreaListener.mbGroupListening, rAreaListener.mpListener);
}
}
}
@@ -340,9 +338,8 @@ void ScDocument::EndListeningFormulaCells( std::vector<ScFormulaCell*>& rCells )
return;
sc::EndListeningContext aCxt(*this);
- std::vector<ScFormulaCell*>::iterator it = rCells.begin(), itEnd = rCells.end();
- for (; it != itEnd; ++it)
- (*it)->EndListeningTo(aCxt);
+ for (auto& pCell : rCells)
+ pCell->EndListeningTo(aCxt);
aCxt.purgeEmptyBroadcasters();
}
@@ -457,10 +454,9 @@ void ScDocument::CalcFormulaTree( bool bOnlyForced, bool bProgressBar, bool bSet
}
pCell = pCell->GetNext();
}
- for (::std::vector<ScFormulaCell*>::iterator it( vAlwaysDirty.begin()), itEnd( vAlwaysDirty.end());
- it != itEnd; ++it)
+ for (auto& rpCell : vAlwaysDirty)
{
- pCell = *it;
+ pCell = rpCell;
if (!pCell->GetDirty())
pCell->SetDirty();
}
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index f9525ba3b1d8..c90353bc207b 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -1233,11 +1233,13 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, Transliteratio
std::unique_ptr<ScEditEngineDefaulter> pEngine; // not using mpEditEngine member because of defaults
SCTAB nCount = GetTableCount();
- ScMarkData::const_iterator itr = rMultiMark.begin(), itrEnd = rMultiMark.end();
- for (; itr != itrEnd && *itr < nCount; ++itr)
- if ( maTabs[*itr] )
+ for (const SCTAB& nTab : rMultiMark)
+ {
+ if (nTab >= nCount)
+ break;
+
+ if ( maTabs[nTab] )
{
- SCTAB nTab = *itr;
SCCOL nCol = 0;
SCROW nRow = 0;
@@ -1337,6 +1339,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, Transliteratio
bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark );
}
}
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index ae3b481b2a87..8fc38fb2e533 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -254,10 +254,13 @@ void ScDocument::DeleteObjectsInArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCR
return;
SCTAB nTabCount = GetTableCount();
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nTabCount; ++itr)
- if (maTabs[*itr])
- mpDrawLayer->DeleteObjectsInArea( *itr, nCol1, nRow1, nCol2, nRow2 );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nTabCount)
+ break;
+ if (maTabs[rTab])
+ mpDrawLayer->DeleteObjectsInArea( rTab, nCol1, nRow1, nCol2, nRow2 );
+ }
}
void ScDocument::DeleteObjectsInSelection( const ScMarkData& rMark )
@@ -494,10 +497,9 @@ bool ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
void ScDocument::Clear( bool bFromDestructor )
{
- TableContainer::iterator it = maTabs.begin();
- for (;it != maTabs.end(); ++it)
- if (*it)
- (*it)->GetCondFormList()->clear();
+ for (auto& rxTab : maTabs)
+ if (rxTab)
+ rxTab->GetCondFormList()->clear();
maTabs.clear();
pSelectionAttr.reset();
@@ -578,13 +580,12 @@ void ScDocument::UpdateFontCharSet()
void ScDocument::SetLoadingMedium( bool bVal )
{
bLoadingMedium = bVal;
- TableContainer::iterator it = maTabs.begin();
- for (; it != maTabs.end(); ++it)
+ for (auto& rxTab : maTabs)
{
- if (!*it)
+ if (!rxTab)
return;
- (*it)->SetLoadingMedium(bVal);
+ rxTab->SetLoadingMedium(bVal);
}
}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 6b933019f4f8..91b799f4b4ee 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -111,15 +111,17 @@ std::pair<SCTAB,SCTAB> getMarkedTableRange(const std::vector<ScTableUniquePtr>&
SCTAB nTabStart = MAXTAB;
SCTAB nTabEnd = 0;
SCTAB nMax = static_cast<SCTAB>(rTables.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
+ for (const auto& rTab : rMark)
{
- if (!rTables[*itr])
+ if (rTab >= nMax)
+ break;
+
+ if (!rTables[rTab])
continue;
- if (*itr < nTabStart)
- nTabStart = *itr;
- nTabEnd = *itr;
+ if (rTab < nTabStart)
+ nTabStart = rTab;
+ nTabEnd = rTab;
}
return std::pair<SCTAB,SCTAB>(nTabStart,nTabEnd);
@@ -2204,11 +2206,11 @@ void ScDocument::CopyToClip(const ScClipParam& rClipParam,
}
//init maTabNames
- for (TableContainer::iterator itr = maTabs.begin(); itr != maTabs.end(); ++itr)
+ for (const auto& rxTab : maTabs)
{
- if( *itr )
+ if( rxTab )
{
- OUString aTabName = (*itr)->GetName();
+ OUString aTabName = rxTab->GetName();
pClipDoc->maTabNames.push_back(aTabName);
}
else
@@ -2303,11 +2305,11 @@ void ScDocument::CopyTabToClip(SCCOL nCol1, SCROW nRow1,
}
//init maTabNames
- for (TableContainer::iterator itr = maTabs.begin(); itr != maTabs.end(); ++itr)
+ for (const auto& rxTab : maTabs)
{
- if( *itr )
+ if( rxTab )
{
- OUString aTabName = (*itr)->GetName();
+ OUString aTabName = rxTab->GetName();
pClipDoc->maTabNames.push_back(aTabName);
}
else
@@ -2347,11 +2349,10 @@ void ScDocument::TransposeClip( ScDocument* pTransClip, InsertDeleteFlags nFlags
if (pRangeName)
{
pTransClip->GetRangeName()->clear();
- ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
- for (; itr != itrEnd; ++itr)
+ for (const auto& rEntry : *pRangeName)
{
- sal_uInt16 nIndex = itr->second->GetIndex();
- ScRangeData* pData = new ScRangeData(*itr->second);
+ sal_uInt16 nIndex = rEntry.second->GetIndex();
+ ScRangeData* pData = new ScRangeData(*rEntry.second);
if (pTransClip->pRangeName->insert(pData))
pData->SetIndex(nIndex);
}
@@ -2407,15 +2408,14 @@ void copyUsedNamesToClip(ScRangeName* pClipRangeName, ScRangeName* pRangeName,
const sc::UpdatedRangeNames::NameIndicesType& rUsedNames)
{
pClipRangeName->clear();
- ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
- for (; itr != itrEnd; ++itr) //TODO: also DB and Pivot regions!!!
+ for (const auto& rEntry : *pRangeName) //TODO: also DB and Pivot regions!!!
{
- sal_uInt16 nIndex = itr->second->GetIndex();
+ sal_uInt16 nIndex = rEntry.second->GetIndex();
bool bInUse = (rUsedNames.count(nIndex) > 0);
if (!bInUse)
continue;
- ScRangeData* pData = new ScRangeData(*itr->second);
+ ScRangeData* pData = new ScRangeData(*rEntry.second);
if (pClipRangeName->insert(pData))
pData->SetIndex(nIndex);
}
@@ -2591,10 +2591,13 @@ void ScDocument::StartListeningFromClip( SCCOL nCol1, SCROW nRow1,
sc::EndListeningContext aEndCxt(*this, pSet, nullptr);
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->StartListeningFormulaCells(aStartCxt, aEndCxt, nCol1, nRow1, nCol2, nRow2);
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->StartListeningFormulaCells(aStartCxt, aEndCxt, nCol1, nRow1, nCol2, nRow2);
+ }
}
}
@@ -2605,10 +2608,13 @@ void ScDocument::SetDirtyFromClip(
if (nInsFlag & InsertDeleteFlags::CONTENTS)
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->SetDirtyFromClip(nCol1, nRow1, nCol2, nRow2, rBroadcastSpans);
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->SetDirtyFromClip(nCol1, nRow1, nCol2, nRow2, rBroadcastSpans);
+ }
}
}
@@ -3254,11 +3260,12 @@ void ScDocument::FillTab( const ScRange& rSrcArea, const ScMarkData& rMark,
sc::MixDocContext aMixDocCxt(*this);
SCTAB nCount = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nCount; ++itr)
- if ( *itr!=nSrcTab && maTabs[*itr])
+ for (const SCTAB& i : rMark)
+ {
+ if (i >= nCount)
+ break;
+ if (i != nSrcTab && maTabs[i])
{
- SCTAB i = *itr;
if (bDoMix)
{
if (!pMixDoc)
@@ -3283,8 +3290,9 @@ void ScDocument::FillTab( const ScRange& rSrcArea, const ScMarkData& rMark,
if (bDoMix)
maTabs[i]->MixData(aMixDocCxt, nStartCol,nStartRow, nEndCol,nEndRow,
- nFunction, bSkipEmpty, pMixDoc->maTabs[i].get() );
+ nFunction, bSkipEmpty, pMixDoc->maTabs[i].get() );
}
+ }
SetAutoCalc( bOldAutoCalc );
}
@@ -3320,11 +3328,12 @@ void ScDocument::FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
sc::CopyToDocContext aCxt(*this);
sc::MixDocContext aMixDocCxt(*this);
SCTAB nCount = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nCount; ++itr)
- if ( *itr!=nSrcTab && maTabs[*itr] )
+ for (const SCTAB& i : rMark)
+ {
+ if (i >= nCount)
+ break;
+ if ( i != nSrcTab && maTabs[i] )
{
- SCTAB i = *itr;
if (bDoMix)
{
if (!pMixDoc)
@@ -3337,9 +3346,9 @@ void ScDocument::FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
sc::CopyToDocContext aMixCxt(*pMixDoc);
maTabs[i]->CopyToTable(aMixCxt, nStartCol,nStartRow, nEndCol,nEndRow,
- InsertDeleteFlags::CONTENTS, true, pMixDoc->maTabs[i].get(), &rMark,
- /*bAsLink*/false, /*bColRowFlags*/true, /*bGlobalNamesToLocal*/false,
- /*bCopyCaptions*/true );
+ InsertDeleteFlags::CONTENTS, true, pMixDoc->maTabs[i].get(), &rMark,
+ /*bAsLink*/false, /*bColRowFlags*/true, /*bGlobalNamesToLocal*/false,
+ /*bCopyCaptions*/true );
}
maTabs[i]->DeleteSelection( nDelFlags, rMark );
@@ -3350,6 +3359,7 @@ void ScDocument::FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
if (bDoMix)
maTabs[i]->MixMarked(aMixDocCxt, rMark, nFunction, bSkipEmpty, pMixDoc->maTabs[i].get());
}
+ }
SetAutoCalc( bOldAutoCalc );
}
@@ -4794,10 +4804,13 @@ void ScDocument::ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow,
bool* const pIsChanged )
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->ApplyPatternArea( nStartCol, nStartRow, nEndCol, nEndRow, rAttr, pDataArray, pIsChanged );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->ApplyPatternArea( nStartCol, nStartRow, nEndCol, nEndRow, rAttr, pDataArray, pIsChanged );
+ }
}
void ScDocument::ApplyPatternAreaTab( SCCOL nStartCol, SCROW nStartRow,
@@ -4812,10 +4825,13 @@ void ScDocument::ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
const ScMarkData& rMark, const ScPatternAttr& rPattern, SvNumFormatType nNewType )
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->ApplyPatternIfNumberformatIncompatible( rRange, rPattern, nNewType );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->ApplyPatternIfNumberformatIncompatible( rRange, rPattern, nNewType );
+ }
}
void ScDocument::AddCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex )
@@ -4853,10 +4869,13 @@ void ScDocument::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow,
const ScStyleSheet& rStyle)
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->ApplyStyleArea( nStartCol, nStartRow, nEndCol, nEndRow, rStyle );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->ApplyStyleArea( nStartCol, nStartRow, nEndCol, nEndRow, rStyle );
+ }
}
void ScDocument::ApplyStyleAreaTab( SCCOL nStartCol, SCROW nStartRow,
@@ -4880,10 +4899,13 @@ void ScDocument::ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkDat
else
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if ( maTabs[*itr] )
- maTabs[*itr]->ApplySelectionStyle( rStyle, rMark );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if ( maTabs[rTab] )
+ maTabs[rTab]->ApplySelectionStyle( rStyle, rMark );
+ }
}
}
@@ -4894,10 +4916,13 @@ void ScDocument::ApplySelectionLineStyle( const ScMarkData& rMark,
return;
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->ApplySelectionLineStyle( rMark, pLine, bColorOnly );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->ApplySelectionLineStyle( rMark, pLine, bColorOnly );
+ }
}
const ScStyleSheet* ScDocument::GetStyle( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
@@ -4919,11 +4944,14 @@ const ScStyleSheet* ScDocument::GetSelectionStyle( const ScMarkData& rMark ) con
if ( rMark.IsMultiMarked() )
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+
+ if (maTabs[rTab])
{
- pNewStyle = maTabs[*itr]->GetSelectionStyle( rMark, bFound );
+ pNewStyle = maTabs[rTab]->GetSelectionStyle( rMark, bFound );
if (bFound)
{
if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
@@ -4931,6 +4959,7 @@ const ScStyleSheet* ScDocument::GetSelectionStyle( const ScMarkData& rMark ) con
pStyle = pNewStyle;
}
}
+ }
}
if ( rMark.IsMarked() )
{
@@ -5048,22 +5077,28 @@ std::unique_ptr<ScPatternAttr> ScDocument::CreateSelectionPattern( const ScMarkD
if ( rMark.IsMultiMarked() ) // multi selection
{
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->MergeSelectionPattern( aState, rMark, bDeep );
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->MergeSelectionPattern( aState, rMark, bDeep );
+ }
}
if ( rMark.IsMarked() ) // single selection
{
ScRange aRange;
rMark.GetMarkArea(aRange);
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->MergePatternArea( aState,
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+ if (maTabs[rTab])
+ maTabs[rTab]->MergePatternArea( aState,
aRange.aStart.Col(), aRange.aStart.Row(),
aRange.aEnd.Col(), aRange.aEnd.Row(), bDeep );
+ }
}
OSL_ENSURE( aState.pItemSet, "SelectionPattern Null" );
@@ -5115,12 +5150,16 @@ void ScDocument::GetSelectionFrame( const ScMarkData& rMark,
bMultipleRows = ( bMultipleRows || ( rRange.aStart.Row() != rRange.aEnd.Row() ) );
bMultipleCols = ( bMultipleCols || ( rRange.aStart.Col() != rRange.aEnd.Col() ) );
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->MergeBlockFrame( &rLineOuter, &rLineInner, aFlags,
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+
+ if (maTabs[rTab])
+ maTabs[rTab]->MergeBlockFrame( &rLineOuter, &rLineInner, aFlags,
rRange.aStart.Col(), rRange.aStart.Row(),
rRange.aEnd.Col(), rRange.aEnd.Row() );
+ }
}
rLineInner.EnableHor( bMultipleRows );
rLineInner.EnableVer( bMultipleCols );
@@ -5132,12 +5171,16 @@ void ScDocument::GetSelectionFrame( const ScMarkData& rMark,
rLineInner.EnableHor( aRange.aStart.Row() != aRange.aEnd.Row() );
rLineInner.EnableVer( aRange.aStart.Col() != aRange.aEnd.Col() );
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax; ++itr)
- if (maTabs[*itr])
- maTabs[*itr]->MergeBlockFrame( &rLineOuter, &rLineInner, aFlags,
+ for (const auto& rTab : rMark)
+ {
+ if (rTab >= nMax)
+ break;
+
+ if (maTabs[rTab])
+ maTabs[rTab]->MergeBlockFrame( &rLineOuter, &rLineInner, aFlags,
aRange.aStart.Col(), aRange.aStart.Row(),
aRange.aEnd.Col(), aRange.aEnd.Row() );
+ }
}
// Evaluate don't care Status
@@ -5343,14 +5386,16 @@ bool ScDocument::IsSelectionEditable( const ScMarkData& rMark,
bool bOk = true;
bool bMatrix = ( pOnlyNotBecauseOfMatrix != nullptr );
SCTAB nMax = static_cast<SCTAB>(maTabs.size());
- ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
- for (; itr != itrEnd && *itr < nMax && (bOk || bMatrix); ++itr)
+ for (const auto& rTab : rMark)
{
- if ( maTabs[*itr] )
+ if (rTab >= nMax)
+ break;
+
+ if ( maTabs[rTab] )
{
if (rMark.IsMarked())
{
- if ( !maTabs[*itr]->IsBlockEditable( aRange.aStart.Col(),
+ if ( !maTabs[rTab]->IsBlockEditable( aRange.aStart.Col(),
aRange.aStart.Row(), aRange.aEnd.Col(),
aRange.aEnd.Row(), pOnlyNotBecauseOfMatrix ) )
{
@@ -5361,7 +5406,7 @@ bool ScDocument::IsSelectionEditable( const ScMarkData& rMark,
}
if (rMark.IsMultiMarked())
{
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list