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 #ifndef INCLUDED_SC_INC_RANGENAM_HXX
21 #define INCLUDED_SC_INC_RANGENAM_HXX
22 
23 #include "global.hxx"
24 #include "address.hxx"
25 #include <formula/grammar.hxx>
26 #include "scdllapi.h"
27 #include "calcmacros.hxx"
28 
29 #include <memory>
30 #include <map>
31 #include <vector>
32 
33 class ScDocument;
34 class ScTokenArray;
35 
36 namespace sc {
37 
38 struct RefUpdateContext;
39 struct RefUpdateInsertTabContext;
40 struct RefUpdateDeleteTabContext;
41 struct RefUpdateMoveTabContext;
42 class CompileFormulaContext;
43 
44 }
45 
47 {
48 public:
49  enum class Type //specialization to typed_flags outside of class
50  {
51  Name = 0x0000,
52  Database = 0x0001,
53  Criteria = 0x0002,
54  PrintArea = 0x0004,
55  ColHeader = 0x0008,
56  RowHeader = 0x0010,
57  AbsArea = 0x0020,
58  RefArea = 0x0040,
59  AbsPos = 0x0080
60  };
61 
63  {
67  };
68 
69 private:
70  OUString aName;
71  OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
72  OUString maNewName;
73  std::unique_ptr<ScTokenArray>
78  formula::FormulaGrammar::Grammar eTempGrammar; // needed for unresolved XML compiles
79  sal_uInt16 nIndex;
80  bool bModified; // is set/cleared by UpdateReference
81 
82  void CompileRangeData( const OUString& rSymbol, bool bSetError );
83  void InitCode();
84 public:
85 
87  const OUString& rName,
88  const OUString& rSymbol,
89  const ScAddress& rAdr = ScAddress(),
93  const OUString& rName,
94  const ScTokenArray& rArr,
95  const ScAddress& rAdr = ScAddress(),
96  Type nType = Type::Name );
98  const OUString& rName,
99  const ScAddress& rTarget );
100  // rTarget is ABSPOS jump label
101 
102  /* Exact copy, not recompiled, no other index (!), nothing... except if
103  * pDocument or pPos are passed, those values are assigned instead of the
104  * copies. */
105  ScRangeData( const ScRangeData& rScRangeData, ScDocument* pDocument = nullptr, const ScAddress* pPos = nullptr );
106 
108 
109  bool operator== (const ScRangeData& rData) const;
110 
111  void GetName( OUString& rName ) const { rName = maNewName.isEmpty() ? aName : maNewName; }
112  const OUString& GetName() const { return maNewName.isEmpty() ? aName : maNewName; }
113  const OUString& GetUpperName() const { return aUpperName; }
114  const ScAddress& GetPos() const { return aPos; }
115  // The index has to be unique. If index=0 a new index value is assigned.
116  void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; }
117  sal_uInt16 GetIndex() const { return nIndex; }
119  void SetNewName( const OUString& rNewName ) { maNewName = rNewName; }
120  ScTokenArray* GetCode() { return pCode.get(); }
121  SC_DLLPUBLIC void SetCode( const ScTokenArray& );
122  const ScTokenArray* GetCode() const { return pCode.get(); }
124  bool HasReferences() const;
125  void AddType( Type nType );
126  Type GetType() const { return eType; }
127  bool HasType( Type nType ) const;
128  sal_uInt32 GetUnoType() const;
129  SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
130  SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
131  void UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress& );
132 
137  void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab );
138  bool IsModified() const { return bModified; }
139 
141 
142  void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
143  void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
144 
145  SC_DLLPUBLIC bool IsReference( ScRange& rRef ) const;
146  bool IsReference( ScRange& rRef, const ScAddress& rPos ) const;
147  SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const;
148  bool IsRangeAtBlock( const ScRange& ) const;
149 
150  void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab );
151  void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab );
152  void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab );
153 
154  void ValidateTabRefs();
155 
156  static void MakeValidName( const ScDocument* pDoc, OUString& rName );
157 
158  SC_DLLPUBLIC static IsNameValidType IsNameValid( const OUString& rName, const ScDocument* pDoc );
159 
161 
162 #if DEBUG_FORMULA_COMPILER
163  void Dump() const;
164 #endif
165 };
166 namespace o3tl
167 {
168  template<> struct typed_flags<ScRangeData::Type> : is_typed_flags<ScRangeData::Type, 0xff> {};
169 }
170 
171 
173 {
174  eType = eType|nType;
175 }
176 
177 inline bool ScRangeData::HasType( Type nType ) const
178 {
179  return ( ( eType & nType ) == nType );
180 }
181 
182 extern "C" int ScRangeData_QsortNameCompare( const void*, const void* );
183 
185 {
186 private:
187  typedef std::vector<ScRangeData*> IndexDataType;
188  typedef ::std::map<OUString, std::unique_ptr<ScRangeData>> DataType;
189  DataType m_Data;
190  IndexDataType maIndexToData;
191 
192 public:
194  typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
195 
196  typedef DataType::const_iterator const_iterator;
197  typedef DataType::iterator iterator;
198 
199  ScRangeName();
201 
202  SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
203  SC_DLLPUBLIC ScRangeData* findByUpperName(const OUString& rName);
204  SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const;
205  SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
206  void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 );
207  void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 );
208  void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 );
209  void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 );
210  void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
211  void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
212 
217 
235  void CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab,
236  const ScDocument& rOldDoc, ScDocument& rNewDoc, const bool bGlobalNamesToLocal ) const;
237 
238  SC_DLLPUBLIC const_iterator begin() const;
239  SC_DLLPUBLIC const_iterator end() const;
240  SC_DLLPUBLIC iterator begin();
241  SC_DLLPUBLIC iterator end();
242  SC_DLLPUBLIC size_t size() const;
243  bool empty() const;
244 
257  SC_DLLPUBLIC bool insert( ScRangeData* p, bool bReuseFreeIndex = true );
258 
259  void erase(const ScRangeData& r);
260  void erase(const OUString& rName);
261 
267  void erase(const iterator& itr);
268  void clear();
269  bool operator== (const ScRangeName& r) const;
270 };
271 
272 #endif
273 
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
sal_uInt32 GetUnoType() const
Definition: rangenam.cxx:509
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:724
SC_DLLPUBLIC ScRangeData(ScDocument *pDoc, 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:47
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:756
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
Definition: rangenam.cxx:605
const OUString & GetUpperName() const
Definition: rangenam.hxx:113
sal_uInt16 GetIndex() const
Definition: rangenam.hxx:117
Context for reference update during shifting, moving or copying of cell ranges.
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:276
bool operator==(const ScRangeName &r) const
Definition: rangenam.cxx:880
DataType::iterator iterator
Definition: rangenam.hxx:197
void clear()
Definition: rangenam.cxx:874
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Definition: rangenam.cxx:180
IndexDataType maIndexToData
Definition: rangenam.hxx:190
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:194
static void MakeValidName(const ScDocument *pDoc, OUString &rName)
Definition: rangenam.cxx:422
DataType::const_iterator const_iterator
Definition: rangenam.hxx:196
formula::FormulaGrammar::Grammar eTempGrammar
Definition: rangenam.hxx:78
bool empty() const
Definition: rangenam.cxx:805
DataType m_Data
Definition: rangenam.hxx:189
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:308
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:764
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:748
SC_DLLPUBLIC void GuessPosition()
Definition: rangenam.cxx:208
SC_DLLPUBLIC const_iterator begin() const
Definition: rangenam.cxx:780
void GetName(OUString &rName) const
Definition: rangenam.hxx:111
OUString aName
Definition: rangenam.hxx:70
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:393
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:704
bool HasReferences() const
Definition: rangenam.cxx:504
std::unique_ptr< ScTokenArray > pCode
Definition: rangenam.hxx:74
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:716
bool IsRangeAtBlock(const ScRange &) const
Definition: rangenam.cxx:360
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:682
SC_DLLPUBLIC const ScRangeData * findByRange(const ScRange &rRange) const
Definition: rangenam.cxx:675
SC_DLLPUBLIC const_iterator end() const
Definition: rangenam.cxx:785
std::vector< ScRangeData * > IndexDataType
Definition: rangenam.hxx:187
SC_DLLPUBLIC void GetSymbol(OUString &rSymbol, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: rangenam.cxx:246
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:740
sal_Int16 SCCOL
Definition: types.hxx:22
const OUString & GetName() const
Definition: rangenam.hxx:112
OUString aUpperName
Definition: rangenam.hxx:71
void AddType(Type nType)
Definition: rangenam.hxx:172
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:413
ScAddress aPos
Definition: rangenam.hxx:75
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:694
void erase(const ScRangeData &r)
Definition: rangenam.cxx:853
bool operator==(const ScRangeData &rData) const
Definition: rangenam.cxx:340
bool HasType(Type nType) const
Definition: rangenam.hxx:177
void CompileRangeData(const OUString &rSymbol, bool bSetError)
Definition: rangenam.cxx:143
FormulaError
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:732
int ScRangeData_QsortNameCompare(const void *, const void *)
Definition: rangenam.cxx:628
ScDocument * pDoc
Definition: rangenam.hxx:77
sal_Int32 SCROW
Definition: types.hxx:18
void SetIndex(sal_uInt16 nInd)
Definition: rangenam.hxx:116
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:403
const ScAddress & GetPos() const
Definition: rangenam.hxx:114
const ScTokenArray * GetCode() const
Definition: rangenam.hxx:122
static SC_DLLPUBLIC IsNameValidType IsNameValid(const OUString &rName, const ScDocument *pDoc)
Definition: rangenam.cxx:467
sal_uInt16 nIndex
Definition: rangenam.hxx:79
void SetNewName(const OUString &rNewName)
Does not change the name, but sets maNewName for formula update after dialog.
Definition: rangenam.hxx:119
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
SC_DLLPUBLIC FormulaError GetErrCode() const
Definition: rangenam.cxx:499
bool IsModified() const
Definition: rangenam.hxx:138
SC_DLLPUBLIC bool IsValidReference(ScRange &rRef) const
Definition: rangenam.cxx:385
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
Definition: rangenam.cxx:369
Type eType
Definition: rangenam.hxx:76
Type GetType() const
Definition: rangenam.hxx:126
void InitCode()
Definition: rangenam.cxx:612
SC_DLLPUBLIC size_t size() const
Definition: rangenam.cxx:800
bool bModified
Definition: rangenam.hxx:80
void UpdateSymbol(OUStringBuffer &rBuffer, const ScAddress &)
Definition: rangenam.cxx:260
ScTokenArray * GetCode()
Definition: rangenam.hxx:120
::std::map< OUString, std::unique_ptr< ScRangeData > > DataType
Definition: rangenam.hxx:188
void ValidateTabRefs()
Definition: rangenam.cxx:519
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:810
SC_DLLPUBLIC ~ScRangeData()
Definition: rangenam.cxx:139
sal_Int16 SCTAB
Definition: types.hxx:23
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:268
OUString maNewName
used for formulas after changing names in the dialog
Definition: rangenam.hxx:72