[Libreoffice-commits] core.git: sc/inc sc/source
Łukasz Hryniuk
lukasz.hryniuk at wp.pl
Wed Mar 25 01:58:24 PDT 2015
sc/inc/scmatrix.hxx | 5 +++
sc/source/core/tool/interpr5.cxx | 30 ------------------
sc/source/core/tool/scmatrix.cxx | 63 +++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 29 deletions(-)
New commits:
commit 9a7959cd63be7b2f36da8af25e7673a525c4d66c
Author: Łukasz Hryniuk <lukasz.hryniuk at wp.pl>
Date: Sun Mar 15 00:00:05 2015 +0100
tdf#89387 Add functor for ScAmpersand
Change-Id: If89073cc6b21aad0f04f79e934aa2d646a057333
Reviewed-on: https://gerrit.libreoffice.org/14873
Reviewed-by: David Tardon <dtardon at redhat.com>
Tested-by: David Tardon <dtardon at redhat.com>
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index e85054e..2ad51e0 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -43,6 +43,10 @@ struct CompareOptions;
}
+namespace svl {
+class SharedStringPool;
+}
+
/**
* Try NOT to use this struct. This struct should go away in a hopefully
* not so distant futture.
@@ -394,6 +398,7 @@ public:
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 AmpersandOp(bool bFlag, svl::SharedString aString, ScMatrix& rMat, svl::SharedStringPool& rStrPool);
ScMatrix& operator+= ( const ScMatrix& r );
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index c030c8d..48e3747 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1362,37 +1362,9 @@ void ScInterpreter::ScAmpersand()
for (SCSIZE j = 0; j < nR; ++j)
pResMat->PutError( nGlobalError, i, j);
}
- else if (bFlag)
- {
- for (SCSIZE i = 0; i < nC; ++i)
- for (SCSIZE j = 0; j < nR; ++j)
- {
- sal_uInt16 nErr = pMat->GetErrorIfNotString( i, j);
- if (nErr)
- pResMat->PutError( nErr, i, j);
- else
- {
- OUString aTmp = sStr;
- aTmp += pMat->GetString(*pFormatter, i, j).getString();
- pResMat->PutString(mrStrPool.intern(aTmp), i, j);
- }
- }
- }
else
{
- for (SCSIZE i = 0; i < nC; ++i)
- for (SCSIZE j = 0; j < nR; ++j)
- {
- sal_uInt16 nErr = pMat->GetErrorIfNotString( i, j);
- if (nErr)
- pResMat->PutError( nErr, i, j);
- else
- {
- OUString aTmp = pMat->GetString(*pFormatter, i, j).getString();
- aTmp += sStr;
- pResMat->PutString(mrStrPool.intern(aTmp), i, j);
- }
- }
+ pMat->AmpersandOp(bFlag, sStr, *pResMat, mrStrPool);
}
PushMatrix(pResMat);
}
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 07e90db..a465e09 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -29,6 +29,7 @@
#include <boost/noncopyable.hpp>
#include <svl/zforlist.hxx>
#include <svl/sharedstring.hxx>
+#include <svl/sharedstringpool.hxx>
#include <tools/stream.hxx>
#include <rtl/math.hxx>
@@ -36,6 +37,7 @@
#include <vector>
#include <limits>
+#include <functional>
#include <mdds/multi_type_matrix.hpp>
#include <mdds/multi_type_vector_types.hpp>
@@ -2584,6 +2586,49 @@ public:
}
};
+
+struct AmpersandOp
+{
+private:
+ std::function<svl::SharedString(svl::SharedString,svl::SharedString)> maOp;
+ svl::SharedString maString;
+
+public:
+ typedef svl::SharedString empty_value_type;
+ typedef double number_value_type;
+ typedef svl::SharedString string_value_type;
+
+ AmpersandOp(std::function<svl::SharedString(svl::SharedString,svl::SharedString)> aOp, svl::SharedString aString):
+ maOp(aOp),
+ maString(aString)
+ { }
+
+ double operator()(double fVal) const
+ {
+ return CreateDoubleError(GetDoubleErrorValue(fVal));
+ }
+
+ double operator()(bool fVal) const
+ {
+ return CreateDoubleError(GetDoubleErrorValue(double(fVal)));
+ }
+
+ svl::SharedString operator()(svl::SharedString aVal) const
+ {
+ return maOp(maString, aVal);
+ }
+
+ svl::SharedString operator()(char) const
+ {
+ return maString;
+ }
+
+ bool useFunctionForEmpty() const
+ {
+ return true;
+ }
+};
+
}
void ScMatrix::NotOp(svl::SharedString aString, ScMatrix& rMat)
@@ -2662,6 +2707,24 @@ void ScMatrix::PowOp(bool bFlag, svl::SharedString aString, double fVal, ScMatri
}
}
+void ScMatrix::AmpersandOp(bool bFlag, svl::SharedString aString, ScMatrix& rMat, svl::SharedStringPool& rStrPool)
+{
+ if (bFlag)
+ {
+ auto amp_ = [&rStrPool](svl::SharedString a, svl::SharedString b) -> svl::SharedString
+ {return rStrPool.intern(a.getString() += b.getString());};
+ matop::AmpersandOp aOp(amp_, aString);
+ pImpl->ApplyOperation(aOp, *rMat.pImpl);
+ }
+ else
+ {
+ auto amp_ = [&rStrPool](svl::SharedString a, svl::SharedString b) -> svl::SharedString
+ {return rStrPool.intern(b.getString() += a.getString());};
+ matop::AmpersandOp aOp(amp_, aString);
+ pImpl->ApplyOperation(aOp, *rMat.pImpl);
+ }
+}
+
ScMatrix& ScMatrix::operator+= ( const ScMatrix& r )
{
pImpl->AddValues(*r.pImpl);
More information about the Libreoffice-commits
mailing list