summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-12-10 12:31:10 -0500
committerKohei Yoshida <kyoshida@novell.com>2010-12-10 12:31:10 -0500
commitc00da0581e3790ea44f381a8fb24a95bf8d9e4cb (patch)
tree11a51081050e00069ab54315cafe89b9d631cedb /sc/source
parent1fa53014ddb04214edafc8c24877c16a473331eb (diff)
Use for_each & iterators to count the number of cells.
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/tool/rangelst.cxx34
1 files changed, 22 insertions, 12 deletions
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 62b149c9da26..5efea71781f1 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -101,6 +101,26 @@ struct DeleteObject : public ::std::unary_function<void, T*>
}
};
+class CountCells : public ::std::unary_function<void, const ScRange*>
+{
+public:
+ CountCells() : mnCellCount(0) {}
+ CountCells(const CountCells& r) : mnCellCount(r.mnCellCount) {}
+
+ void operator() (const ScRange* p)
+ {
+ mnCellCount +=
+ size_t(p->aEnd.Col() - p->aStart.Col() + 1)
+ * size_t(p->aEnd.Row() - p->aStart.Row() + 1)
+ * size_t(p->aEnd.Tab() - p->aStart.Tab() + 1);
+ }
+
+ size_t getCellCount() const { return mnCellCount; }
+
+private:
+ size_t mnCellCount;
+};
+
}
// === ScRangeList ====================================================
@@ -393,18 +413,8 @@ bool ScRangeList::In( const ScRange& rRange ) const
size_t ScRangeList::GetCellCount() const
{
- size_t nCellCount = 0;
-
- vector<ScRange*>::const_iterator itr = maRanges.begin(), itrEnd = maRanges.end();
- for (; itr != itrEnd; ++itr)
- {
- const ScRange* pR = *itr;
- nCellCount += size_t(pR->aEnd.Col() - pR->aStart.Col() + 1)
- * size_t(pR->aEnd.Row() - pR->aStart.Row() + 1)
- * size_t(pR->aEnd.Tab() - pR->aStart.Tab() + 1);
- }
-
- return nCellCount;
+ CountCells func;
+ return for_each(maRanges.begin(), maRanges.end(), func).getCellCount();
}
ScRange* ScRangeList::Remove(size_t nPos)