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