1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SC_BIGRANGE_HXX
21 #define SC_BIGRANGE_HXX
25 static const sal_Int32 nInt32Min
= 0x80000000;
26 static const sal_Int32 nInt32Max
= 0x7fffffff;
37 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
38 ScBigAddress( sal_Int32 nColP
, sal_Int32 nRowP
, sal_Int32 nTabP
)
39 : nRow( nRowP
), nCol( nColP
), nTab( nTabP
) {}
40 ScBigAddress( const ScBigAddress
& r
)
41 : nRow( r
.nRow
), nCol( r
.nCol
), nTab( r
.nTab
) {}
42 ScBigAddress( const ScAddress
& r
)
43 : nRow( r
.Row() ), nCol( r
.Col() ), nTab( r
.Tab() ) {}
45 sal_Int32
Col() const { return nCol
; }
46 sal_Int32
Row() const { return nRow
; }
47 sal_Int32
Tab() const { return nTab
; }
49 void Set( sal_Int32 nColP
, sal_Int32 nRowP
, sal_Int32 nTabP
)
50 { nCol
= nColP
; nRow
= nRowP
; nTab
= nTabP
; }
51 void SetCol( sal_Int32 nColP
) { nCol
= nColP
; }
52 void SetRow( sal_Int32 nRowP
) { nRow
= nRowP
; }
53 void SetTab( sal_Int32 nTabP
) { nTab
= nTabP
; }
54 void IncCol( sal_Int32 n
= 1 ) { nCol
+= n
; }
55 void IncRow( sal_Int32 n
= 1 ) { nRow
+= n
; }
56 void IncTab( sal_Int32 n
= 1 ) { nTab
+= n
; }
58 void GetVars( sal_Int32
& nColP
, sal_Int32
& nRowP
, sal_Int32
& nTabP
) const
59 { nColP
= nCol
; nRowP
= nRow
; nTabP
= nTab
; }
61 inline void PutInOrder( ScBigAddress
& r
);
62 bool IsValid( const ScDocument
* pDoc
) const;
63 inline ScAddress
MakeAddress() const;
65 ScBigAddress
& operator=( const ScBigAddress
& r
)
66 { nCol
= r
.nCol
; nRow
= r
.nRow
; nTab
= r
.nTab
; return *this; }
67 ScBigAddress
& operator=( const ScAddress
& r
)
68 { nCol
= r
.Col(); nRow
= r
.Row(); nTab
= r
.Tab(); return *this; }
69 int operator==( const ScBigAddress
& r
) const
70 { return nCol
== r
.nCol
&& nRow
== r
.nRow
&& nTab
== r
.nTab
; }
71 int operator!=( const ScBigAddress
& r
) const
72 { return !operator==( r
); }
74 friend inline SvStream
& operator<< ( SvStream
& rStream
, const ScBigAddress
& rAdr
);
75 friend inline SvStream
& operator>> ( SvStream
& rStream
, ScBigAddress
& rAdr
);
79 inline void ScBigAddress::PutInOrder( ScBigAddress
& r
)
102 inline ScAddress
ScBigAddress::MakeAddress() const
110 else if ( nCol
> MAXCOL
)
113 nColA
= (SCCOL
) nCol
;
117 else if ( nRow
> MAXROW
)
120 nRowA
= (SCROW
) nRow
;
124 else if ( nTab
> MAXTAB
)
127 nTabA
= (SCTAB
) nTab
;
129 return ScAddress( nColA
, nRowA
, nTabA
);
133 inline SvStream
& operator<< ( SvStream
& rStream
, const ScBigAddress
& rAdr
)
135 rStream
<< rAdr
.nCol
<< rAdr
.nRow
<< rAdr
.nTab
;
140 inline SvStream
& operator>> ( SvStream
& rStream
, ScBigAddress
& rAdr
)
142 rStream
>> rAdr
.nCol
>> rAdr
.nRow
>> rAdr
.nTab
;
154 ScBigRange() : aStart(), aEnd() {}
155 ScBigRange( const ScBigAddress
& s
, const ScBigAddress
& e
)
156 : aStart( s
), aEnd( e
) { aStart
.PutInOrder( aEnd
); }
157 ScBigRange( const ScBigRange
& r
)
158 : aStart( r
.aStart
), aEnd( r
.aEnd
) {}
159 ScBigRange( const ScRange
& r
)
160 : aStart( r
.aStart
), aEnd( r
.aEnd
) {}
161 ScBigRange( const ScBigAddress
& r
)
162 : aStart( r
), aEnd( r
) {}
163 ScBigRange( const ScAddress
& r
)
164 : aStart( r
), aEnd( r
) {}
165 ScBigRange( sal_Int32 nCol
, sal_Int32 nRow
, sal_Int32 nTab
)
166 : aStart( nCol
, nRow
, nTab
), aEnd( aStart
) {}
167 ScBigRange( sal_Int32 nCol1
, sal_Int32 nRow1
, sal_Int32 nTab1
,
168 sal_Int32 nCol2
, sal_Int32 nRow2
, sal_Int32 nTab2
)
169 : aStart( nCol1
, nRow1
, nTab1
),
170 aEnd( nCol2
, nRow2
, nTab2
) {}
172 void Set( sal_Int32 nCol1
, sal_Int32 nRow1
, sal_Int32 nTab1
,
173 sal_Int32 nCol2
, sal_Int32 nRow2
, sal_Int32 nTab2
)
174 { aStart
.Set( nCol1
, nRow1
, nTab1
);
175 aEnd
.Set( nCol2
, nRow2
, nTab2
); }
177 void GetVars( sal_Int32
& nCol1
, sal_Int32
& nRow1
, sal_Int32
& nTab1
,
178 sal_Int32
& nCol2
, sal_Int32
& nRow2
, sal_Int32
& nTab2
) const
179 { aStart
.GetVars( nCol1
, nRow1
, nTab1
);
180 aEnd
.GetVars( nCol2
, nRow2
, nTab2
); }
182 sal_Bool
IsValid( const ScDocument
* pDoc
) const
183 { return aStart
.IsValid( pDoc
) && aEnd
.IsValid( pDoc
); }
184 inline ScRange
MakeRange() const
185 { return ScRange( aStart
.MakeAddress(),
186 aEnd
.MakeAddress() ); }
188 inline sal_Bool
In( const ScBigAddress
& ) const; ///< is Address& in range?
189 inline sal_Bool
In( const ScBigRange
& ) const; ///< is Range& in range?
190 inline sal_Bool
Intersects( const ScBigRange
& ) const; ///< do two ranges overlap?
192 ScBigRange
& operator=( const ScBigRange
& r
)
193 { aStart
= r
.aStart
; aEnd
= r
.aEnd
; return *this; }
194 int operator==( const ScBigRange
& r
) const
195 { return (aStart
== r
.aStart
) && (aEnd
== r
.aEnd
); }
196 int operator!=( const ScBigRange
& r
) const
197 { return !operator==( r
); }
199 friend inline SvStream
& operator<< ( SvStream
& rStream
, const ScBigRange
& rRange
);
200 friend inline SvStream
& operator>> ( SvStream
& rStream
, ScBigRange
& rRange
);
204 inline sal_Bool
ScBigRange::In( const ScBigAddress
& rAddr
) const
207 aStart
.Col() <= rAddr
.Col() && rAddr
.Col() <= aEnd
.Col() &&
208 aStart
.Row() <= rAddr
.Row() && rAddr
.Row() <= aEnd
.Row() &&
209 aStart
.Tab() <= rAddr
.Tab() && rAddr
.Tab() <= aEnd
.Tab();
213 inline sal_Bool
ScBigRange::In( const ScBigRange
& r
) const
216 aStart
.Col() <= r
.aStart
.Col() && r
.aEnd
.Col() <= aEnd
.Col() &&
217 aStart
.Row() <= r
.aStart
.Row() && r
.aEnd
.Row() <= aEnd
.Row() &&
218 aStart
.Tab() <= r
.aStart
.Tab() && r
.aEnd
.Tab() <= aEnd
.Tab();
222 inline sal_Bool
ScBigRange::Intersects( const ScBigRange
& r
) const
225 std::min( aEnd
.Col(), r
.aEnd
.Col() ) < std::max( aStart
.Col(), r
.aStart
.Col() )
226 || std::min( aEnd
.Row(), r
.aEnd
.Row() ) < std::max( aStart
.Row(), r
.aStart
.Row() )
227 || std::min( aEnd
.Tab(), r
.aEnd
.Tab() ) < std::max( aStart
.Tab(), r
.aStart
.Tab() )
232 inline SvStream
& operator<< ( SvStream
& rStream
, const ScBigRange
& rRange
)
234 rStream
<< rRange
.aStart
;
235 rStream
<< rRange
.aEnd
;
240 inline SvStream
& operator>> ( SvStream
& rStream
, ScBigRange
& rRange
)
242 rStream
>> rRange
.aStart
;
243 rStream
>> rRange
.aEnd
;
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */