diff options
-rw-r--r-- | include/formula/tokenarray.hxx | 106 | ||||
-rw-r--r-- | sc/source/core/data/colorscale.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/conditio.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 15 |
4 files changed, 112 insertions, 17 deletions
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index eb04f041abd8..eed55d089921 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -136,6 +136,97 @@ public: } }; +class FORMULA_DLLPUBLIC FormulaTokenArrayReferencesIterator +{ +private: + FormulaToken** maIter; + FormulaToken** maEnd; + + void nextReference() + { + while (maIter != maEnd) + { + switch ((*maIter)->GetType()) + { + case svSingleRef: + case svDoubleRef: + case svExternalSingleRef: + case svExternalDoubleRef: + return; + default: + ++maIter; + } + } + } + + enum class Dummy { Flag }; + + FormulaTokenArrayReferencesIterator(const FormulaTokenArrayStandardRange& rRange, Dummy) : + maIter(rRange.end()), + maEnd(rRange.end()) + { + } + +public: + FormulaTokenArrayReferencesIterator(const FormulaTokenArrayStandardRange& rRange) : + maIter(rRange.begin()), + maEnd(rRange.end()) + { + nextReference(); + } + + FormulaTokenArrayReferencesIterator operator++(int) + { + FormulaTokenArrayReferencesIterator result(*this); + operator++(); + return result; + } + + FormulaTokenArrayReferencesIterator operator++() + { + assert(maIter != maEnd); + ++maIter; + nextReference(); + return *this; + } + + FormulaToken* operator*() const + { + return *maIter; + } + + bool operator==(const FormulaTokenArrayReferencesIterator& rhs) const + { + return maIter == rhs.maIter; + } + + bool operator!=(const FormulaTokenArrayReferencesIterator& rhs) const + { + return !operator==(rhs); + } + + static FormulaTokenArrayReferencesIterator endOf(const FormulaTokenArrayStandardRange& rRange) + { + return FormulaTokenArrayReferencesIterator(rRange, Dummy::Flag); + } +}; + +class FORMULA_DLLPUBLIC FormulaTokenArrayReferencesRange +{ +private: + const FormulaTokenArray& mrFTA; + +public: + FormulaTokenArrayReferencesRange(const FormulaTokenArray& rFTA) : + mrFTA(rFTA) + { + } + + FormulaTokenArrayReferencesIterator begin(); + + FormulaTokenArrayReferencesIterator end(); +}; + class FORMULA_DLLPUBLIC FormulaTokenArray { protected: @@ -284,6 +375,11 @@ public: return FormulaTokenArrayStandardRange(pRPN, nRPN); } + FormulaTokenArrayReferencesRange References() const + { + return FormulaTokenArrayReferencesRange(*this); + } + sal_uInt16 GetLen() const { return nLen; } sal_uInt16 GetCodeLen() const { return nRPN; } FormulaError GetCodeError() const { return nError; } @@ -401,6 +497,16 @@ inline OpCode FormulaTokenArray::GetOuterFuncOpCode() return ocNone; } +inline FormulaTokenArrayReferencesIterator FormulaTokenArrayReferencesRange::begin() +{ + return FormulaTokenArrayReferencesIterator(mrFTA.Tokens()); +} + +inline FormulaTokenArrayReferencesIterator FormulaTokenArrayReferencesRange::end() +{ + return FormulaTokenArrayReferencesIterator::endOf(mrFTA.Tokens()); +} + class FORMULA_DLLPUBLIC FormulaTokenIterator { struct Item diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 2a7b213de2a3..d14b0622be54 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -41,9 +41,7 @@ void ScFormulaListener::startListening(ScTokenArray* pArr, const ScRange& rRange if (!pArr || mpDoc->IsClipOrUndo()) return; - formula::FormulaToken* t; - formula::FormulaTokenArrayPlainIterator aIter( *pArr ); - while ( ( t = aIter.GetNextReference() ) != nullptr ) + for ( auto t: pArr->References() ) { switch (t->GetType()) { diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 6ca66da581cb..eab769e70b0d 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1418,9 +1418,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const ScTokenArray* pFormula = nPass ? pFormula2 : pFormula1; if (pFormula) { - formula::FormulaTokenArrayPlainIterator aIter(*pFormula); - formula::FormulaToken* t; - while ( ( t = aIter.GetNextReference() ) != nullptr ) + for ( auto t: pFormula->References() ) { ScSingleRefData& rRef1 = *t->GetSingleRef(); ScAddress aAbs = rRef1.toAbs(aSrcPos); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index d373516899fd..e8284bc8fa37 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4808,8 +4808,7 @@ bool ScCompiler::HandleExternalReference(const FormulaToken& _aToken) void ScCompiler::AdjustSheetLocalNameRelReferences( SCTAB nDelta ) { - maArrIterator.Reset(); - for (formula::FormulaToken* t = maArrIterator.GetNextReference(); t; t = maArrIterator.GetNextReference()) + for ( auto t: pArr->References() ) { ScSingleRefData& rRef1 = *t->GetSingleRef(); if (rRef1.IsTabRel()) @@ -4827,9 +4826,7 @@ void ScCompiler::AdjustSheetLocalNameRelReferences( SCTAB nDelta ) void ScCompiler::SetRelNameReference() { - maArrIterator.Reset(); - for( formula::FormulaToken* t = maArrIterator.GetNextReference(); t; - t = maArrIterator.GetNextReference() ) + for ( auto t: pArr->References() ) { ScSingleRefData& rRef1 = *t->GetSingleRef(); if ( rRef1.IsColRel() || rRef1.IsRowRel() || rRef1.IsTabRel() ) @@ -4847,9 +4844,7 @@ void ScCompiler::SetRelNameReference() // don't call for other token arrays! void ScCompiler::MoveRelWrap( SCCOL nMaxCol, SCROW nMaxRow ) { - maArrIterator.Reset(); - for( formula::FormulaToken* t = maArrIterator.GetNextReference(); t; - t = maArrIterator.GetNextReference() ) + for ( auto t: pArr->References() ) { if ( t->GetType() == svSingleRef || t->GetType() == svExternalSingleRef ) ScRefUpdate::MoveRelWrap( pDoc, aPos, nMaxCol, nMaxRow, SingleDoubleRefModifier( *t->GetSingleRef() ).Ref() ); @@ -4863,9 +4858,7 @@ void ScCompiler::MoveRelWrap( SCCOL nMaxCol, SCROW nMaxRow ) void ScCompiler::MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) { - formula::FormulaTokenArrayPlainIterator aIter(rArr); - for( formula::FormulaToken* t = aIter.GetNextReference(); t; - t = aIter.GetNextReference() ) + for ( auto t: rArr.References() ) { if ( t->GetType() == svSingleRef || t->GetType() == svExternalSingleRef ) ScRefUpdate::MoveRelWrap( pDoc, rPos, nMaxCol, nMaxRow, SingleDoubleRefModifier( *t->GetSingleRef() ).Ref() ); |