1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_SEGMENTTREE_HXX 25 #define SC_SEGMENTTREE_HXX 26 27 #include "address.hxx" 28 29 #include <memory> 30 31 class ScFlatBoolSegmentsImpl; 32 33 class ScFlatBoolRowSegments 34 { 35 public: 36 struct RangeData 37 { 38 SCROW mnRow1; 39 SCROW mnRow2; 40 bool mbValue; 41 }; 42 43 class ForwardIterator 44 { 45 public: 46 explicit ForwardIterator(ScFlatBoolRowSegments& rSegs); 47 48 bool getValue(SCROW nPos, bool& rVal); 49 SCROW getLastPos() const; 50 51 private: 52 ScFlatBoolRowSegments& mrSegs; 53 54 SCROW mnCurPos; 55 SCROW mnLastPos; 56 bool mbCurValue; 57 }; 58 59 class RangeIterator 60 { 61 public: 62 explicit RangeIterator(ScFlatBoolRowSegments& rSegs); 63 bool getFirst(RangeData& rRange); 64 bool getNext(RangeData& rRange); 65 private: 66 ScFlatBoolRowSegments& mrSegs; 67 }; 68 69 ScFlatBoolRowSegments(); 70 ScFlatBoolRowSegments(const ScFlatBoolRowSegments& r); 71 ~ScFlatBoolRowSegments(); 72 73 void setTrue(SCROW nRow1, SCROW nRow2); 74 void setFalse(SCROW nRow1, SCROW nRow2); 75 bool getValue(SCROW nRow); 76 bool getRangeData(SCROW nRow, RangeData& rData); 77 void removeSegment(SCROW nRow1, SCROW nRow2); 78 void insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary); 79 80 SCROW findLastNotOf(bool bValue) const; 81 82 void enableTreeSearch(bool bEnable); 83 void setInsertFromBack(bool bInsertFromBack); 84 85 private: 86 ::std::auto_ptr<ScFlatBoolSegmentsImpl> mpImpl; 87 }; 88 89 // ============================================================================ 90 91 class ScFlatBoolColSegments 92 { 93 public: 94 struct RangeData 95 { 96 SCCOL mnCol1; 97 SCCOL mnCol2; 98 bool mbValue; 99 }; 100 ScFlatBoolColSegments(); 101 ScFlatBoolColSegments(const ScFlatBoolColSegments& r); 102 ~ScFlatBoolColSegments(); 103 104 void setTrue(SCCOL nCol1, SCCOL nCol2); 105 void setFalse(SCCOL nCol1, SCCOL nCol2); 106 bool getValue(SCCOL nCol); 107 bool getRangeData(SCCOL nCol, RangeData& rData); 108 void removeSegment(SCCOL nCol1, SCCOL nCol2); 109 void insertSegment(SCCOL nCol, SCCOL nSize, bool bSkipStartBoundary); 110 111 void enableTreeSearch(bool bEnable); 112 void setInsertFromBack(bool bInsertFromBack); 113 114 private: 115 ::std::auto_ptr<ScFlatBoolSegmentsImpl> mpImpl; 116 }; 117 118 // ============================================================================ 119 120 class ScFlatUInt16SegmentsImpl; 121 122 class ScFlatUInt16RowSegments 123 { 124 public: 125 struct RangeData 126 { 127 SCROW mnRow1; 128 SCROW mnRow2; 129 sal_uInt16 mnValue; 130 }; 131 132 class ForwardIterator 133 { 134 public: 135 explicit ForwardIterator(ScFlatUInt16RowSegments& rSegs); 136 137 bool getValue(SCROW nPos, sal_uInt16& rVal); 138 SCROW getLastPos() const; 139 140 private: 141 ScFlatUInt16RowSegments& mrSegs; 142 143 SCROW mnCurPos; 144 SCROW mnLastPos; 145 sal_uInt16 mnCurValue; 146 }; 147 148 ScFlatUInt16RowSegments(sal_uInt16 nDefault); 149 ScFlatUInt16RowSegments(const ScFlatUInt16RowSegments& r); 150 ~ScFlatUInt16RowSegments(); 151 152 void setValue(SCROW nRow1, SCROW nRow2, sal_uInt16 nValue); 153 sal_uInt16 getValue(SCROW nRow); 154 sal_uInt32 getSumValue(SCROW nRow1, SCROW nRow2); 155 bool getRangeData(SCROW nRow, RangeData& rData); 156 void removeSegment(SCROW nRow1, SCROW nRow2); 157 void insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary); 158 159 SCROW findLastNotOf(sal_uInt16 nValue) const; 160 161 void enableTreeSearch(bool bEnable); 162 void setInsertFromBack(bool bInsertFromBack); 163 164 private: 165 ::std::auto_ptr<ScFlatUInt16SegmentsImpl> mpImpl; 166 }; 167 168 #endif 169