summaryrefslogtreecommitdiff
path: root/include/formula
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2017-06-19 19:56:48 +0300
committerTor Lillqvist <tml@collabora.com>2017-06-22 12:28:27 +0200
commit4e27d3cf6bcb278f26878ef7070723dd8a799a03 (patch)
tree257e00ba9682463d45e462f2fa60e8d2b08af12a /include/formula
parente751e24250fda31dde52b3c65ca79f86142dc789 (diff)
Introduce a range-based iterator for 'references' in a FormulaTokenArray
Take it into use in a couple of places. Change-Id: I72127f4236220fbe6fbf9ea25cdd56470be89961 Reviewed-on: https://gerrit.libreoffice.org/38997 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include/formula')
-rw-r--r--include/formula/tokenarray.hxx106
1 files changed, 106 insertions, 0 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