[Libreoffice-commits] .: sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Dec 10 09:31:36 PST 2010


 sc/source/core/tool/rangelst.cxx |   34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

New commits:
commit a8ead55f1ce22efc72a31f888eb0582c962bbf71
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Dec 10 12:31:10 2010 -0500

    Use for_each & iterators to count the number of cells.

diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index bc6b9c2..13bde0b 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)


More information about the Libreoffice-commits mailing list