Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/refdata.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 "scdllapi.h"
24
#include "calcmacros.hxx"
25
26
struct ScSheetLimits;
27
28
/// Single reference (one address) into the sheet
29
struct SAL_DLLPUBLIC_RTTI ScSingleRefData
30
{
31
private:
32
    SCCOL mnCol;
33
    SCROW mnRow;
34
    SCTAB mnTab;
35
36
    union
37
    {
38
        sal_uInt8 mnFlagValue;
39
        struct
40
        {
41
            bool bColRel     :1;
42
            bool bColDeleted :1;
43
            bool bRowRel     :1;
44
            bool bRowDeleted :1;
45
            bool bTabRel     :1;
46
            bool bTabDeleted :1;
47
            bool bFlag3D     :1;     ///< 3D-Ref
48
            bool bRelName    :1;     ///< Reference derived from RangeName with relative values
49
        } Flags;
50
    };
51
52
public:
53
    /// No default ctor, because used in ScRawToken union, set InitFlags!
54
12.5M
    void InitFlags() { mnFlagValue = 0; }    ///< all FALSE
55
    /// InitAddress: InitFlags and set address
56
    SC_DLLPUBLIC void InitAddress( const ScAddress& rAdr );
57
    void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
58
    /// InitAddressRel: InitFlags and set address, everything relative to rPos
59
    void InitAddressRel( const ScDocument& rDoc, const ScAddress& rAdr, const ScAddress& rPos );
60
    /// InitFlags and set address, relative to rPos if rRef says so.
61
    void InitFromRefAddress( const ScDocument& rDoc, const ScRefAddress& rRef, const ScAddress& rPos );
62
0
    sal_uInt8 FlagValue() const { return mnFlagValue;}
63
64
1.29M
    void SetColRel( bool bVal ) { Flags.bColRel = bVal; }
65
3.57M
    bool IsColRel() const { return Flags.bColRel; }
66
1.57M
    void SetRowRel( bool bVal ) { Flags.bRowRel = bVal; }
67
70.9M
    bool IsRowRel() const { return Flags.bRowRel; }
68
1.29M
    void SetTabRel( bool bVal ) { Flags.bTabRel = bVal; }
69
3.81M
    bool IsTabRel() const { return Flags.bTabRel; }
70
71
    SC_DLLPUBLIC void SetAbsCol( SCCOL nVal );
72
    SC_DLLPUBLIC void SetRelCol( SCCOL nVal );
73
    void IncCol( SCCOL nInc );
74
    SC_DLLPUBLIC void SetAbsRow( SCROW nVal );
75
    SC_DLLPUBLIC void SetRelRow( SCROW nVal );
76
    void IncRow( SCROW nInc );
77
    SC_DLLPUBLIC void SetAbsTab( SCTAB nVal );
78
    SC_DLLPUBLIC void SetRelTab( SCTAB nVal );
79
    void IncTab( SCTAB nInc );
80
81
    SC_DLLPUBLIC void SetColDeleted( bool bVal );
82
2.90M
    bool IsColDeleted() const { return Flags.bColDeleted;}
83
    SC_DLLPUBLIC void SetRowDeleted( bool bVal );
84
2.82M
    bool IsRowDeleted() const { return Flags.bRowDeleted;}
85
    SC_DLLPUBLIC void SetTabDeleted( bool bVal );
86
2.77M
    bool IsTabDeleted() const { return Flags.bTabDeleted;}
87
    SC_DLLPUBLIC bool IsDeleted() const;
88
89
4.50M
    void SetFlag3D( bool bVal ) { Flags.bFlag3D = bVal; }
90
1.91M
    bool IsFlag3D() const { return Flags.bFlag3D; }
91
2.14k
    void SetRelName( bool bVal ) { Flags.bRelName = bVal; }
92
82.9k
    bool IsRelName() const { return Flags.bRelName; }
93
94
    bool Valid(const ScDocument& rDoc) const;
95
    bool ColValid(const ScDocument& rDoc) const;
96
    bool RowValid(const ScDocument& rDoc) const;
97
    bool TabValid(const ScDocument& rDoc) const;
98
    /** In external references nTab is -1 if the external document was not
99
        loaded but the sheet was cached, or >=0 if the external document was
100
        loaded. */
101
    bool ValidExternal(const ScDocument& rDoc) const;
102
103
    ScAddress toAbs( const ScSheetLimits& rLimits, const ScAddress& rPos ) const;
104
    SC_DLLPUBLIC ScAddress toAbs( const ScDocument& rDoc, const ScAddress& rPos ) const;
105
    SC_DLLPUBLIC void SetAddress( const ScSheetLimits& rLimits, const ScAddress& rAddr, const ScAddress& rPos );
106
    SC_DLLPUBLIC SCROW Row() const;
107
    SC_DLLPUBLIC SCCOL Col() const;
108
    SC_DLLPUBLIC SCTAB Tab() const;
109
110
    /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
111
    static void PutInOrder( ScSingleRefData& rRef1, ScSingleRefData& rRef2, const ScAddress& rPos );
112
113
    bool operator==( const ScSingleRefData& ) const;
114
115
#if DEBUG_FORMULA_COMPILER
116
    void Dump( int nIndent = 0 ) const;
117
#endif
118
};
119
120
/// Complex reference (a range) into the sheet
121
struct ScComplexRefData
122
{
123
    ScSingleRefData Ref1;
124
    ScSingleRefData Ref2;
125
    bool bTrimToData = false;
126
127
    void InitFlags()
128
2.57M
        { Ref1.InitFlags(); Ref2.InitFlags(); }
129
    void InitRange( const ScRange& rRange )
130
311k
        {
131
311k
            Ref1.InitAddress( rRange.aStart );
132
311k
            Ref2.InitAddress( rRange.aEnd );
133
311k
        }
134
    void InitRangeRel( const ScDocument& rDoc, const ScRange& rRange, const ScAddress& rPos )
135
0
        {
136
0
            Ref1.InitAddressRel( rDoc, rRange.aStart, rPos );
137
0
            Ref2.InitAddressRel( rDoc, rRange.aEnd, rPos );
138
0
        }
139
    void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
140
                            SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
141
91
        {
142
91
            Ref1.InitAddress( nCol1, nRow1, nTab1 );
143
91
            Ref2.InitAddress( nCol2, nRow2, nTab2 );
144
91
        }
145
146
    /// InitFlags and set range, relative to rPos if rRef1 and rRef2 say so.
147
    void InitFromRefAddresses( const ScDocument& rDoc, const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos );
148
149
    bool Valid(const ScDocument& rDoc) const;
150
151
    /** In external references nTab is -1 for the start tab and -1 for the end
152
        tab if one sheet and the external document was not loaded but sheet was
153
        cached, or >=0 also if more than one sheets. */
154
    bool ValidExternal(const ScDocument& rDoc) const;
155
156
    /** Whether this references entire columns, A:A */
157
    bool IsEntireCol( const ScSheetLimits& rLimits ) const;
158
159
    /** Whether this references entire rows, 1:1 */
160
    bool IsEntireRow( const ScSheetLimits& rLimits ) const;
161
162
    SC_DLLPUBLIC ScRange toAbs( const ScSheetLimits& rLimits, const ScAddress& rPos ) const;
163
    SC_DLLPUBLIC ScRange toAbs( const ScDocument& rDoc, const ScAddress& rPos ) const;
164
165
    /** Set a new range, assuming that the ordering of the range matches the
166
        ordering of the reference data flags already set. */
167
    void SetRange( const ScSheetLimits& rLimits, const ScRange& rRange, const ScAddress& rPos );
168
169
    /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
170
    void PutInOrder( const ScAddress& rPos );
171
172
    bool operator==( const ScComplexRefData& r ) const
173
1
        { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
174
    /** Enlarge range if reference passed is not within existing range.
175
        ScAddress position is used to calculate absolute references from
176
        relative references. */
177
    ScComplexRefData& Extend( const ScSheetLimits& rLimits, const ScSingleRefData & rRef, const ScAddress & rPos );
178
    ScComplexRefData& Extend( const ScSheetLimits& rLimits, const ScComplexRefData & rRef, const ScAddress & rPos );
179
180
    /** Increment or decrement end column unless or until sticky.
181
        @see ScRange::IncEndColSticky()
182
        @return TRUE if changed. */
183
    bool IncEndColSticky( const ScDocument& rDoc, SCCOL nDelta, const ScAddress& rPos );
184
185
    /** Increment or decrement end row unless or until sticky.
186
        @see ScRange::IncEndRowSticky()
187
        @return TRUE if changed. */
188
    bool IncEndRowSticky( const ScDocument& rDoc, SCROW nDelta, const ScAddress& rPos );
189
190
    bool IsDeleted() const;
191
192
932
    bool IsTrimToData() const { return bTrimToData; }
193
3.89k
    void SetTrimToData(bool bSet) { bTrimToData = bSet; }
194
195
#if DEBUG_FORMULA_COMPILER
196
    void Dump( int nIndent = 0 ) const;
197
#endif
198
};
199
200
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */