Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/bigrange.hxx
Line
Count
Source
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
28
class ScBigAddress
29
{
30
    sal_Int64   nRow;
31
    sal_Int64   nCol;
32
    sal_Int64   nTab;
33
34
public:
35
0
            ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
36
            ScBigAddress( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
37
0
                : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
38
            ScBigAddress( const ScBigAddress& r )
39
0
                : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
40
            ScBigAddress( ScBigAddress&& ) = default;
41
            ScBigAddress( const ScAddress& r )
42
154
                : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
43
44
0
    sal_Int64   Col() const { return nCol; }
45
134
    sal_Int64   Row() const { return nRow; }
46
0
    sal_Int64   Tab() const { return nTab; }
47
48
    void    Set( sal_Int64 nColP, sal_Int64 nRowP, sal_Int64 nTabP )
49
0
                { nCol = nColP; nRow = nRowP; nTab = nTabP; }
50
0
    void    SetCol( sal_Int64 nColP ) { nCol = nColP; }
51
0
    void    SetRow( sal_Int64 nRowP ) { nRow = nRowP; }
52
0
    void    SetTab( sal_Int64 nTabP ) { nTab = nTabP; }
53
0
    void    IncCol( sal_Int64 n = 1 ) { nCol += n; }
54
0
    void    IncRow( sal_Int64 n = 1 ) { nRow += n; }
55
0
    void    IncTab( sal_Int64 n = 1 ) { nTab += n; }
56
57
    void    GetVars( sal_Int64& nColP, sal_Int64& nRowP, sal_Int64& nTabP ) const
58
0
                { nColP = nCol; nRowP = nRow; nTabP = nTab; }
59
60
    bool IsValid( const ScDocument& rDoc ) const;
61
    inline ScAddress    MakeAddress( const ScDocument& rDoc ) const;
62
63
    ScBigAddress&   operator=( const ScBigAddress& r )
64
0
                    { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
65
    ScBigAddress&   operator=( ScBigAddress&& ) = default;
66
    ScBigAddress&   operator=( const ScAddress& r )
67
0
                    { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
68
    bool            operator==( const ScBigAddress& r ) const
69
70
                    { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
70
    bool            operator!=( const ScBigAddress& r ) const
71
0
                    { return !operator==( r ); }
72
};
73
74
inline ScAddress ScBigAddress::MakeAddress( const ScDocument& rDoc ) const
75
0
{
76
0
    SCCOL nColA;
77
0
    SCROW nRowA;
78
0
    SCTAB nTabA;
79
80
0
    if ( nCol < 0 )
81
0
        nColA = 0;
82
0
    else if ( nCol > rDoc.MaxCol() )
83
0
        nColA = rDoc.MaxCol();
84
0
    else
85
0
        nColA = static_cast<SCCOL>(nCol);
86
87
0
    if ( nRow < 0 )
88
0
        nRowA = 0;
89
0
    else if ( nRow > rDoc.MaxRow() )
90
0
        nRowA = rDoc.MaxRow();
91
0
    else
92
0
        nRowA = static_cast<SCROW>(nRow);
93
94
0
    if ( nTab < 0 )
95
0
        nTabA = 0;
96
0
    else if ( nTab > MAXTAB )
97
0
        nTabA = MAXTAB;
98
0
    else
99
0
        nTabA = static_cast<SCTAB>(nTab);
100
101
0
    return ScAddress( nColA, nRowA, nTabA );
102
0
}
103
104
class ScBigRange
105
{
106
public:
107
108
    ScBigAddress    aStart;
109
    ScBigAddress    aEnd;
110
111
0
                    ScBigRange() : aStart(), aEnd() {}
112
                    ScBigRange( const ScBigRange& r )
113
0
                        : aStart( r.aStart ), aEnd( r.aEnd ) {}
114
                    ScBigRange( ScBigRange&& ) = default;
115
                    ScBigRange( const ScRange& r )
116
77
                        : 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
0
                        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
0
                { aStart.Set( nCol1, nRow1, nTab1 );
125
0
                  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
0
                { aStart.GetVars( nCol1, nRow1, nTab1 );
130
0
                  aEnd.GetVars( nCol2, nRow2, nTab2 ); }
131
132
    bool    IsValid( const ScDocument& rDoc ) const
133
0
                { return aStart.IsValid( rDoc ) && aEnd.IsValid( rDoc ); }
134
    ScRange  MakeRange( const ScDocument& rDoc ) const
135
0
                { return ScRange( aStart.MakeAddress( rDoc ), aEnd.MakeAddress( rDoc ) ); }
136
137
    inline bool Contains( const ScBigAddress& ) const;    ///< is Address& in range?
138
    inline bool Contains( const ScBigRange& ) const;      ///< is Range& in range?
139
    inline bool Intersects( const ScBigRange& ) const;  ///< do two ranges overlap?
140
141
    ScBigRange&     operator=( const ScBigRange& r )
142
0
                        { aStart = r.aStart; aEnd = r.aEnd; return *this; }
143
    ScBigRange&     operator=( ScBigRange&& ) = default;
144
    bool            operator==( const ScBigRange& r ) const
145
0
                        { return (aStart == r.aStart) && (aEnd == r.aEnd); }
146
    bool            operator!=( const ScBigRange& r ) const
147
0
                        { 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
0
{
156
0
    return
157
0
        aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
158
0
        aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
159
0
        aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
160
0
}
161
162
inline bool ScBigRange::Contains( const ScBigRange& r ) const
163
0
{
164
0
    return
165
0
        aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
166
0
        aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
167
0
        aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
168
0
}
169
170
inline bool ScBigRange::Intersects( const ScBigRange& r ) const
171
0
{
172
0
    return
173
0
        aStart.Col() <= r.aEnd.Col() && r.aStart.Col() <= aEnd.Col() &&
174
0
        aStart.Row() <= r.aEnd.Row() && r.aStart.Row() <= aEnd.Row() &&
175
0
        aStart.Tab() <= r.aEnd.Tab() && r.aStart.Tab() <= aEnd.Tab();
176
0
}
177
178
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */