diff options
Diffstat (limited to 'sc/inc/compressedarray.hxx')
-rw-r--r-- | sc/inc/compressedarray.hxx | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/sc/inc/compressedarray.hxx b/sc/inc/compressedarray.hxx index e95c036991e7..86063049b774 100644 --- a/sc/inc/compressedarray.hxx +++ b/sc/inc/compressedarray.hxx @@ -29,7 +29,7 @@ const size_t nScCompressedArrayDelta = 4; /** Compressed array of row (or column) entries, e.g. heights, flags, ... - The array stores ranges of values such that consecutive values occupy only + The array stores ranges of values such that equal consecutive values occupy only one entry. Initially it consists of one DataEntry with an implied start row/column of 0 and an end row/column of access type maximum value. @@ -48,6 +48,19 @@ const size_t nScCompressedArrayDelta = 4; template< typename A, typename D > class ScCompressedArray { public: + class Iterator + { + friend ScCompressedArray; + const ScCompressedArray& mrArray; + size_t mnIndex = 0; + A mnRegion = 0; + Iterator(const ScCompressedArray& rArray) : mrArray(rArray) {} + Iterator(const ScCompressedArray& rArray, size_t nIndex, A nRegion) : mrArray(rArray), mnIndex(nIndex), mnRegion(nRegion) {} + public: + void operator++(); + Iterator operator+(size_t) const; + const D & operator*() const { return mrArray.pData[mnIndex].aValue; } + }; struct DataEntry { A nEnd; // start is end of previous entry + 1 @@ -67,30 +80,42 @@ public: void Reset( const D& rValue ); void SetValue( A nPos, const D& rValue ); void SetValue( A nStart, A nEnd, const D& rValue ); + SAL_WARN_UNUSED_RESULT const D& GetValue( A nPos ) const; + SAL_WARN_UNUSED_RESULT + A GetLastPos() const { return pData[nCount-1].nEnd; } /** Get value for a row, and it's region end row */ + SAL_WARN_UNUSED_RESULT const D& GetValue( A nPos, size_t& nIndex, A& nEnd ) const; /** Get next value and it's region end row. If nIndex<nCount, nIndex is incremented first. If the resulting nIndex>=nCount, the value of the last entry is returned again. */ + SAL_WARN_UNUSED_RESULT const D& GetNextValue( size_t& nIndex, A& nEnd ) const; /** Insert rows before nStart and copy value for inserted rows from nStart-1, return that value. */ const D& Insert( A nStart, size_t nCount ); + void InsertPreservingSize( A nStart, size_t nCount, const D& rFillValue ); void Remove( A nStart, size_t nCount ); + void RemovePreservingSize( A nStart, size_t nCount, const D& rFillValue ); /** Copy rArray.nStart+nSourceDy to this.nStart */ void CopyFrom( const ScCompressedArray& rArray, - A nStart, A nEnd ); + A nStart, A nEnd ) + { CopyFrom(rArray, nStart, nEnd, nStart); } + void CopyFrom( const ScCompressedArray& rArray, + A nDestStart, A nDestEnd, A nSrcStart ); // methods public for the coupled array sum methods /** Obtain index into entries for nPos */ SC_DLLPUBLIC size_t Search( A nPos ) const; + Iterator begin() const { return Iterator(*this); } + protected: size_t nCount; size_t nLimit; |