LibreOffice Module sc (master) 1
rangenam.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 "global.hxx"
23#include "address.hxx"
24#include <formula/grammar.hxx>
25#include "scdllapi.h"
26#include "calcmacros.hxx"
27
28#include <memory>
29#include <map>
30#include <vector>
31
32class ScDocument;
33class ScTokenArray;
34
35namespace sc {
36
37struct RefUpdateContext;
38struct RefUpdateInsertTabContext;
39struct RefUpdateDeleteTabContext;
40struct RefUpdateMoveTabContext;
41class CompileFormulaContext;
42
43}
44
46{
47public:
48 enum class Type //specialization to typed_flags outside of class
49 {
50 Name = 0x0000,
51 Database = 0x0001,
52 Criteria = 0x0002,
53 PrintArea = 0x0004,
54 ColHeader = 0x0008,
55 RowHeader = 0x0010,
56 AbsArea = 0x0020,
57 RefArea = 0x0040,
58 AbsPos = 0x0080
59 };
60
61 enum class IsNameValidType
62 {
63 NAME_VALID,
64 NAME_INVALID_CELL_REF,
65 NAME_INVALID_BAD_STRING
66 };
67
68private:
69 OUString aName;
70 OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
71 OUString maNewName;
72 std::unique_ptr<ScTokenArray>
77 formula::FormulaGrammar::Grammar eTempGrammar; // needed for unresolved XML compiles
78 sal_uInt16 nIndex;
79 bool bModified; // is set/cleared by UpdateReference
80
81 void CompileRangeData( const OUString& rSymbol, bool bSetError );
82 void InitCode();
83public:
84
86 const OUString& rName,
87 const OUString& rSymbol,
88 const ScAddress& rAdr = ScAddress(),
92 const OUString& rName,
93 const ScTokenArray& rArr,
94 const ScAddress& rAdr = ScAddress(),
97 const OUString& rName,
98 const ScAddress& rTarget );
99 // rTarget is ABSPOS jump label
100
101 /* Exact copy, not recompiled, no other index (!), nothing... except if
102 * pDocument or pPos are passed, those values are assigned instead of the
103 * copies. */
104 ScRangeData( const ScRangeData& rScRangeData, ScDocument* pDocument = nullptr, const ScAddress* pPos = nullptr );
105
107
108 bool operator== (const ScRangeData& rData) const;
109
110 void GetName( OUString& rName ) const { rName = maNewName.isEmpty() ? aName : maNewName; }
111 const OUString& GetName() const { return maNewName.isEmpty() ? aName : maNewName; }
112 const OUString& GetUpperName() const { return aUpperName; }
113 const ScAddress& GetPos() const { return aPos; }
114 // The index has to be unique. If index=0 a new index value is assigned.
115 void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; }
116 sal_uInt16 GetIndex() const { return nIndex; }
118 void SetNewName( const OUString& rNewName ) { maNewName = rNewName; }
119 ScTokenArray* GetCode() { return pCode.get(); }
120 SC_DLLPUBLIC void SetCode( const ScTokenArray& );
121 const ScTokenArray* GetCode() const { return pCode.get(); }
123 bool HasReferences() const;
124 void AddType( Type nType );
125 Type GetType() const { return eType; }
126 bool HasType( Type nType ) const;
127 sal_uInt32 GetUnoType() const;
130 void UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress& );
131
136 void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab );
137 bool IsModified() const { return bModified; }
138
140
141 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
142 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
143
144 SC_DLLPUBLIC bool IsReference( ScRange& rRef ) const;
145 bool IsReference( ScRange& rRef, const ScAddress& rPos ) const;
146 SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const;
147 bool IsRangeAtBlock( const ScRange& ) const;
148
149 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab );
150 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab );
151 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab );
152
153 void ValidateTabRefs();
154
155 static void MakeValidName( const ScDocument& rDoc, OUString& rName );
156
157 SC_DLLPUBLIC static IsNameValidType IsNameValid( const OUString& rName, const ScDocument& rDoc );
158
159 bool HasPossibleAddressConflict() const;
160
162
163#if DEBUG_FORMULA_COMPILER
164 void Dump() const;
165#endif
166};
167namespace o3tl
168{
169 template<> struct typed_flags<ScRangeData::Type> : is_typed_flags<ScRangeData::Type, 0xff> {};
170}
171
172
174{
175 eType = eType|nType;
176}
177
178inline bool ScRangeData::HasType( Type nType ) const
179{
180 return ( ( eType & nType ) == nType );
181}
182
183extern "C" int ScRangeData_QsortNameCompare( const void*, const void* );
184
186{
187private:
188 typedef std::vector<ScRangeData*> IndexDataType;
189 typedef ::std::map<OUString, std::unique_ptr<ScRangeData>> DataType;
192 // Use for optimization, true if any of the contained names resolves
193 // as a valid cell address (e.g. 'day1' with 16k columns).
196
198
199public:
201 typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
202
203 typedef DataType::const_iterator const_iterator;
204 typedef DataType::iterator iterator;
205
206 ScRangeName();
208
209 SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
210 SC_DLLPUBLIC ScRangeData* findByUpperName(const OUString& rName);
211 SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const;
212 SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
213 void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 );
214 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 );
215 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 );
216 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 );
217 void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
218 void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
219
224
242 void CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab,
243 const ScDocument& rOldDoc, ScDocument& rNewDoc, const bool bGlobalNamesToLocal ) const;
244
245 SC_DLLPUBLIC const_iterator begin() const { return m_Data.begin(); }
246 SC_DLLPUBLIC const_iterator end() const { return m_Data.end(); }
247 SC_DLLPUBLIC size_t size() const { return m_Data.size(); }
248 SC_DLLPUBLIC size_t index_size() const { return maIndexToData.size(); }
249 bool empty() const { return m_Data.empty(); }
250
263 SC_DLLPUBLIC bool insert( ScRangeData* p, bool bReuseFreeIndex = true );
264
265 void erase(const ScRangeData& r);
266 void erase(const OUString& rName);
267
273 void erase(const_iterator itr);
274
275 void clear();
276 bool operator== (const ScRangeName& r) const;
277
279 {
283 }
284};
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
Definition: rangenam.cxx:371
bool HasType(Type nType) const
Definition: rangenam.hxx:178
Type eType
Definition: rangenam.hxx:75
const ScTokenArray * GetCode() const
Definition: rangenam.hxx:121
ScTokenArray * GetCode()
Definition: rangenam.hxx:119
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Definition: rangenam.cxx:178
void GetName(OUString &rName) const
Definition: rangenam.hxx:110
bool HasPossibleAddressConflict() const
Definition: rangenam.cxx:500
ScAddress aPos
Definition: rangenam.hxx:74
sal_uInt32 GetUnoType() const
Definition: rangenam.cxx:525
std::unique_ptr< ScTokenArray > pCode
Definition: rangenam.hxx:73
formula::FormulaGrammar::Grammar eTempGrammar
Definition: rangenam.hxx:77
SC_DLLPUBLIC FormulaError GetErrCode() const
Definition: rangenam.cxx:515
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:395
SC_DLLPUBLIC void GuessPosition()
Definition: rangenam.cxx:206
bool IsModified() const
Definition: rangenam.hxx:137
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:405
static void MakeValidName(const ScDocument &rDoc, OUString &rName)
Definition: rangenam.cxx:423
void InitCode()
Definition: rangenam.cxx:628
void SetIndex(sal_uInt16 nInd)
Definition: rangenam.hxx:115
sal_uInt16 nIndex
Definition: rangenam.hxx:78
OUString maNewName
used for formulas after changing names in the dialog
Definition: rangenam.hxx:71
OUString aName
Definition: rangenam.hxx:69
void UpdateSymbol(OUStringBuffer &rBuffer, const ScAddress &)
Definition: rangenam.cxx:260
void CompileRangeData(const OUString &rSymbol, bool bSetError)
Definition: rangenam.cxx:141
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:268
SC_DLLPUBLIC ~ScRangeData()
Definition: rangenam.cxx:137
SC_DLLPUBLIC bool IsValidReference(ScRange &rRef) const
Definition: rangenam.cxx:387
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
Definition: rangenam.cxx:621
void SetNewName(const OUString &rNewName)
Does not change the name, but sets maNewName for formula update after dialog.
Definition: rangenam.hxx:118
const ScAddress & GetPos() const
Definition: rangenam.hxx:113
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:276
Type GetType() const
Definition: rangenam.hxx:125
sal_uInt16 GetIndex() const
Definition: rangenam.hxx:116
void AddType(Type nType)
Definition: rangenam.hxx:173
void ValidateTabRefs()
Definition: rangenam.cxx:535
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:310
static SC_DLLPUBLIC IsNameValidType IsNameValid(const OUString &rName, const ScDocument &rDoc)
Definition: rangenam.cxx:468
bool IsRangeAtBlock(const ScRange &) const
Definition: rangenam.cxx:362
SC_DLLPUBLIC OUString GetSymbol(const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: rangenam.cxx:244
bool HasReferences() const
Definition: rangenam.cxx:520
SC_DLLPUBLIC ScRangeData(ScDocument &rDoc, const OUString &rName, const OUString &rSymbol, const ScAddress &rAdr=ScAddress(), Type nType=Type::Name, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT)
Definition: rangenam.cxx:45
const OUString & GetName() const
Definition: rangenam.hxx:111
const OUString & GetUpperName() const
Definition: rangenam.hxx:112
bool bModified
Definition: rangenam.hxx:79
bool operator==(const ScRangeData &rData) const
Definition: rangenam.cxx:342
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:414
ScDocument & rDoc
Definition: rangenam.hxx:76
OUString aUpperName
Definition: rangenam.hxx:70
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:746
bool empty() const
Definition: rangenam.hxx:249
::std::map< OUString, std::unique_ptr< ScRangeData > > DataType
Definition: rangenam.hxx:189
void CopyUsedNames(const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab, const ScDocument &rOldDoc, ScDocument &rNewDoc, const bool bGlobalNamesToLocal) const
Copy names while copying a sheet if they reference the sheet to be copied.
Definition: rangenam.cxx:786
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:716
SC_DLLPUBLIC size_t index_size() const
Definition: rangenam.hxx:248
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:726
SC_DLLPUBLIC size_t size() const
Definition: rangenam.hxx:247
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Compile those names that couldn't be resolved during loading and inserting because they may have refe...
Definition: rangenam.cxx:778
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:704
void clear()
Definition: rangenam.cxx:869
std::vector< ScRangeData * > IndexDataType
Definition: rangenam.hxx:188
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:738
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:754
IndexDataType maIndexToData
Definition: rangenam.hxx:191
void erase(const ScRangeData &r)
Definition: rangenam.cxx:846
bool mHasPossibleAddressConflictDirty
Definition: rangenam.hxx:195
DataType::iterator iterator
Definition: rangenam.hxx:204
SC_DLLPUBLIC const_iterator end() const
Definition: rangenam.hxx:246
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:201
bool hasPossibleAddressConflict() const
Definition: rangenam.hxx:278
DataType::const_iterator const_iterator
Definition: rangenam.hxx:203
SC_DLLPUBLIC const_iterator begin() const
Definition: rangenam.hxx:245
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:802
bool mHasPossibleAddressConflict
Definition: rangenam.hxx:194
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:770
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:762
void checkHasPossibleAddressConflict() const
Definition: rangenam.cxx:877
DataType m_Data
Definition: rangenam.hxx:190
SC_DLLPUBLIC const ScRangeData * findByRange(const ScRange &rRange) const
Definition: rangenam.cxx:697
bool operator==(const ScRangeName &r) const
Definition: rangenam.cxx:891
@ PrintArea
FormulaError
Type
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
int ScRangeData_QsortNameCompare(const void *, const void *)
Definition: rangenam.cxx:644
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
Context for reference update during shifting, moving or copying of cell ranges.
OUString Name
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17