[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - sc/inc sc/source

Eike Rathke erack at redhat.com
Wed Mar 9 10:01:03 UTC 2016


 sc/inc/scmatrix.hxx              |    6 +++---
 sc/source/core/tool/interpr6.cxx |    4 ++--
 sc/source/core/tool/scmatrix.cxx |   32 ++++++++++++++++++++++++--------
 3 files changed, 29 insertions(+), 13 deletions(-)

New commits:
commit 6f718d779a99e86dc43444338d48c89cf64e7f9e
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 2 21:18:24 2016 +0100

    Resolves: tdf#98297 exclude error values from COUNT in array/matrix
    
    Change-Id: I202dcc2a2b90ee8ed27815b97a2aad6e4df2f1b9
    (cherry picked from commit b2f5336b08b5f638f890a626eb2aeefaf499a79b)
    Reviewed-on: https://gerrit.libreoffice.org/22843
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index d057437..bb09ab5 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -368,7 +368,7 @@ public:
     virtual IterateResult Sum(bool bTextAsZero) const = 0;
     virtual IterateResult SumSquare(bool bTextAsZero) const = 0;
     virtual IterateResult Product(bool bTextAsZero) const = 0;
-    virtual size_t Count(bool bCountStrings) const = 0;
+    virtual size_t Count(bool bCountStrings, bool bCountErrors) const = 0;
     virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const = 0;
     virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const = 0;
 
@@ -573,7 +573,7 @@ public:
     virtual IterateResult Sum(bool bTextAsZero) const override;
     virtual IterateResult SumSquare(bool bTextAsZero) const override;
     virtual IterateResult Product(bool bTextAsZero) const override;
-    virtual size_t Count(bool bCountStrings) const override;
+    virtual size_t Count(bool bCountStrings, bool bCountErrors) const override;
     virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const override;
     virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const override;
 
@@ -782,7 +782,7 @@ public:
     virtual IterateResult Sum(bool bTextAsZero) const override;
     virtual IterateResult SumSquare(bool bTextAsZero) const override;
     virtual IterateResult Product(bool bTextAsZero) const override;
-    virtual size_t Count(bool bCountStrings) const override;
+    virtual size_t Count(bool bCountStrings, bool bCountErrors) const override;
     virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const override;
     virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const override;
 
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
index e7e321b..8dd5d8d 100644
--- a/sc/source/core/tool/interpr6.cxx
+++ b/sc/source/core/tool/interpr6.cxx
@@ -433,10 +433,10 @@ void IterateMatrix(
         }
         break;
         case ifCOUNT:
-            rCount += pMat->Count(bTextAsZero);
+            rCount += pMat->Count(bTextAsZero, false);  // do not count error values
         break;
         case ifCOUNT2:
-            rCount += pMat->Count(true);
+            rCount += pMat->Count(true, true);          // do count error values
         break;
         case ifPRODUCT:
         {
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 2bbe993..3da4d2c 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -284,7 +284,7 @@ public:
     ScMatrix::IterateResult Sum(bool bTextAsZero) const;
     ScMatrix::IterateResult SumSquare(bool bTextAsZero) const;
     ScMatrix::IterateResult Product(bool bTextAsZero) const;
-    size_t Count(bool bCountStrings) const;
+    size_t Count(bool bCountStrings, bool bCountErrors) const;
     size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const;
     size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const;
 
@@ -1177,8 +1177,10 @@ class CountElements : std::unary_function<MatrixImplType::element_block_node_typ
 {
     size_t mnCount;
     bool mbCountString;
+    bool mbCountErrors;
 public:
-    explicit CountElements(bool bCountString) : mnCount(0), mbCountString(bCountString) {}
+    explicit CountElements(bool bCountString, bool bCountErrors) :
+        mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {}
 
     size_t getCount() const { return mnCount; }
 
@@ -1187,6 +1189,20 @@ public:
         switch (node.type)
         {
             case mdds::mtm::element_numeric:
+                mnCount += node.size;
+                if (!mbCountErrors)
+                {
+                    typedef MatrixImplType::numeric_block_type block_type;
+
+                    block_type::const_iterator it = block_type::begin(*node.data);
+                    block_type::const_iterator itEnd = block_type::end(*node.data);
+                    for (; it != itEnd; ++it)
+                    {
+                        if (!::rtl::math::isFinite(*it))
+                            --mnCount;
+                    }
+                }
+            break;
             case mdds::mtm::element_boolean:
                 mnCount += node.size;
             break;
@@ -1796,9 +1812,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const
     return GetValueWithCount<sc::op::Product>(bTextAsZero, maMat);
 }
 
-size_t ScMatrixImpl::Count(bool bCountStrings) const
+size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const
 {
-    CountElements aFunc(bCountStrings);
+    CountElements aFunc(bCountStrings, bCountErrors);
     maMat.walk(aFunc);
     return aFunc.getCount();
 }
@@ -2609,9 +2625,9 @@ ScMatrix::IterateResult ScFullMatrix::Product(bool bTextAsZero) const
     return pImpl->Product(bTextAsZero);
 }
 
-size_t ScFullMatrix::Count(bool bCountStrings) const
+size_t ScFullMatrix::Count(bool bCountStrings, bool bCountErrors) const
 {
-    return pImpl->Count(bCountStrings);
+    return pImpl->Count(bCountStrings, bCountErrors);
 }
 
 size_t ScFullMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const
@@ -3500,10 +3516,10 @@ ScMatrix::IterateResult ScVectorRefMatrix::Product(bool bTextAsZero) const
     return mpFullMatrix->Product(bTextAsZero);
 }
 
-size_t ScVectorRefMatrix::Count(bool bCountStrings) const
+size_t ScVectorRefMatrix::Count(bool bCountStrings, bool bCountErrors) const
 {
     const_cast<ScVectorRefMatrix*>(this)->ensureFullMatrix();
-    return mpFullMatrix->Count(bCountStrings);
+    return mpFullMatrix->Count(bCountStrings, bCountErrors);
 }
 
 size_t ScVectorRefMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const


More information about the Libreoffice-commits mailing list