LibreOffice Module sc (master)  1
bigrange.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include "address.hxx"
23 #include "document.hxx"
24 
25 // This is used by change tracking. References there may be located also outside of the document
26 // (see ScRefUpdate::Update()), and so it needs bigger range than ScAddress/ScRange.
27 
29 {
30  sal_Int64 nRow;
31  sal_Int64 nCol;
32  sal_Int64 nTab;
33 
34 public:
35  ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
36  ScBigAddress( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
37  : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
39  : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
40  ScBigAddress( ScBigAddress&& ) = default;
41  ScBigAddress( const ScAddress& r )
42  : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
43 
44  sal_Int64 Col() const { return nCol; }
45  sal_Int64 Row() const { return nRow; }
46  sal_Int64 Tab() const { return nTab; }
47 
48  void Set( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
49  { nCol = nColP; nRow = nRowP; nTab = nTabP; }
50  void SetCol( sal_Int64 nColP ) { nCol = nColP; }
51  void SetRow( sal_Int64 nRowP ) { nRow = nRowP; }
52  void SetTab( sal_Int64 nTabP ) { nTab = nTabP; }
53  void IncCol( sal_Int64 n = 1 ) { nCol += n; }
54  void IncRow( sal_Int64 n = 1 ) { nRow += n; }
55  void IncTab( sal_Int64 n = 1 ) { nTab += n; }
56 
57  void GetVars( sal_Int64& nColP, sal_Int64& nRowP, sal_Int64& nTabP ) const
58  { nColP = nCol; nRowP = nRow; nTabP = nTab; }
59 
60  bool IsValid( const ScDocument& rDoc ) const;
61  inline ScAddress MakeAddress( const ScDocument& rDoc ) const;
62 
64  { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
65  ScBigAddress& operator=( ScBigAddress&& ) = default;
67  { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
68  bool operator==( const ScBigAddress& r ) const
69  { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
70  bool operator!=( const ScBigAddress& r ) const
71  { return !operator==( r ); }
72 };
73 
74 inline ScAddress ScBigAddress::MakeAddress( const ScDocument& rDoc ) const
75 {
76  SCCOL nColA;
77  SCROW nRowA;
78  SCTAB nTabA;
79 
80  if ( nCol < 0 )
81  nColA = 0;
82  else if ( nCol > rDoc.MaxCol() )
83  nColA = rDoc.MaxCol();
84  else
85  nColA = static_cast<SCCOL>(nCol);
86 
87  if ( nRow < 0 )
88  nRowA = 0;
89  else if ( nRow > rDoc.MaxRow() )
90  nRowA = rDoc.MaxRow();
91  else
92  nRowA = static_cast<SCROW>(nRow);
93 
94  if ( nTab < 0 )
95  nTabA = 0;
96  else if ( nTab > MAXTAB )
97  nTabA = MAXTAB;
98  else
99  nTabA = static_cast<SCTAB>(nTab);
100 
101  return ScAddress( nColA, nRowA, nTabA );
102 }
103 
105 {
106 public:
107 
110 
111  ScBigRange() : aStart(), aEnd() {}
112  ScBigRange( const ScBigRange& r )
113  : aStart( r.aStart ), aEnd( r.aEnd ) {}
114  ScBigRange( ScBigRange&& ) = default;
115  ScBigRange( const ScRange& r )
116  : aStart( r.aStart ), aEnd( r.aEnd ) {}
117  ScBigRange( sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1,
118  sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2 )
119  : aStart( nCol1, nRow1, nTab1 ),
120  aEnd( nCol2, nRow2, nTab2 ) {}
121 
122  void Set( sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1,
123  sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2 )
124  { aStart.Set( nCol1, nRow1, nTab1 );
125  aEnd.Set( nCol2, nRow2, nTab2 ); }
126 
127  void GetVars( sal_Int64& nCol1, sal_Int64& nRow1, sal_Int64& nTab1,
128  sal_Int64& nCol2, sal_Int64& nRow2, sal_Int64& nTab2 ) const
129  { aStart.GetVars( nCol1, nRow1, nTab1 );
130  aEnd.GetVars( nCol2, nRow2, nTab2 ); }
131 
132  bool IsValid( const ScDocument& rDoc ) const
133  { return aStart.IsValid( rDoc ) && aEnd.IsValid( rDoc ); }
134  ScRange MakeRange( const ScDocument& rDoc ) const
135  { return ScRange( aStart.MakeAddress( rDoc ), aEnd.MakeAddress( rDoc ) ); }
136 
137  inline bool Contains( const ScBigAddress& ) const;
138  inline bool Contains( const ScBigRange& ) const;
139  inline bool Intersects( const ScBigRange& ) const;
140 
142  { aStart = r.aStart; aEnd = r.aEnd; return *this; }
143  ScBigRange& operator=( ScBigRange&& ) = default;
144  bool operator==( const ScBigRange& r ) const
145  { return (aStart == r.aStart) && (aEnd == r.aEnd); }
146  bool operator!=( const ScBigRange& r ) const
147  { return !operator==( r ); }
148 
149  // These are used to define whole rows/cols/tabs.
150  constexpr static sal_Int64 nRangeMin = ::std::numeric_limits<sal_Int64>::min();;
151  constexpr static sal_Int64 nRangeMax = ::std::numeric_limits<sal_Int64>::max();;
152 };
153 
154 inline bool ScBigRange::Contains( const ScBigAddress& rAddr ) const
155 {
156  return
157  aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
158  aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
159  aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
160 }
161 
162 inline bool ScBigRange::Contains( const ScBigRange& r ) const
163 {
164  return
165  aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
166  aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
167  aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
168 }
169 
170 inline bool ScBigRange::Intersects( const ScBigRange& r ) const
171 {
172  return
173  aStart.Col() <= r.aEnd.Col() && r.aStart.Col() <= aEnd.Col() &&
174  aStart.Row() <= r.aEnd.Row() && r.aStart.Row() <= aEnd.Row() &&
175  aStart.Tab() <= r.aEnd.Tab() && r.aStart.Tab() <= aEnd.Tab();
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator!=(const ScBigRange &r) const
Definition: bigrange.hxx:146
void IncTab(sal_Int64 n=1)
Definition: bigrange.hxx:55
ScBigAddress(const ScBigAddress &r)
Definition: bigrange.hxx:38
bool IsValid(const ScDocument &rDoc) const
Definition: bigrange.cxx:13
SCROW Row() const
Definition: address.hxx:274
void IncRow(sal_Int64 n=1)
Definition: bigrange.hxx:54
static constexpr sal_Int64 nRangeMax
Definition: bigrange.hxx:151
sal_Int64 n
ScBigRange & operator=(const ScBigRange &r)
Definition: bigrange.hxx:141
sal_Int64 nCol
Definition: bigrange.hxx:31
sal_Int64 Tab() const
Definition: bigrange.hxx:46
void Set(sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1, sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2)
Definition: bigrange.hxx:122
ScBigAddress & operator=(const ScBigAddress &r)
Definition: bigrange.hxx:63
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:891
void Set(sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP)
Definition: bigrange.hxx:48
ScBigAddress & operator=(const ScAddress &r)
Definition: bigrange.hxx:66
SCTAB Tab() const
Definition: address.hxx:283
sal_Int64 Row() const
Definition: bigrange.hxx:45
sal_Int64 nTab
Definition: bigrange.hxx:32
bool Intersects(const ScBigRange &) const
do two ranges overlap?
Definition: bigrange.hxx:170
ScBigAddress aEnd
Definition: bigrange.hxx:109
bool Contains(const ScBigAddress &) const
is Address& in range?
Definition: bigrange.hxx:154
ScBigAddress(const ScAddress &r)
Definition: bigrange.hxx:41
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:890
void SetCol(sal_Int64 nColP)
Definition: bigrange.hxx:50
void GetVars(sal_Int64 &nColP, sal_Int64 &nRowP, sal_Int64 &nTabP) const
Definition: bigrange.hxx:57
void GetVars(sal_Int64 &nCol1, sal_Int64 &nRow1, sal_Int64 &nTab1, sal_Int64 &nCol2, sal_Int64 &nRow2, sal_Int64 &nTab2) const
Definition: bigrange.hxx:127
sal_Int16 SCCOL
Definition: types.hxx:21
bool IsValid(const ScDocument &rDoc) const
Definition: bigrange.hxx:132
sal_Int64 Col() const
Definition: bigrange.hxx:44
sal_Int64 nRow
Definition: bigrange.hxx:30
const SCTAB MAXTAB
Definition: address.hxx:70
ScAddress MakeAddress(const ScDocument &rDoc) const
Definition: bigrange.hxx:74
SCCOL Col() const
Definition: address.hxx:279
ScBigRange(sal_Int64 nCol1, sal_Int64 nRow1, sal_Int64 nTab1, sal_Int64 nCol2, sal_Int64 nRow2, sal_Int64 nTab2)
Definition: bigrange.hxx:117
ScBigRange(const ScBigRange &r)
Definition: bigrange.hxx:112
sal_Int32 SCROW
Definition: types.hxx:17
ScBigAddress aStart
Definition: bigrange.hxx:108
void SetRow(sal_Int64 nRowP)
Definition: bigrange.hxx:51
bool operator==(const ScBigRange &r) const
Definition: bigrange.hxx:144
void SetTab(sal_Int64 nTabP)
Definition: bigrange.hxx:52
bool operator!=(const ScBigAddress &r) const
Definition: bigrange.hxx:70
ScRange MakeRange(const ScDocument &rDoc) const
Definition: bigrange.hxx:134
ScBigRange(const ScRange &r)
Definition: bigrange.hxx:115
static constexpr sal_Int64 nRangeMin
Definition: bigrange.hxx:150
bool operator==(const ScBigAddress &r) const
Definition: bigrange.hxx:68
sal_Int16 SCTAB
Definition: types.hxx:22
ScBigAddress(sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP)
Definition: bigrange.hxx:36
void IncCol(sal_Int64 n=1)
Definition: bigrange.hxx:53