LibreOffice Module sc (master)  1
tokenarray.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 <formula/token.hxx>
23 #include <rtl/ref.hxx>
24 #include "document.hxx"
25 #include "scdllapi.h"
26 #include "types.hxx"
27 #include "calcmacros.hxx"
28 #include "address.hxx"
29 #include "global.hxx"
30 #include <formula/tokenarray.hxx>
31 
32 namespace sc {
33 
34 struct RefUpdateContext;
35 struct RefUpdateInsertTabContext;
36 struct RefUpdateDeleteTabContext;
37 struct RefUpdateMoveTabContext;
38 struct RefUpdateResult;
39 struct TokenStringContext;
40 class ColRowReorderMapType;
41 
42 }
43 
44 struct ScRawToken;
45 struct ScSingleRefData;
46 struct ScComplexRefData;
47 
49 {
50  friend class ScCompiler;
51 
52  bool ImplGetReference( ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const;
53 
54  // hold a reference to the limits because sometimes our lifetime exceeds the lifetime of the associated ScDocument
56  size_t mnHashValue;
57  ScFormulaVectorState meVectorState : 4; // Only 4 bits
58  bool mbOpenCLEnabled : 1;
59  bool mbThreadingEnabled : 1;
60 
61  void CheckForThreading( const formula::FormulaToken& r );
62 
63 public:
68  ScTokenArray( const ScTokenArray& ) = default;
69  virtual ~ScTokenArray() override;
70 
71  bool EqualTokens( const ScTokenArray* pArr2 ) const;
72 
73  virtual void Clear() override;
74  std::unique_ptr<ScTokenArray> Clone() const;
75 
76  void GenHash();
77  size_t GetHash() const { return mnHashValue;}
78 
79  ScFormulaVectorState GetVectorState() const { return meVectorState;}
80  void ResetVectorState();
81  bool IsFormulaVectorDisabled() const;
82 
87  bool IsInvariant() const;
88 
90  bool IsReference( ScRange& rRange, const ScAddress& rPos ) const;
92  bool IsValidReference( ScRange& rRange, const ScAddress& rPos ) const;
93 
97  bool GetAdjacentExtendOfOuterFuncRefs(
98  SCCOLROW& nExtend,
99  const ScAddress& rPos, ScDirection );
100 
101  formula::FormulaToken* AddRawToken( const ScRawToken& );
102  virtual bool AddFormulaToken(
103  const css::sheet::FormulaToken& rToken,
104  svl::SharedStringPool& rSPool,
105  formula::ExternalReferenceHelper* _pRef) override;
106  virtual void CheckToken( const formula::FormulaToken& r ) override;
107  virtual formula::FormulaToken* AddOpCode( OpCode eCode ) override;
109  formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );
111  formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
112  formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
113  void AddRangeName( sal_uInt16 n, sal_Int16 nSheet );
114  formula::FormulaToken* AddDBRange( sal_uInt16 n );
115  formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName );
116  void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef );
117  formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef );
118  formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
120  formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
121  virtual formula::FormulaToken* MergeArray( ) override;
122 
125  void MergeRangeReference( const ScAddress & rPos );
126 
128  void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
129 
133 
142  void ReadjustAbsolute3DReferences( const ScDocument& rOldDoc, ScDocument& rNewDoc, const ScAddress& rPos, bool bRangeName = false );
143 
148  void AdjustAbsoluteRefs( const ScDocument& rOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bCheckCopyArea );
149 
153  void AdjustSheetLocalNameReferences( SCTAB nOldTab, SCTAB nNewTab );
154 
158  bool ReferencesSheet( SCTAB nTab, SCTAB nPosTab ) const;
159 
167  sc::RefUpdateResult AdjustReferenceOnShift( const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos );
168 
169  sc::RefUpdateResult AdjustReferenceOnMove(
170  const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos, const ScAddress& rNewPos );
171 
182  void MoveReferenceColReorder(
183  const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2,
184  const sc::ColRowReorderMapType& rColMap );
185 
186  void MoveReferenceRowReorder(
187  const ScAddress& rPos, SCTAB nTab, SCCOL nCol1, SCCOL nCol2,
188  const sc::ColRowReorderMapType& rRowMap );
189 
198  sc::RefUpdateResult AdjustReferenceInName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
199 
200  sc::RefUpdateResult AdjustReferenceInMovedName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
201 
211  sc::RefUpdateResult AdjustReferenceOnDeletedTab( const sc::RefUpdateDeleteTabContext& rCxt, const ScAddress& rOldPos );
212 
213  sc::RefUpdateResult AdjustReferenceOnInsertedTab( const sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos );
214 
215  sc::RefUpdateResult AdjustReferenceOnMovedTab( const sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos );
216 
220  void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos );
221 
226  void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos );
227 
232  void AdjustReferenceOnCopy( const ScAddress& rNewPos );
233 
244  void ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab );
245 
246  void CheckRelativeReferenceBounds(
247  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
248 
249  void CheckRelativeReferenceBounds(
250  const ScAddress& rPos, SCROW nGroupLen, const ScRange& rRange, std::vector<SCROW>& rBounds ) const;
251 
252  void CheckExpandReferenceBounds(
253  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
254 
259  OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
260 
261  void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
262  bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
263 
264  sal_Int32 GetWeight() const;
265 
266  bool IsEnabledForOpenCL() const { return mbOpenCLEnabled; }
267  bool IsEnabledForThreading() const { return mbThreadingEnabled; }
268 
269 #if DEBUG_FORMULA_COMPILER
270  void Dump() const;
271 #endif
272 };
273 
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Single reference (one address) into the sheet.
Definition: refdata.hxx:29
Context for reference update during shifting, moving or copying of cell ranges.
virtual bool AddFormulaToken(const css::sheet::FormulaToken &rToken, svl::SharedStringPool &rSPool, ExternalReferenceHelper *pExtRef)
size_t mnHashValue
Definition: tokenarray.hxx:56
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
ScFormulaVectorState GetVectorState() const
Definition: tokenarray.hxx:79
OpCode
virtual FormulaToken * MergeArray()
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25
bool IsEnabledForOpenCL() const
Definition: tokenarray.hxx:266
size_t GetHash() const
Definition: tokenarray.hxx:77
bool IsEnabledForThreading() const
Definition: tokenarray.hxx:267
virtual void CheckToken(const FormulaToken &t)
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
sal_Int16 SCCOL
Definition: types.hxx:21
bool MergeRangeReference(FormulaToken **const pCode1, FormulaToken *const *const pCode2)
Context for creating string from an array of formula tokens, used in ScTokenArray::CreateString().
FormulaTokenArray & operator=(const FormulaTokenArray &)
#define SAL_WARN_UNUSED
sal_Int32 SCROW
Definition: types.hxx:17
rtl::Reference< ScSheetLimits > mxSheetLimits
Definition: tokenarray.hxx:55
virtual FormulaToken * AddOpCode(OpCode e)
Complex reference (a range) into the sheet.
Definition: refdata.hxx:122
ScDirection
Definition: global.hxx:351
ScFormulaVectorState
When vectorization is enabled, we could potentially mass-calculate a series of formula token arrays i...
Definition: types.hxx:51
bool IsReference(const OUString &rSymbol, const OUString *pErrRef=nullptr)
Definition: compiler.cxx:3328
ScDocument & rDoc
Definition: compiler.hxx:269
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int16 SCTAB
Definition: types.hxx:22