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 <algorithm>
24 
25 const sal_Int32 nInt32Min = 0x80000000;
26 const sal_Int32 nInt32Max = 0x7fffffff;
27 
28 class ScDocument;
29 
31 {
32  sal_Int32 nRow;
33  sal_Int32 nCol;
34  sal_Int32 nTab;
35 
36 public:
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 ) {}
41  : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
42  ScBigAddress( ScBigAddress&& ) = default;
43  ScBigAddress( const ScAddress& r )
44  : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
45 
46  sal_Int32 Col() const { return nCol; }
47  sal_Int32 Row() const { return nRow; }
48  sal_Int32 Tab() const { return nTab; }
49 
50  void Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
51  { nCol = nColP; nRow = nRowP; nTab = nTabP; }
52  void SetCol( sal_Int32 nColP ) { nCol = nColP; }
53  void SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
54  void SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
55  void IncCol( sal_Int32 n = 1 ) { nCol += n; }
56  void IncRow( sal_Int32 n = 1 ) { nRow += n; }
57  void IncTab( sal_Int32 n = 1 ) { nTab += n; }
58 
59  void GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
60  { nColP = nCol; nRowP = nRow; nTabP = nTab; }
61 
62  bool IsValid( const ScDocument& rDoc ) const;
63  inline ScAddress MakeAddress() const;
64 
66  { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
67  ScBigAddress& operator=( ScBigAddress&& ) = default;
69  { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
70  bool operator==( const ScBigAddress& r ) const
71  { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
72  bool operator!=( const ScBigAddress& r ) const
73  { return !operator==( r ); }
74 };
75 
77 {
78  SCCOL nColA;
79  SCROW nRowA;
80  SCTAB nTabA;
81 
82  if ( nCol < 0 )
83  nColA = 0;
84  else if ( nCol > MAXCOL )
85  nColA = MAXCOL;
86  else
87  nColA = static_cast<SCCOL>(nCol);
88 
89  if ( nRow < 0 )
90  nRowA = 0;
91  else if ( nRow > MAXROW )
92  nRowA = MAXROW;
93  else
94  nRowA = static_cast<SCROW>(nRow);
95 
96  if ( nTab < 0 )
97  nTabA = 0;
98  else if ( nTab > MAXTAB )
99  nTabA = MAXTAB;
100  else
101  nTabA = static_cast<SCTAB>(nTab);
102 
103  return ScAddress( nColA, nRowA, nTabA );
104 }
105 
107 {
108 public:
109 
112 
113  ScBigRange() : aStart(), aEnd() {}
114  ScBigRange( const ScBigRange& r )
115  : aStart( r.aStart ), aEnd( r.aEnd ) {}
116  ScBigRange( ScBigRange&& ) = default;
117  ScBigRange( const ScRange& r )
118  : aStart( r.aStart ), aEnd( r.aEnd ) {}
119  ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
120  sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
121  : aStart( nCol1, nRow1, nTab1 ),
122  aEnd( nCol2, nRow2, nTab2 ) {}
123 
124  void Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
125  sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
126  { aStart.Set( nCol1, nRow1, nTab1 );
127  aEnd.Set( nCol2, nRow2, nTab2 ); }
128 
129  void GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
130  sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
131  { aStart.GetVars( nCol1, nRow1, nTab1 );
132  aEnd.GetVars( nCol2, nRow2, nTab2 ); }
133 
134  bool IsValid( const ScDocument& rDoc ) const
135  { return aStart.IsValid( rDoc ) && aEnd.IsValid( rDoc ); }
137  { return ScRange( aStart.MakeAddress(),
138  aEnd.MakeAddress() ); }
139 
140  inline bool In( const ScBigAddress& ) const;
141  inline bool In( const ScBigRange& ) const;
142  inline bool Intersects( const ScBigRange& ) const;
143 
145  { aStart = r.aStart; aEnd = r.aEnd; return *this; }
146  ScBigRange& operator=( ScBigRange&& ) = default;
147  bool operator==( const ScBigRange& r ) const
148  { return (aStart == r.aStart) && (aEnd == r.aEnd); }
149  bool operator!=( const ScBigRange& r ) const
150  { return !operator==( r ); }
151 };
152 
153 inline bool ScBigRange::In( const ScBigAddress& rAddr ) const
154 {
155  return
156  aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
157  aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
158  aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
159 }
160 
161 inline bool ScBigRange::In( const ScBigRange& r ) const
162 {
163  return
164  aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
165  aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
166  aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
167 }
168 
169 inline bool ScBigRange::Intersects( const ScBigRange& r ) const
170 {
171  return !(
172  std::min( aEnd.Col(), r.aEnd.Col() ) < std::max( aStart.Col(), r.aStart.Col() )
173  || std::min( aEnd.Row(), r.aEnd.Row() ) < std::max( aStart.Row(), r.aStart.Row() )
174  || std::min( aEnd.Tab(), r.aEnd.Tab() ) < std::max( aStart.Tab(), r.aStart.Tab() )
175  );
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator!=(const ScBigRange &r) const
Definition: bigrange.hxx:149
ScBigAddress(const ScBigAddress &r)
Definition: bigrange.hxx:40
void Set(sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1, sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2)
Definition: bigrange.hxx:124
bool IsValid(const ScDocument &rDoc) const
Definition: bigrange.cxx:13
SCROW Row() const
Definition: address.hxx:261
sal_Int64 n
ScBigRange & operator=(const ScBigRange &r)
Definition: bigrange.hxx:144
sal_Int32 nCol
Definition: bigrange.hxx:33
ScBigAddress & operator=(const ScBigAddress &r)
Definition: bigrange.hxx:65
sal_Int32 Col() const
Definition: bigrange.hxx:46
ScBigAddress & operator=(const ScAddress &r)
Definition: bigrange.hxx:68
const SCROW MAXROW
Definition: address.hxx:68
SCTAB Tab() const
Definition: address.hxx:270
void Set(sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP)
Definition: bigrange.hxx:50
void GetVars(sal_Int32 &nColP, sal_Int32 &nRowP, sal_Int32 &nTabP) const
Definition: bigrange.hxx:59
bool Intersects(const ScBigRange &) const
do two ranges overlap?
Definition: bigrange.hxx:169
ScBigAddress aEnd
Definition: bigrange.hxx:111
ScBigAddress(const ScAddress &r)
Definition: bigrange.hxx:43
sal_Int32 nRow
Definition: bigrange.hxx:32
sal_Int16 SCCOL
Definition: types.hxx:21
const SCCOL MAXCOL
Definition: address.hxx:69
bool IsValid(const ScDocument &rDoc) const
Definition: bigrange.hxx:134
bool In(const ScBigAddress &) const
is Address& in range?
Definition: bigrange.hxx:153
sal_Int32 nTab
Definition: bigrange.hxx:34
sal_Int32 Row() const
Definition: bigrange.hxx:47
const SCTAB MAXTAB
Definition: address.hxx:70
void IncCol(sal_Int32 n=1)
Definition: bigrange.hxx:55
SCCOL Col() const
Definition: address.hxx:266
void SetCol(sal_Int32 nColP)
Definition: bigrange.hxx:52
void IncRow(sal_Int32 n=1)
Definition: bigrange.hxx:56
ScRange MakeRange() const
Definition: bigrange.hxx:136
ScBigRange(const ScBigRange &r)
Definition: bigrange.hxx:114
sal_Int32 SCROW
Definition: types.hxx:17
ScBigAddress aStart
Definition: bigrange.hxx:110
sal_Int32 Tab() const
Definition: bigrange.hxx:48
ScBigAddress(sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP)
Definition: bigrange.hxx:38
bool operator==(const ScBigRange &r) const
Definition: bigrange.hxx:147
void IncTab(sal_Int32 n=1)
Definition: bigrange.hxx:57
void SetRow(sal_Int32 nRowP)
Definition: bigrange.hxx:53
bool operator!=(const ScBigAddress &r) const
Definition: bigrange.hxx:72
void GetVars(sal_Int32 &nCol1, sal_Int32 &nRow1, sal_Int32 &nTab1, sal_Int32 &nCol2, sal_Int32 &nRow2, sal_Int32 &nTab2) const
Definition: bigrange.hxx:129
ScBigRange(const ScRange &r)
Definition: bigrange.hxx:117
const sal_Int32 nInt32Max
Definition: bigrange.hxx:26
ScAddress MakeAddress() const
Definition: bigrange.hxx:76
void SetTab(sal_Int32 nTabP)
Definition: bigrange.hxx:54
bool operator==(const ScBigAddress &r) const
Definition: bigrange.hxx:70
sal_Int16 SCTAB
Definition: types.hxx:22
ScBigRange(sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1, sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2)
Definition: bigrange.hxx:119
const sal_Int32 nInt32Min
Definition: bigrange.hxx:25