maNewMatValues.reserve(nRow*nCol);
}
+ CompareMatrixElemFunc( const CompareMatrixElemFunc& ) = delete;
+ CompareMatrixElemFunc& operator= ( const CompareMatrixElemFunc& ) = delete;
+
+ CompareMatrixElemFunc( CompareMatrixElemFunc&& ) = default;
+ CompareMatrixElemFunc& operator= ( CompareMatrixElemFunc&& ) = default;
+
void operator() (const MatrixImplType::element_block_node_type& node)
{
switch (node.type)
const ScFullMatrix::EmptyOpFunction& aEmptyFunc) const;
template<typename T>
- std::vector<ScMatrix::IterateResult> ApplyCollectOperation(bool bTextAsZero, const std::vector<std::unique_ptr<T>>& aOp);
+ std::vector<ScMatrix::IterateResult> ApplyCollectOperation(const std::vector<std::unique_ptr<T>>& aOp);
void MatConcat(SCSIZE nMaxCol, SCSIZE nMaxRow, const ScMatrixRef& xMat1, const ScMatrixRef& xMat2,
SvNumberFormatter& rFormatter, svl::SharedStringPool& rPool);
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemEqualZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemNotEqualZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemLessZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemGreaterZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemLessEqualZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
{
MatrixImplType::size_pair_type aSize = maMat.size();
CompareMatrixElemFunc<ElemGreaterEqualZero> aFunc(aSize.row, aSize.column);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(maMat);
}
template<typename Op>
class WalkElementBlocksMultipleValues
{
- const std::vector<std::unique_ptr<Op>>& maOp;
+ const std::vector<std::unique_ptr<Op>>* mpOp;
std::vector<ScMatrix::IterateResult> maRes;
bool mbFirst:1;
- bool mbTextAsZero:1;
public:
- WalkElementBlocksMultipleValues(bool bTextAsZero, const std::vector<std::unique_ptr<Op>>& aOp) :
- maOp(aOp), mbFirst(true), mbTextAsZero(bTextAsZero)
+ WalkElementBlocksMultipleValues(const std::vector<std::unique_ptr<Op>>& aOp) :
+ mpOp(&aOp), mbFirst(true)
{
- for (const auto& rpOp : maOp)
+ for (const auto& rpOp : *mpOp)
{
maRes.emplace_back(rpOp->mInitVal, rpOp->mInitVal, 0);
}
maRes.emplace_back(0.0, 0.0, 0); // count
}
+ WalkElementBlocksMultipleValues( const WalkElementBlocksMultipleValues& ) = delete;
+ WalkElementBlocksMultipleValues& operator= ( const WalkElementBlocksMultipleValues& ) = delete;
+
+ WalkElementBlocksMultipleValues( WalkElementBlocksMultipleValues&& r ) :
+ mpOp(r.mpOp), maRes(std::move(r.maRes)), mbFirst(r.mbFirst) {}
+
+ WalkElementBlocksMultipleValues& operator= ( WalkElementBlocksMultipleValues&& r )
+ {
+ mpOp = r.mpOp;
+ maRes = std::move(r.maRes);
+ mbFirst = r.mbFirst;
+ return *this;
+ }
+
const std::vector<ScMatrix::IterateResult>& getResult() const { return maRes; }
void operator() (const MatrixImplType::element_block_node_type& node)
{
if (mbFirst)
{
- for (auto i = 0u; i < maOp.size(); ++i)
+ for (auto i = 0u; i < mpOp->size(); ++i)
{
- (*maOp[i])(maRes[i].mfFirst, *it);
+ (*(*mpOp)[i])(maRes[i].mfFirst, *it);
}
mbFirst = false;
}
else
{
- for (auto i = 0u; i < maOp.size(); ++i)
+ for (auto i = 0u; i < mpOp->size(); ++i)
{
- (*maOp[i])(maRes[i].mfRest, *it);
+ (*(*mpOp)[i])(maRes[i].mfRest, *it);
}
}
}
{
if (mbFirst)
{
- for (auto i = 0u; i < maOp.size(); ++i)
+ for (auto i = 0u; i < mpOp->size(); ++i)
{
- (*maOp[i])(maRes[i].mfFirst, *it);
+ (*(*mpOp)[i])(maRes[i].mfFirst, *it);
}
mbFirst = false;
}
else
{
- for (auto i = 0u; i < maOp.size(); ++i)
+ for (auto i = 0u; i < mpOp->size(); ++i)
{
- (*maOp[i])(maRes[i].mfRest, *it);
+ (*(*mpOp)[i])(maRes[i].mfRest, *it);
}
}
}
}
break;
case mdds::mtm::element_string:
- if (mbTextAsZero)
- maRes.back().mnCount += node.size;
- break;
case mdds::mtm::element_empty:
default:
;
class WalkAndMatchElements
{
Type maMatchValue;
- const size_t mnStartIndex;
- const size_t mnStopIndex;
+ size_t mnStartIndex;
+ size_t mnStopIndex;
size_t mnResult;
size_t mnIndex;
maResValues.reserve(nResSize);
}
+ CompareMatrixFunc( const CompareMatrixFunc& ) = delete;
+ CompareMatrixFunc& operator= ( const CompareMatrixFunc& ) = delete;
+
+ CompareMatrixFunc( CompareMatrixFunc&& r ) :
+ mrComp(r.mrComp),
+ mnMatPos(r.mnMatPos),
+ mpOptions(r.mpOptions),
+ maResValues(std::move(r.maResValues)) {}
+
+ CompareMatrixFunc& operator= ( CompareMatrixFunc&& r )
+ {
+ mrComp = r.mrComp;
+ mnMatPos = r.mnMatPos;
+ mpOptions = r.mpOptions;
+ maResValues = std::move(r.maResValues);
+ return *this;
+ }
+
void operator() (const MatrixImplType::element_block_node_type& node)
{
sc::Compare::Cell& rCell = mrComp.maCells[mnMatPos];
maResValues.reserve(nResSize);
}
+ CompareMatrixToNumericFunc( const CompareMatrixToNumericFunc& ) = delete;
+ CompareMatrixToNumericFunc& operator= ( const CompareMatrixToNumericFunc& ) = delete;
+
+ CompareMatrixToNumericFunc( CompareMatrixToNumericFunc&& r ) :
+ mrComp(r.mrComp),
+ mfRightValue(r.mfRightValue),
+ mpOptions(r.mpOptions),
+ maResValues(std::move(r.maResValues)) {}
+
+ CompareMatrixToNumericFunc& operator= ( CompareMatrixToNumericFunc&& r )
+ {
+ mrComp = r.mrComp;
+ mfRightValue = r.mfRightValue;
+ mpOptions = r.mpOptions;
+ maResValues = std::move(r.maResValues);
+ return *this;
+ }
+
void operator() (const MatrixImplType::element_block_node_type& node)
{
sc::Compare::Cell& rCell = mrComp.maCells[0];
double mfNaN;
bool mbEmptyAsZero;
+ void moveArray( ToDoubleArray& r )
+ {
+ // Re-create the iterator from the new array after the array has been
+ // moved, to ensure that the iterator points to a valid array
+ // position.
+ size_t n = std::distance(r.maArray.begin(), r.miPos);
+ maArray = std::move(r.maArray);
+ miPos = maArray.begin();
+ std::advance(miPos, n);
+ }
+
public:
ToDoubleArray( size_t nSize, bool bEmptyAsZero ) :
maArray(nSize, 0.0), miPos(maArray.begin()), mbEmptyAsZero(bEmptyAsZero)
mfNaN = CreateDoubleError( FormulaError::ElementNaN);
}
+ ToDoubleArray( const ToDoubleArray& ) = delete;
+ ToDoubleArray& operator= ( const ToDoubleArray& ) = delete;
+
+ ToDoubleArray( ToDoubleArray&& r ) :
+ mfNaN(r.mfNaN), mbEmptyAsZero(r.mbEmptyAsZero)
+ {
+ moveArray(r);
+ }
+
+ ToDoubleArray& operator= ( ToDoubleArray&& r )
+ {
+ mfNaN = r.mfNaN;
+ mbEmptyAsZero = r.mbEmptyAsZero;
+ moveArray(r);
+ return *this;
+ }
+
void operator() (const MatrixImplType::element_block_node_type& node)
{
using namespace mdds::mtv;
mfNaN = CreateDoubleError( FormulaError::ElementNaN);
}
+ MergeDoubleArrayFunc( const MergeDoubleArrayFunc& ) = delete;
+ MergeDoubleArrayFunc& operator= ( const MergeDoubleArrayFunc& ) = delete;
+
+ MergeDoubleArrayFunc( MergeDoubleArrayFunc&& ) = default;
+ MergeDoubleArrayFunc& operator= ( MergeDoubleArrayFunc&& ) = default;
+
void operator() (const MatrixImplType::element_block_node_type& node)
{
using namespace mdds::mtv;
ScMatrix::IterateResult GetValueWithCount(bool bTextAsZero, const MatrixImplType& maMat)
{
WalkElementBlocks<TOp> aFunc(bTextAsZero);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getResult();
}
size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const
{
CountElements aFunc(bCountStrings, bCountErrors);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getCount();
}
size_t ScMatrixImpl::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const
{
WalkAndMatchElements<double> aFunc(fValue, maMat.size(), nCol1, nCol2);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getMatching();
}
size_t ScMatrixImpl::MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const
{
WalkAndMatchElements<svl::SharedString> aFunc(rStr, maMat.size(), nCol1, nCol2);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getMatching();
}
double ScMatrixImpl::GetMaxValue( bool bTextAsZero ) const
{
CalcMaxMinValue<MaxOp> aFunc(bTextAsZero);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getValue();
}
double ScMatrixImpl::GetMinValue( bool bTextAsZero ) const
{
CalcMaxMinValue<MinOp> aFunc(bTextAsZero);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getValue();
}
double ScMatrixImpl::GetGcd() const
{
CalcGcdLcm<Gcd> aFunc;
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getResult();
}
double ScMatrixImpl::GetLcm() const
{
CalcGcdLcm<Lcm> aFunc;
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
return aFunc.getResult();
}
// function object that has much less branching for much better
// performance.
CompareMatrixToNumericFunc aFunc(nSize, rComp, rComp.maCells[1].mfValue, pOptions);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
// We assume the result matrix has the same dimension as this matrix.
const std::vector<double>& rResVal = aFunc.getValues();
}
CompareMatrixFunc aFunc(nSize, rComp, nMatPos, pOptions);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
// We assume the result matrix has the same dimension as this matrix.
const std::vector<double>& rResVal = aFunc.getValues();
{
MatrixImplType::size_pair_type aSize = maMat.size();
ToDoubleArray aFunc(aSize.row*aSize.column, bEmptyAsZero);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
aFunc.swap(rArray);
}
case ScFullMatrix::Mul:
{
MergeDoubleArrayFunc<ArrayMul> aFunc(rArray);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(std::move(aFunc));
}
break;
default:
private:
MatrixImplType& mrMat;
MatrixImplType::position_type pos;
- T maOp;
+ const T* mpOp;
public:
- MatrixOpWrapper(MatrixImplType& rMat, T const & aOp):
+ MatrixOpWrapper(MatrixImplType& rMat, const T& aOp):
mrMat(rMat),
pos(rMat.position(0,0)),
- maOp(aOp)
+ mpOp(&aOp)
{
}
+ MatrixOpWrapper( const MatrixOpWrapper& r ) : mrMat(r.mrMat), pos(r.pos), mpOp(r.mpOp) {}
+
+ MatrixOpWrapper& operator= ( const MatrixOpWrapper& r )
+ {
+ mrMat = r.mrMat;
+ pos = r.pos;
+ mpOp = r.mpOp;
+ return *this;
+ }
+
void operator()(const MatrixImplType::element_block_node_type& node)
{
switch (node.type)
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::number_value_type> aFunc(it, itEnd, maOp);
+ MatrixIteratorWrapper<block_type, T, typename T::number_value_type> aFunc(it, itEnd, *mpOp);
pos = mrMat.set(pos,aFunc.begin(), aFunc.end());
}
break;
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::number_value_type> aFunc(it, itEnd, maOp);
+ MatrixIteratorWrapper<block_type, T, typename T::number_value_type> aFunc(it, itEnd, *mpOp);
pos = mrMat.set(pos, aFunc.begin(), aFunc.end());
}
break;
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::number_value_type> aFunc(it, itEnd, maOp);
+ MatrixIteratorWrapper<block_type, T, typename T::number_value_type> aFunc(it, itEnd, *mpOp);
pos = mrMat.set(pos, aFunc.begin(), aFunc.end());
}
break;
case mdds::mtm::element_empty:
{
- if (maOp.useFunctionForEmpty())
+ if (mpOp->useFunctionForEmpty())
{
std::vector<char> aVec(node.size);
MatrixIteratorWrapper<std::vector<char>, T, typename T::number_value_type>
- aFunc(aVec.begin(), aVec.end(), maOp);
+ aFunc(aVec.begin(), aVec.end(), *mpOp);
pos = mrMat.set(pos, aFunc.begin(), aFunc.end());
}
}
void ScMatrixImpl::ApplyOperation(T aOp, ScMatrixImpl& rMat)
{
MatrixOpWrapper<T> aFunc(rMat.maMat, aOp);
- maMat.walk(aFunc);
+ aFunc = maMat.walk(aFunc);
}
template<typename T>
-std::vector<ScMatrix::IterateResult> ScMatrixImpl::ApplyCollectOperation(bool bTextAsZero, const std::vector<std::unique_ptr<T>>& aOp)
+std::vector<ScMatrix::IterateResult> ScMatrixImpl::ApplyCollectOperation(const std::vector<std::unique_ptr<T>>& aOp)
{
- WalkElementBlocksMultipleValues<T> aFunc(bTextAsZero, aOp);
- maMat.walk(aFunc);
+ WalkElementBlocksMultipleValues<T> aFunc(aOp);
+ aFunc = maMat.walk(std::move(aFunc));
return aFunc.getResult();
}
{
WalkElementBlockOperation aFunc(maMat.size().row,
aDoubleFunc, aBoolFunc, aStringFunc, aEmptyFunc);
- maMat.walk(aFunc, MatrixImplType::size_pair_type(rStartPos.first, rStartPos.second),
- MatrixImplType::size_pair_type(rEndPos.first, rEndPos.second));
+ aFunc = maMat.walk(
+ aFunc,
+ MatrixImplType::size_pair_type(rStartPos.first, rStartPos.second),
+ MatrixImplType::size_pair_type(rEndPos.first, rEndPos.second));
}
#if DEBUG_MATRIX
pImpl->ExecuteOperation(rStartPos, rEndPos, aDoubleFunc, aBoolFunc, aStringFunc, aEmptyFunc);
}
-std::vector<ScMatrix::IterateResult> ScFullMatrix::Collect(bool bTextAsZero, const std::vector<std::unique_ptr<sc::op::Op>>& aOp)
+std::vector<ScMatrix::IterateResult> ScFullMatrix::Collect(const std::vector<std::unique_ptr<sc::op::Op>>& aOp)
{
- return pImpl->ApplyCollectOperation(bTextAsZero, aOp);
+ return pImpl->ApplyCollectOperation(aOp);
}
ScFullMatrix& ScFullMatrix::operator+= ( const ScFullMatrix& r )
mpFullMatrix->PowOp(bFlag, fVal, rMat);
}
-std::vector<ScMatrix::IterateResult> ScVectorRefMatrix::Collect(bool bTextAsZero, const std::vector<std::unique_ptr<sc::op::Op>>& aOp)
+std::vector<ScMatrix::IterateResult> ScVectorRefMatrix::Collect(const std::vector<std::unique_ptr<sc::op::Op>>& aOp)
{
ensureFullMatrix();
- return mpFullMatrix->Collect(bTextAsZero, aOp);
+ return mpFullMatrix->Collect(aOp);
}
void ScVectorRefMatrix::ExecuteOperation(const std::pair<size_t, size_t>& rStartPos,