summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-04-02 21:16:00 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-04-13 20:05:45 +0000
commit6b3decb3bb0a580c2978028660567ba3a66878ae (patch)
treeefa168dcb6ae11179cbc817c1b980eda86ea8fb1
parentfa316c6459d40d97fab52881cdff94d2cbab0c91 (diff)
use error value instead of string in array/matrix, tdf#42481 related
Change-Id: Iaacf5636749077efc6f91f0eb0bac477cfcf4553 Reviewed-on: https://gerrit.libreoffice.org/15129 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/inc/scmatrix.hxx3
-rw-r--r--sc/source/core/tool/interpr1.cxx6
-rw-r--r--sc/source/core/tool/interpr5.cxx15
-rw-r--r--sc/source/core/tool/scmatrix.cxx72
4 files changed, 42 insertions, 54 deletions
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index 6f8ad9104329..27d3777521b3 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -264,6 +264,7 @@ public:
/// Jump sal_False without path
void PutEmptyPath( SCSIZE nC, SCSIZE nR);
void PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR );
+ void PutError( sal_uInt16 nErrorCode, SCSIZE nIndex );
void PutBoolean( bool bVal, SCSIZE nC, SCSIZE nR);
void FillDouble( double fVal,
@@ -388,7 +389,7 @@ public:
void GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero = true ) const;
void MergeDoubleArray( std::vector<double>& rArray, Op eOp ) const;
- void SubAddOp(bool bSub, double fVal, svl::SharedString aString, ScMatrix& rMat);
+ void SubAddOp(bool bSub, 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 4ad6f1e9d25d..1713089c23b7 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1499,8 +1499,7 @@ void ScInterpreter::ScNeg()
if ( pMat->IsValueOrEmpty(i,j) )
pResMat->PutDouble( -pMat->GetDouble(i,j), i, j );
else
- pResMat->PutString(
- mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i, j);
+ pResMat->PutError( errNoValue, i, j);
}
}
PushMatrix( pResMat );
@@ -1553,8 +1552,7 @@ void ScInterpreter::ScNot()
if ( pMat->IsValueOrEmpty(i,j) )
pResMat->PutDouble( double(pMat->GetDouble(i,j) == 0.0), i, j );
else
- pResMat->PutString(
- mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i, j);
+ pResMat->PutError( errNoValue, i, j);
}
}
PushMatrix( pResMat );
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 7b46fd88956b..3aab1c23a50d 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1284,14 +1284,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 (bFlag || !_bSub )
{
- pMat->SubAddOp(_bSub, fVal, aString, *pResMat);
+ pMat->SubAddOp(_bSub, fVal, *pResMat);
}
else
{
- pMat->SubAddOp(false, -fVal, aString, *pResMat);
+ pMat->SubAddOp(false, -fVal, *pResMat);
}
PushMatrix(pResMat);
}
@@ -1475,7 +1474,7 @@ void ScInterpreter::ScMul()
if (pMat->IsValue(i))
pResMat->PutDouble(pMat->GetDouble(i)*fVal, i);
else
- pResMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i);
+ pResMat->PutError( errNoValue, i);
PushMatrix(pResMat);
}
else
@@ -1554,14 +1553,14 @@ void ScInterpreter::ScDiv()
if (pMat->IsValue(i))
pResMat->PutDouble( div( fVal, pMat->GetDouble(i)), i);
else
- pResMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i);
+ pResMat->PutError( errNoValue, i);
}
else
{ for ( SCSIZE i = 0; i < nCount; i++ )
if (pMat->IsValue(i))
pResMat->PutDouble( div( pMat->GetDouble(i), fVal), i);
else
- pResMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i);
+ pResMat->PutError( errNoValue, i);
}
PushMatrix(pResMat);
}
@@ -1633,14 +1632,14 @@ void ScInterpreter::ScPow()
if (pMat->IsValue(i))
pResMat->PutDouble(pow(fVal,pMat->GetDouble(i)), i);
else
- pResMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i);
+ pResMat->PutError( errNoValue, i);
}
else
{ for ( SCSIZE i = 0; i < nCount; i++ )
if (pMat->IsValue(i))
pResMat->PutDouble(pow(pMat->GetDouble(i),fVal), i);
else
- pResMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), i);
+ pResMat->PutError( errNoValue, i);
}
PushMatrix(pResMat);
}
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 4398308bf90e..90b23765c041 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -242,6 +242,7 @@ public:
void PutEmpty(SCSIZE nC, SCSIZE nR);
void PutEmptyPath(SCSIZE nC, SCSIZE nR);
void PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR );
+ void PutError( sal_uInt16 nErrorCode, SCSIZE nIndex );
void PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR);
sal_uInt16 GetError( SCSIZE nC, SCSIZE nR) const;
double GetDouble(SCSIZE nC, SCSIZE nR) const;
@@ -488,6 +489,13 @@ void ScMatrixImpl::PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR )
maMat.set(nR, nC, CreateDoubleError(nErrorCode));
}
+void ScMatrixImpl::PutError( sal_uInt16 nErrorCode, SCSIZE nIndex )
+{
+ SCSIZE nC, nR;
+ CalcPosition(nIndex, nC, nR);
+ maMat.set(nR, nC, CreateDoubleError(nErrorCode));
+}
+
void ScMatrixImpl::PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR)
{
if (ValidColRow( nC, nR))
@@ -1871,34 +1879,11 @@ void ScMatrixImpl::AddValues( const ScMatrixImpl& rMat )
}
}
-namespace Op {
-
-template<typename T>
-struct return_type
-{
- typedef T type;
-};
-
-template<>
-struct return_type<bool>
-{
- typedef double type;
-};
-
-template<>
-struct return_type<char>
-{
- typedef svl::SharedString type;
-};
-
-}
-
template<typename T, typename U>
struct wrapped_iterator
{
typedef ::std::bidirectional_iterator_tag iterator_category;
- typedef typename T::const_iterator::value_type old_value_type;
- typedef typename Op::return_type<old_value_type>::type value_type;
+ typedef double value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef typename T::const_iterator::difference_type difference_type;
@@ -2294,6 +2279,11 @@ void ScMatrix::PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR )
pImpl->PutError(nErrorCode, nC, nR);
}
+void ScMatrix::PutError( sal_uInt16 nErrorCode, SCSIZE nIndex )
+{
+ pImpl->PutError(nErrorCode, nIndex);
+}
+
void ScMatrix::PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR)
{
pImpl->PutBoolean(bVal, nC, nR);
@@ -2536,13 +2526,13 @@ struct AddOp
{
private:
double mnVal;
- svl::SharedString maString;
+ double mnError;
public:
- AddOp(double nVal, svl::SharedString aString):
+ AddOp(double nVal):
mnVal(nVal),
- maString(aString)
+ mnError( CreateDoubleError( errNoValue))
{
}
@@ -2556,14 +2546,14 @@ public:
return mnVal + (double)bVal;
}
- svl::SharedString operator()(const svl::SharedString&) const
+ double operator()(const svl::SharedString&) const
{
- return maString;
+ return mnError;
}
- svl::SharedString operator()(char) const
+ double operator()(char) const
{
- return maString;
+ return mnVal; // mnVal + 0.0
}
bool useFunctionForEmpty() const
@@ -2576,13 +2566,13 @@ struct SubOp
{
private:
double mnVal;
- svl::SharedString maString;
+ double mnError;
public:
- SubOp(double nVal, svl::SharedString aString):
+ SubOp(double nVal):
mnVal(nVal),
- maString(aString)
+ mnError( CreateDoubleError( errNoValue))
{
}
@@ -2596,14 +2586,14 @@ public:
return mnVal - (double)bVal;
}
- svl::SharedString operator()(const svl::SharedString&) const
+ double operator()(const svl::SharedString&) const
{
- return maString;
+ return mnError;
}
- svl::SharedString operator()(char) const
+ double operator()(char) const
{
- return maString;
+ return mnVal; // mnVal - 0.0
}
bool useFunctionForEmpty() const
@@ -2614,16 +2604,16 @@ public:
}
-void ScMatrix::SubAddOp(bool bSub, double fVal, svl::SharedString aString, ScMatrix& rMat)
+void ScMatrix::SubAddOp(bool bSub, double fVal, ScMatrix& rMat)
{
if(bSub)
{
- SubOp aOp(fVal, aString);
+ SubOp aOp(fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
else
{
- AddOp aOp(fVal, aString);
+ AddOp aOp(fVal);
pImpl->ApplyOperation(aOp, *rMat.pImpl);
}
}