1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_SEGMENTTREE_HXX 29 #define SC_SEGMENTTREE_HXX 30 31 #include "address.hxx" 32 33 #include <memory> 34 35 class ScFlatBoolSegmentsImpl; 36 37 class ScFlatBoolRowSegments 38 { 39 public: 40 struct RangeData 41 { 42 SCROW mnRow1; 43 SCROW mnRow2; 44 bool mbValue; 45 }; 46 47 class ForwardIterator 48 { 49 public: 50 explicit ForwardIterator(ScFlatBoolRowSegments& rSegs); 51 52 bool getValue(SCROW nPos, bool& rVal); 53 SCROW getLastPos() const; 54 55 private: 56 ScFlatBoolRowSegments& mrSegs; 57 58 SCROW mnCurPos; 59 SCROW mnLastPos; 60 bool mbCurValue; 61 }; 62 63 class RangeIterator 64 { 65 public: 66 explicit RangeIterator(ScFlatBoolRowSegments& rSegs); 67 bool getFirst(RangeData& rRange); 68 bool getNext(RangeData& rRange); 69 private: 70 ScFlatBoolRowSegments& mrSegs; 71 }; 72 73 ScFlatBoolRowSegments(); 74 ScFlatBoolRowSegments(const ScFlatBoolRowSegments& r); 75 ~ScFlatBoolRowSegments(); 76 77 void setTrue(SCROW nRow1, SCROW nRow2); 78 void setFalse(SCROW nRow1, SCROW nRow2); 79 bool getValue(SCROW nRow); 80 bool getRangeData(SCROW nRow, RangeData& rData); 81 void removeSegment(SCROW nRow1, SCROW nRow2); 82 void insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary); 83 84 SCROW findLastNotOf(bool bValue) const; 85 86 void enableTreeSearch(bool bEnable); 87 void setInsertFromBack(bool bInsertFromBack); 88 89 private: 90 ::std::auto_ptr<ScFlatBoolSegmentsImpl> mpImpl; 91 }; 92 93 // ============================================================================ 94 95 class ScFlatBoolColSegments 96 { 97 public: 98 struct RangeData 99 { 100 SCCOL mnCol1; 101 SCCOL mnCol2; 102 bool mbValue; 103 }; 104 ScFlatBoolColSegments(); 105 ScFlatBoolColSegments(const ScFlatBoolColSegments& r); 106 ~ScFlatBoolColSegments(); 107 108 void setTrue(SCCOL nCol1, SCCOL nCol2); 109 void setFalse(SCCOL nCol1, SCCOL nCol2); 110 bool getValue(SCCOL nCol); 111 bool getRangeData(SCCOL nCol, RangeData& rData); 112 void removeSegment(SCCOL nCol1, SCCOL nCol2); 113 void insertSegment(SCCOL nCol, SCCOL nSize, bool bSkipStartBoundary); 114 115 void enableTreeSearch(bool bEnable); 116 void setInsertFromBack(bool bInsertFromBack); 117 118 private: 119 ::std::auto_ptr<ScFlatBoolSegmentsImpl> mpImpl; 120 }; 121 122 // ============================================================================ 123 124 class ScFlatUInt16SegmentsImpl; 125 126 class ScFlatUInt16RowSegments 127 { 128 public: 129 struct RangeData 130 { 131 SCROW mnRow1; 132 SCROW mnRow2; 133 sal_uInt16 mnValue; 134 }; 135 136 class ForwardIterator 137 { 138 public: 139 explicit ForwardIterator(ScFlatUInt16RowSegments& rSegs); 140 141 bool getValue(SCROW nPos, sal_uInt16& rVal); 142 SCROW getLastPos() const; 143 144 private: 145 ScFlatUInt16RowSegments& mrSegs; 146 147 SCROW mnCurPos; 148 SCROW mnLastPos; 149 sal_uInt16 mnCurValue; 150 }; 151 152 ScFlatUInt16RowSegments(sal_uInt16 nDefault); 153 ScFlatUInt16RowSegments(const ScFlatUInt16RowSegments& r); 154 ~ScFlatUInt16RowSegments(); 155 156 void setValue(SCROW nRow1, SCROW nRow2, sal_uInt16 nValue); 157 sal_uInt16 getValue(SCROW nRow); 158 sal_uInt32 getSumValue(SCROW nRow1, SCROW nRow2); 159 bool getRangeData(SCROW nRow, RangeData& rData); 160 void removeSegment(SCROW nRow1, SCROW nRow2); 161 void insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary); 162 163 SCROW findLastNotOf(sal_uInt16 nValue) const; 164 165 void enableTreeSearch(bool bEnable); 166 void setInsertFromBack(bool bInsertFromBack); 167 168 private: 169 ::std::auto_ptr<ScFlatUInt16SegmentsImpl> mpImpl; 170 }; 171 172 #endif 173