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  ScTokenArray( ScTokenArray&& ) = default;
70  virtual ~ScTokenArray() override;
71 
72  bool EqualTokens( const ScTokenArray* pArr2 ) const;
73 
74  virtual void Clear() override;
75  std::unique_ptr<ScTokenArray> Clone() const;
76  ScTokenArray CloneValue() const;
77 
78  void GenHash();
79  size_t GetHash() const { return mnHashValue;}
80 
81  ScFormulaVectorState GetVectorState() const { return meVectorState;}
82  void ResetVectorState();
83  bool IsFormulaVectorDisabled() const;
84 
89  bool IsInvariant() const;
90 
92  bool IsReference( ScRange& rRange, const ScAddress& rPos ) const;
94  bool IsValidReference( ScRange& rRange, const ScAddress& rPos ) const;
95 
99  bool GetAdjacentExtendOfOuterFuncRefs(
100  SCCOLROW& nExtend,
101  const ScAddress& rPos, ScDirection );
102 
103  formula::FormulaToken* AddRawToken( const ScRawToken& );
104  virtual bool AddFormulaToken(
105  const css::sheet::FormulaToken& rToken,
106  svl::SharedStringPool& rSPool,
107  formula::ExternalReferenceHelper* _pRef) override;
108  virtual void CheckToken( const formula::FormulaToken& r ) override;
109  virtual formula::FormulaToken* AddOpCode( OpCode eCode ) override;
111  formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );
113  formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
114  formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
115  void AddRangeName( sal_uInt16 n, sal_Int16 nSheet );
116  formula::FormulaToken* AddDBRange( sal_uInt16 n );
117  formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName );
118  void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef );
119  formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef );
120  formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
122  formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
123  virtual formula::FormulaToken* MergeArray( ) override;
124 
127  void MergeRangeReference( const ScAddress & rPos );
128 
130  void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
131 
136 
145  void ReadjustAbsolute3DReferences( const ScDocument& rOldDoc, ScDocument& rNewDoc, const ScAddress& rPos, bool bRangeName = false );
146 
151  void AdjustAbsoluteRefs( const ScDocument& rOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bCheckCopyArea );
152 
156  void AdjustSheetLocalNameReferences( SCTAB nOldTab, SCTAB nNewTab );
157 
161  bool ReferencesSheet( SCTAB nTab, SCTAB nPosTab ) const;
162 
170  sc::RefUpdateResult AdjustReferenceOnShift( const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos );
171 
172  sc::RefUpdateResult AdjustReferenceOnMove(
173  const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos, const ScAddress& rNewPos );
174 
185  void MoveReferenceColReorder(
186  const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2,
187  const sc::ColRowReorderMapType& rColMap );
188 
189  void MoveReferenceRowReorder(
190  const ScAddress& rPos, SCTAB nTab, SCCOL nCol1, SCCOL nCol2,
191  const sc::ColRowReorderMapType& rRowMap );
192 
201  sc::RefUpdateResult AdjustReferenceInName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
202 
203  sc::RefUpdateResult AdjustReferenceInMovedName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
204 
214  sc::RefUpdateResult AdjustReferenceOnDeletedTab( const sc::RefUpdateDeleteTabContext& rCxt, const ScAddress& rOldPos );
215 
216  sc::RefUpdateResult AdjustReferenceOnInsertedTab( const sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos );
217 
218  sc::RefUpdateResult AdjustReferenceOnMovedTab( const sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos );
219 
223  void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos );
224 
229  void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos );
230 
235  void AdjustReferenceOnCopy( const ScAddress& rNewPos );
236 
247  void ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab );
248 
249  void CheckRelativeReferenceBounds(
250  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
251 
252  void CheckRelativeReferenceBounds(
253  const ScAddress& rPos, SCROW nGroupLen, const ScRange& rRange, std::vector<SCROW>& rBounds ) const;
254 
255  void CheckExpandReferenceBounds(
256  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
257 
262  OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
263 
264  void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
265  bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
266 
267  sal_Int32 GetWeight() const;
268 
269  bool IsEnabledForOpenCL() const { return mbOpenCLEnabled; }
270  bool IsEnabledForThreading() const { return mbThreadingEnabled; }
271 
272 #if DEBUG_FORMULA_COMPILER
273  void Dump() const;
274 #endif
275 };
276 
277 /* 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:81
OpCode
virtual FormulaToken * MergeArray()
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25
bool IsEnabledForOpenCL() const
Definition: tokenarray.hxx:269
size_t GetHash() const
Definition: tokenarray.hxx:79
bool IsEnabledForThreading() const
Definition: tokenarray.hxx:270
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:352
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:3388
ScDocument & rDoc
Definition: compiler.hxx:273
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int16 SCTAB
Definition: types.hxx:22