diff options
author | Tor Lillqvist <tml@collabora.com> | 2017-06-06 19:37:16 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2017-06-06 21:11:41 +0300 |
commit | c2b256084b086b63a13d16f65d1be2966f4febb3 (patch) | |
tree | 7bb756a868268e98bb5fbc95984c56078cc80ffc /formula | |
parent | 8d998ae06a742033d4a343e6daae7285a2a3207b (diff) |
Partial start of separating the iterator out from FormulaTokenArray
The plan is to drop the iterator functionality from FormulaTokenArray
and instead use separate iterator objects. This will make
parallelising code that uses these data structures easier. I call the
new separate iterator class FormulaTokenArrayPlainIterator for now,
feel free to come up with a better name.
No change to what code actually gets run yet, so yeah, this adds
"unused" code.
Change-Id: Ie86f80529354174f0ce8bde1085a54bc6c5ac67b
Diffstat (limited to 'formula')
-rw-r--r-- | formula/source/core/api/token.cxx | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index 63afd00cfc36..703c0eca5c29 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -1757,6 +1757,173 @@ bool FormulaTokenIterator::IsEndOfPath() const return GetNonEndOfPathToken( maStack.back().nPC + 1) == nullptr; } +FormulaToken* FormulaTokenArrayPlainIterator::GetNextReference() +{ + while( mnIndex < mrFTA.nLen ) + { + FormulaToken* t = mrFTA.pCode[ mnIndex++ ]; + switch( t->GetType() ) + { + case svSingleRef: + case svDoubleRef: + case svExternalSingleRef: + case svExternalDoubleRef: + return t; + default: + { + // added to avoid warnings + } + } + } + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::GetNextColRowName() +{ + while( mnIndex < mrFTA.nLen ) + { + FormulaToken* t = mrFTA.pCode[ mnIndex++ ]; + if ( t->GetOpCode() == ocColRowName ) + return t; + } + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceRPN() +{ + while( mnIndex < mrFTA.nRPN ) + { + FormulaToken* t = mrFTA.pRPN[ mnIndex++ ]; + switch( t->GetType() ) + { + case svSingleRef: + case svDoubleRef: + case svExternalSingleRef: + case svExternalDoubleRef: + return t; + default: + { + // added to avoid warnings + } + } + } + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceOrName() +{ + if( mrFTA.pCode ) + { + while ( mnIndex < mrFTA.nLen ) + { + FormulaToken* t = mrFTA.pCode[ mnIndex++ ]; + switch( t->GetType() ) + { + case svSingleRef: + case svDoubleRef: + case svIndex: + case svExternalSingleRef: + case svExternalDoubleRef: + case svExternalName: + return t; + default: + { + // added to avoid warnings + } + } + } + } + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::Next() +{ + if( mrFTA.pCode && mnIndex < mrFTA.nLen ) + return mrFTA.pCode[ mnIndex++ ]; + else + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::NextNoSpaces() +{ + if( mrFTA.pCode ) + { + while( (mnIndex < mrFTA.nLen) && (mrFTA.pCode[ mnIndex ]->GetOpCode() == ocSpaces) ) + ++mnIndex; + if( mnIndex < mrFTA.nLen ) + return mrFTA.pCode[ mnIndex++ ]; + } + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::NextRPN() +{ + if( mrFTA.pRPN && mnIndex < mrFTA.nRPN ) + return mrFTA.pRPN[ mnIndex++ ]; + else + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::PrevRPN() +{ + if( mrFTA.pRPN && mnIndex ) + return mrFTA.pRPN[ --mnIndex ]; + else + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::PeekNext() +{ + if( mrFTA.pCode && mnIndex < mrFTA.nLen ) + return mrFTA.pCode[ mnIndex ]; + else + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::PeekNextNoSpaces() const +{ + if( mrFTA.pCode && mnIndex < mrFTA.nLen ) + { + sal_uInt16 j = mnIndex; + while ( j < mrFTA.nLen && mrFTA.pCode[j]->GetOpCode() == ocSpaces ) + j++; + if ( j < mrFTA.nLen ) + return mrFTA.pCode[ j ]; + else + return nullptr; + } + else + return nullptr; +} + +FormulaToken* FormulaTokenArrayPlainIterator::PeekPrevNoSpaces() const +{ + if( mrFTA.pCode && mnIndex > 1 ) + { + sal_uInt16 j = mnIndex - 2; + while ( mrFTA.pCode[j]->GetOpCode() == ocSpaces && j > 0 ) + j--; + if ( j > 0 || mrFTA.pCode[j]->GetOpCode() != ocSpaces ) + return mrFTA.pCode[ j ]; + else + return nullptr; + } + else + return nullptr; +} + +void FormulaTokenArrayPlainIterator::AfterRemoveToken( sal_uInt16 nOffset, sal_uInt16 nCount ) +{ + const sal_uInt16 nStop = std::min( static_cast<sal_uInt16>(nOffset + nCount), mrFTA.nLen); + + if (mnIndex >= nOffset) + { + if (mnIndex < nStop) + mnIndex = nOffset + 1; + else + mnIndex -= nStop - nOffset; + } +} // real implementations of virtual functions |