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

Eike Rathke erack at redhat.com
Wed Mar 9 10:14:40 UTC 2016


 sc/inc/scmatrix.hxx              |    2 +-
 sc/source/core/tool/interpr6.cxx |    4 ++--
 sc/source/core/tool/scmatrix.cxx |   28 ++++++++++++++++++++++------
 3 files changed, 25 insertions(+), 9 deletions(-)

New commits:
commit 84f8fa501ac772b40639d7b6e95ebeb752b01bf5
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 2 22:48:01 2016 +0100

    Resolves: tdf#98297 exclude error values from COUNT in array/matrix
    
    Backport of b2f5336b08b5f638f890a626eb2aeefaf499a79b
    
    Change-Id: I04ef53b8880243b3548e1b7fd926690dcb4a2137
    Reviewed-on: https://gerrit.libreoffice.org/22846
    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 5a5ff95..a4b38df 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -372,7 +372,7 @@ public:
     IterateResult Sum(bool bTextAsZero) const;
     IterateResult SumSquare(bool bTextAsZero) const;
     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;
 
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
index e02abbc..6d5e624 100644
--- a/sc/source/core/tool/interpr6.cxx
+++ b/sc/source/core/tool/interpr6.cxx
@@ -376,10 +376,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 328a4ba..55ed380 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;
 
@@ -1105,8 +1105,10 @@ class CountElements : std::unary_function<MatrixImplType::element_block_node_typ
 {
     size_t mnCount;
     bool mbCountString;
+    bool mbCountErrors;
 public:
-    CountElements(bool bCountString) : mnCount(0), mbCountString(bCountString) {}
+    CountElements(bool bCountString, bool bCountErrors) :
+        mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {}
 
     size_t getCount() const { return mnCount; }
 
@@ -1115,6 +1117,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;
@@ -1719,9 +1735,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const
     return aRes;
 }
 
-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();
 }
@@ -2518,9 +2534,9 @@ ScMatrix::IterateResult ScMatrix::Product(bool bTextAsZero) const
     return pImpl->Product(bTextAsZero);
 }
 
-size_t ScMatrix::Count(bool bCountStrings) const
+size_t ScMatrix::Count(bool bCountStrings, bool bCountErrors) const
 {
-    return pImpl->Count(bCountStrings);
+    return pImpl->Count(bCountStrings, bCountErrors);
 }
 
 size_t ScMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const


More information about the Libreoffice-commits mailing list