[Libreoffice-commits] core.git: 2 commits - sc/source
Eike Rathke
erack at redhat.com
Mon Oct 5 09:48:57 PDT 2015
sc/source/core/inc/interpre.hxx | 5 ++++
sc/source/core/tool/interpr4.cxx | 5 ++++
sc/source/core/tool/scmatrix.cxx | 41 ++++++++++++++++++++++++++-------------
3 files changed, 38 insertions(+), 13 deletions(-)
New commits:
commit 466a20ef07f36d50a73a18ab119b3cc18b4babf4
Author: Eike Rathke <erack at redhat.com>
Date: Mon Oct 5 18:43:45 2015 +0200
Resolves: tdf#91453 use configuration of text to number conversion
... also in arithmetic matrix operations.
Change-Id: Ia00054d0af383e225d9d40b59da2dc28a817b65a
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index f178db4..21b4545 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -2634,7 +2634,10 @@ struct COp<T, double>
};
/** A template for operations where operands are supposed to be numeric.
- A non-numeric (string) operand leads to an errNoValue DoubleError.
+ A non-numeric (string) operand leads to the configured conversion to number
+ method being called if in interpreter context and an errNoValue DoubleError
+ if conversion was not possible, else to an unconditional errNoValue
+ DoubleError.
An empty operand evaluates to 0.
XXX: semantically TEmptyRes and types other than number_value_type are
unused, but this template could serve as a basis for future enhancements.
@@ -2644,6 +2647,7 @@ struct MatOp
{
private:
TOp maOp;
+ ScInterpreter* mpErrorInterpreter;
svl::SharedString maString;
double mfVal;
COp<TOp, TEmptyRes> maCOp;
@@ -2653,8 +2657,10 @@ public:
typedef TRet number_value_type;
typedef svl::SharedString string_value_type;
- MatOp( TOp aOp, double fVal = 0.0, const svl::SharedString& rString = svl::SharedString() ):
+ MatOp( TOp aOp, ScInterpreter* pErrorInterpreter,
+ double fVal = 0.0, const svl::SharedString& rString = svl::SharedString() ):
maOp(aOp),
+ mpErrorInterpreter(pErrorInterpreter),
maString(rString),
mfVal(fVal)
{ }
@@ -2669,8 +2675,17 @@ public:
return maOp((double)bVal, mfVal);
}
- double operator()(const svl::SharedString&) const
+ double operator()(const svl::SharedString& rStr) const
{
+ if (mpErrorInterpreter)
+ {
+ sal_uInt16 nError = 0;
+ short nCurFmtType = 0;
+ double fValue = mpErrorInterpreter->ConvertStringToValue( rStr.getString(), nError, nCurFmtType);
+ if (nError)
+ return CreateDoubleError( nError);
+ return fValue;
+ }
return CreateDoubleError( errNoValue);
}
@@ -2690,21 +2705,21 @@ public:
void ScMatrix::NotOp( ScMatrix& rMat)
{
auto not_ = [](double a, double){return double(a == 0.0);};
- matop::MatOp<decltype(not_), double> aOp(not_);
+ matop::MatOp<decltype(not_), double> aOp(not_, pImpl->GetErrorInterpreter());
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
void ScMatrix::NegOp( ScMatrix& rMat)
{
auto neg_ = [](double a, double){return -a;};
- matop::MatOp<decltype(neg_), double> aOp(neg_);
+ matop::MatOp<decltype(neg_), double> aOp(neg_, pImpl->GetErrorInterpreter());
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
void ScMatrix::AddOp( double fVal, ScMatrix& rMat)
{
auto add_ = [](double a, double b){return a + b;};
- matop::MatOp<decltype(add_)> aOp(add_, fVal);
+ matop::MatOp<decltype(add_)> aOp(add_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
@@ -2713,13 +2728,13 @@ 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_, fVal);
+ matop::MatOp<decltype(sub_)> aOp(sub_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto sub_ = [](double a, double b){return a - b;};
- matop::MatOp<decltype(sub_)> aOp(sub_, fVal);
+ matop::MatOp<decltype(sub_)> aOp(sub_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
@@ -2727,7 +2742,7 @@ void ScMatrix::SubOp( bool bFlag, 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_, fVal);
+ matop::MatOp<decltype(mul_)> aOp(mul_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
@@ -2736,13 +2751,13 @@ 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_)> aOp(div_, fVal);
+ matop::MatOp<decltype(div_)> aOp(div_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto div_ = [](double a, double b){return sc::div(a, b);};
- matop::MatOp<decltype(div_)> aOp(div_, fVal);
+ matop::MatOp<decltype(div_)> aOp(div_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
@@ -2752,13 +2767,13 @@ 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_, fVal);
+ matop::MatOp<decltype(pow_)> aOp(pow_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
auto pow_ = [](double a, double b){return pow(a, b);};
- matop::MatOp<decltype(pow_)> aOp(pow_, fVal);
+ matop::MatOp<decltype(pow_)> aOp(pow_, pImpl->GetErrorInterpreter(), fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}
commit 6516d5e299bdf0e7aa03d1004763f6d10db48546
Author: Eike Rathke <erack at redhat.com>
Date: Mon Oct 5 16:07:51 2015 +0200
add half decoupled ScInterpreter::ConvertStringToValue()
... for back calls of ScMatrix in preparation of tdf#91453
Change-Id: Ife94d1675c1bc7c5611586e3f352ff69264469d7
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 1bda8a8..85ede44 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -204,6 +204,11 @@ void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab ); // for TableOp
bool IsTableOpInRange( const ScRange& );
sal_uLong GetCellNumberFormat( const ScAddress& rPos, ScRefCellValue& rCell );
double ConvertStringToValue( const OUString& );
+public:
+/** For matrix back calls into the current interpreter.
+ Uses rError instead of nGlobalError and rCurFmtType instead of nCurFmtType. */
+double ConvertStringToValue( const OUString&, sal_uInt16& rError, short& rCurFmtType );
+private:
double GetCellValue( const ScAddress&, ScRefCellValue& rCell );
double GetCellValueOrZero( const ScAddress&, ScRefCellValue& rCell );
double GetValueCellValue( const ScAddress&, double fOrig );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 3f95e6d..68d182c 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -193,6 +193,11 @@ double ScInterpreter::ConvertStringToValue( const OUString& rStr )
return fValue;
}
+double ScInterpreter::ConvertStringToValue( const OUString& rStr, sal_uInt16& rError, short& rCurFmtType )
+{
+ return ScGlobal::ConvertStringToValue( rStr, maCalcConfig, rError, mnStringNoValueError, pFormatter, rCurFmtType);
+}
+
double ScInterpreter::GetCellValue( const ScAddress& rPos, ScRefCellValue& rCell )
{
sal_uInt16 nErr = nGlobalError;
More information about the Libreoffice-commits
mailing list