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