[Libreoffice-commits] core.git: sc/inc sc/source
Eike Rathke
erack at redhat.com
Wed Apr 1 16:32:17 PDT 2015
sc/inc/scmatrix.hxx | 14 ++++-----
sc/source/core/tool/interpr1.cxx | 6 +---
sc/source/core/tool/interpr5.cxx | 14 +++------
sc/source/core/tool/scmatrix.cxx | 55 ++++++++++++++++++++-------------------
4 files changed, 43 insertions(+), 46 deletions(-)
New commits:
commit 636dd43c1cc10ca5f609fe23ee388d9679a60f2e
Author: Eike Rathke <erack at redhat.com>
Date: Thu Apr 2 01:13:53 2015 +0200
use error value instead of string in array/matrix, tdf#89387 tdf#42481 related
Hopefully tdf#90391 will be solved, else we'll have to revert all MatOp
work and do this change on the previous code.
Change-Id: I4789ccf389558f3687d90c600a4f1a27c24a20d9
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index e85054e..f1fbe8e 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -387,13 +387,13 @@ public:
void GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero = true ) const;
void MergeDoubleArray( std::vector<double>& rArray, Op eOp ) const;
- void NotOp(svl::SharedString aString, ScMatrix& rMat);
- void NegOp(svl::SharedString aString, ScMatrix& rMat);
- void AddOp(svl::SharedString aString, double fVal, ScMatrix& rMat);
- void SubOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat);
- void MulOp(svl::SharedString aString, double fVal, ScMatrix& rMat);
- void DivOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat);
- void PowOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat);
+ void NotOp(ScMatrix& rMat);
+ void NegOp(ScMatrix& rMat);
+ void AddOp(double fVal, ScMatrix& rMat);
+ void SubOp(bool bFlag, double fVal, ScMatrix& rMat);
+ void MulOp(double fVal, ScMatrix& rMat);
+ void DivOp(bool bFlag, double fVal, ScMatrix& rMat);
+ void PowOp(bool bFlag, double fVal, ScMatrix& rMat);
ScMatrix& operator+= ( const ScMatrix& r );
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 292ed38..09fca4d 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1500,8 +1500,7 @@ void ScInterpreter::ScNeg()
PushIllegalArgument();
else
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
- pMat->NegOp(aString, *pResMat);
+ pMat->NegOp( *pResMat);
PushMatrix( pResMat );
}
}
@@ -1545,8 +1544,7 @@ void ScInterpreter::ScNot()
PushIllegalArgument();
else
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
- pMat->NotOp(aString, *pResMat);
+ pMat->NotOp( *pResMat);
PushMatrix( pResMat );
}
}
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index f2f8dd6..5b472ee 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1288,14 +1288,13 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
ScMatrixRef pResMat = GetNewMat(nC, nR, true);
if (pResMat)
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
if (_bSub)
{
- pMat->SubOp(bFlag, aString, fVal, *pResMat);
+ pMat->SubOp( bFlag, fVal, *pResMat);
}
else
{
- pMat->AddOp(aString, fVal, *pResMat);
+ pMat->AddOp( fVal, *pResMat);
}
PushMatrix(pResMat);
}
@@ -1474,8 +1473,7 @@ void ScInterpreter::ScMul()
ScMatrixRef pResMat = GetNewMat(nC, nR);
if (pResMat)
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
- pMat->MulOp(aString, fVal, *pResMat);
+ pMat->MulOp( fVal, *pResMat);
PushMatrix(pResMat);
}
else
@@ -1548,8 +1546,7 @@ void ScInterpreter::ScDiv()
ScMatrixRef pResMat = GetNewMat(nC, nR);
if (pResMat)
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
- pMat->DivOp(bFlag, aString, fVal, *pResMat);
+ pMat->DivOp( bFlag, fVal, *pResMat);
PushMatrix(pResMat);
}
else
@@ -1614,8 +1611,7 @@ void ScInterpreter::ScPow()
ScMatrixRef pResMat = GetNewMat(nC, nR);
if (pResMat)
{
- svl::SharedString aString = mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE));
- pMat->PowOp(bFlag, aString, fVal, *pResMat);
+ pMat->PowOp( bFlag, fVal, *pResMat);
PushMatrix(pResMat);
}
else
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 07e90db..47554d1 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -2050,7 +2050,7 @@ public:
block_type::const_iterator it = block_type::begin(*node.data);
block_type::const_iterator itEnd = block_type::end(*node.data);
- MatrixIteratorWrapper<block_type, T, typename T::string_value_type> aFunc(it, itEnd, maOp);
+ MatrixIteratorWrapper<block_type, T, typename T::number_value_type> aFunc(it, itEnd, maOp);
pos = mrMat.set(pos, aFunc.begin(), aFunc.end());
++pos.first;
}
@@ -2523,22 +2523,25 @@ struct COp {};
template <typename T>
struct COp<T, svl::SharedString>
{
- svl::SharedString operator()(char, T /*aOp*/, const svl::SharedString& aString) const
+ svl::SharedString operator()(char, T /*aOp*/, const svl::SharedString& rString) const
{
- return aString;
+ return rString;
}
};
template <typename T>
struct COp<T, double>
{
- double operator()(char, T aOp, const svl::SharedString& /*aString*/) const
+ double operator()(char, T aOp, const svl::SharedString& /*rString*/) const
{
return aOp(double{}, double{});
}
};
-template<typename TOp, typename TEmptyRes=svl::SharedString, typename TRet=double>
+/** A template for operations where operands are supposed to be numeric.
+ A non-numeric operand leads to an errNoValue DoubleError.
+ */
+template<typename TOp, typename TEmptyRes=double, typename TRet=double>
struct MatOp
{
private:
@@ -2552,9 +2555,9 @@ public:
typedef TRet number_value_type;
typedef svl::SharedString string_value_type;
- MatOp(TOp aOp, svl::SharedString aString, double fVal=0.0):
+ MatOp( TOp aOp, double fVal = 0.0, const svl::SharedString& rString = svl::SharedString() ):
maOp(aOp),
- maString(aString),
+ maString(rString),
mfVal(fVal)
{ }
@@ -2568,9 +2571,9 @@ public:
return maOp((double)bVal, mfVal);
}
- svl::SharedString operator()(const svl::SharedString&) const
+ double operator()(const svl::SharedString&) const
{
- return maString;
+ return CreateDoubleError( errNoValue);
}
TEmptyRes operator()(char) const
@@ -2586,78 +2589,78 @@ public:
}
-void ScMatrix::NotOp(svl::SharedString aString, ScMatrix& rMat)
+void ScMatrix::NotOp( ScMatrix& rMat)
{
auto not_ = [](double a, double){return double(a == 0.0);};
- matop::MatOp<decltype(not_), double> aOp(not_, aString);
+ matop::MatOp<decltype(not_), double> aOp(not_);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
-void ScMatrix::NegOp(svl::SharedString aString, ScMatrix& rMat)
+void ScMatrix::NegOp( ScMatrix& rMat)
{
auto neg_ = [](double a, double){return -a;};
- matop::MatOp<decltype(neg_), double> aOp(neg_, aString);
+ matop::MatOp<decltype(neg_), double> aOp(neg_);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
-void ScMatrix::AddOp(svl::SharedString aString, double fVal, ScMatrix& rMat)
+void ScMatrix::AddOp( double fVal, ScMatrix& rMat)
{
auto add_ = [](double a, double b){return a + b;};
- matop::MatOp<decltype(add_)> aOp(add_, aString, fVal);
+ matop::MatOp<decltype(add_)> aOp(add_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
-void ScMatrix::SubOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat)
+void ScMatrix::SubOp( bool bFlag, double fVal, ScMatrix& rMat)
{
if (bFlag)
{
auto sub_ = [](double a, double b){return b - a;};
- matop::MatOp<decltype(sub_)> aOp(sub_, aString, fVal);
+ matop::MatOp<decltype(sub_)> aOp(sub_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto sub_ = [](double a, double b){return a - b;};
- matop::MatOp<decltype(sub_)> aOp(sub_, aString, fVal);
+ matop::MatOp<decltype(sub_)> aOp(sub_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
-void ScMatrix::MulOp(svl::SharedString aString, double fVal, ScMatrix& rMat)
+void ScMatrix::MulOp( double fVal, ScMatrix& rMat)
{
auto mul_ = [](double a, double b){return a * b;};
- matop::MatOp<decltype(mul_)> aOp(mul_, aString, fVal);
+ matop::MatOp<decltype(mul_)> aOp(mul_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
-void ScMatrix::DivOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat)
+void ScMatrix::DivOp( bool bFlag, double fVal, ScMatrix& rMat)
{
if (bFlag)
{
auto div_ = [](double a, double b){return sc::div(b, a);};
- matop::MatOp<decltype(div_), svl::SharedString> aOp(div_, aString, fVal);
+ matop::MatOp<decltype(div_)> aOp(div_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto div_ = [](double a, double b){return sc::div(a, b);};
- matop::MatOp<decltype(div_), svl::SharedString> aOp(div_, aString, fVal);
+ matop::MatOp<decltype(div_)> aOp(div_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
-void ScMatrix::PowOp(bool bFlag, svl::SharedString aString, double fVal, ScMatrix& rMat)
+void ScMatrix::PowOp( bool bFlag, double fVal, ScMatrix& rMat)
{
if (bFlag)
{
auto pow_ = [](double a, double b){return pow(b, a);};
- matop::MatOp<decltype(pow_)> aOp(pow_, aString, fVal);
+ matop::MatOp<decltype(pow_)> aOp(pow_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto pow_ = [](double a, double b){return pow(a, b);};
- matop::MatOp<decltype(pow_)> aOp(pow_, aString, fVal);
+ matop::MatOp<decltype(pow_)> aOp(pow_, fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
More information about the Libreoffice-commits
mailing list