LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / inc / bigrange.hxx
blobb921cfcd4dfaf5d8d8bd4cca08df5218c563ff48
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include "address.hxx"
23 #include <algorithm>
24 #include "document.hxx"
26 // This is used by change tracking. References there may be located also outside of the document
27 // (see ScRefUpdate::Update()), and so it needs bigger range than ScAddress/ScRange.
29 class ScBigAddress
31 sal_Int64 nRow;
32 sal_Int64 nCol;
33 sal_Int64 nTab;
35 public:
36 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
37 ScBigAddress( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
38 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
39 ScBigAddress( const ScBigAddress& r )
40 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
41 ScBigAddress( ScBigAddress&& ) = default;
42 ScBigAddress( const ScAddress& r )
43 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
45 sal_Int64 Col() const { return nCol; }
46 sal_Int64 Row() const { return nRow; }
47 sal_Int64 Tab() const { return nTab; }
49 void Set( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
50 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
51 void SetCol( sal_Int64 nColP ) { nCol = nColP; }
52 void SetRow( sal_Int64 nRowP ) { nRow = nRowP; }
53 void SetTab( sal_Int64 nTabP ) { nTab = nTabP; }
54 void IncCol( sal_Int64 n = 1 ) { nCol += n; }
55 void IncRow( sal_Int64 n = 1 ) { nRow += n; }
56 void IncTab( sal_Int64 n = 1 ) { nTab += n; }
58 void GetVars( sal_Int64& nColP, sal_Int64& nRowP, sal_Int64& nTabP ) const
59 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
61 bool IsValid( const ScDocument& rDoc ) const;
62 inline ScAddress MakeAddress( const ScDocument& rDoc ) const;
64 ScBigAddress& operator=( const ScBigAddress& r )
65 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
66 ScBigAddress& operator=( ScBigAddress&& ) = default;
67 ScBigAddress& operator=( const ScAddress& r )
68 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
69 bool operator==( const ScBigAddress& r ) const
70 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
71 bool operator!=( const ScBigAddress& r ) const
72 { return !operator==( r ); }
75 inline ScAddress ScBigAddress::MakeAddress( const ScDocument& rDoc ) const
77 SCCOL nColA;
78 SCROW nRowA;
79 SCTAB nTabA;
81 if ( nCol < 0 )
82 nColA = 0;
83 else if ( nCol > rDoc.MaxCol() )
84 nColA = rDoc.MaxCol();
85 else
86 nColA = static_cast<SCCOL>(nCol);
88 if ( nRow < 0 )
89 nRowA = 0;
90 else if ( nRow > rDoc.MaxRow() )
91 nRowA = rDoc.MaxRow();
92 else
93 nRowA = static_cast<SCROW>(nRow);
95 if ( nTab < 0 )
96 nTabA = 0;
97 else if ( nTab > MAXTAB )
98 nTabA = MAXTAB;
99 else
100 nTabA = static_cast<SCTAB>(nTab);
102 return ScAddress( nColA, nRowA, nTabA );
105 class ScBigRange
107 public:
109 ScBigAddress aStart;
110 ScBigAddress aEnd;
112 ScBigRange() : aStart(), aEnd() {}
113 ScBigRange( const ScBigRange& r )
114 : aStart( r.aStart ), aEnd( r.aEnd ) {}
115 ScBigRange( ScBigRange&& ) = default;
116 ScBigRange( const ScRange& r )
117 : aStart( r.aStart ), aEnd( r.aEnd ) {}
118 ScBigRange( sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1,
119 sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2 )
120 : aStart( nCol1, nRow1, nTab1 ),
121 aEnd( nCol2, nRow2, nTab2 ) {}
123 void Set( sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1,
124 sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2 )
125 { aStart.Set( nCol1, nRow1, nTab1 );
126 aEnd.Set( nCol2, nRow2, nTab2 ); }
128 void GetVars( sal_Int64& nCol1, sal_Int64& nRow1, sal_Int64& nTab1,
129 sal_Int64& nCol2, sal_Int64& nRow2, sal_Int64& nTab2 ) const
130 { aStart.GetVars( nCol1, nRow1, nTab1 );
131 aEnd.GetVars( nCol2, nRow2, nTab2 ); }
133 bool IsValid( const ScDocument& rDoc ) const
134 { return aStart.IsValid( rDoc ) && aEnd.IsValid( rDoc ); }
135 ScRange MakeRange( const ScDocument& rDoc ) const
136 { return ScRange( aStart.MakeAddress( rDoc ), aEnd.MakeAddress( rDoc ) ); }
138 inline bool In( const ScBigAddress& ) const; ///< is Address& in range?
139 inline bool In( const ScBigRange& ) const; ///< is Range& in range?
140 inline bool Intersects( const ScBigRange& ) const; ///< do two ranges overlap?
142 ScBigRange& operator=( const ScBigRange& r )
143 { aStart = r.aStart; aEnd = r.aEnd; return *this; }
144 ScBigRange& operator=( ScBigRange&& ) = default;
145 bool operator==( const ScBigRange& r ) const
146 { return (aStart == r.aStart) && (aEnd == r.aEnd); }
147 bool operator!=( const ScBigRange& r ) const
148 { return !operator==( r ); }
150 // These are used to define whole rows/cols/tabs.
151 constexpr static sal_Int64 nRangeMin = ::std::numeric_limits<sal_Int64>::min();;
152 constexpr static sal_Int64 nRangeMax = ::std::numeric_limits<sal_Int64>::max();;
155 inline bool ScBigRange::In( const ScBigAddress& rAddr ) const
157 return
158 aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
159 aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
160 aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
163 inline bool ScBigRange::In( const ScBigRange& r ) const
165 return
166 aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
167 aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
168 aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
171 inline bool ScBigRange::Intersects( const ScBigRange& r ) const
173 return !(
174 std::min( aEnd.Col(), r.aEnd.Col() ) < std::max( aStart.Col(), r.aStart.Col() )
175 || std::min( aEnd.Row(), r.aEnd.Row() ) < std::max( aStart.Row(), r.aStart.Row() )
176 || std::min( aEnd.Tab(), r.aEnd.Tab() ) < std::max( aStart.Tab(), r.aStart.Tab() )
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */