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 #ifndef INCLUDED_SC_INC_TOKENARRAY_HXX
21 #define INCLUDED_SC_INC_TOKENARRAY_HXX
22 
23 #include <formula/token.hxx>
24 #include <rtl/ref.hxx>
25 #include "document.hxx"
26 #include "scdllapi.h"
27 #include "types.hxx"
28 #include "calcmacros.hxx"
29 #include "address.hxx"
30 #include "global.hxx"
31 #include <formula/tokenarray.hxx>
32 
33 namespace sc {
34 
35 struct RefUpdateContext;
36 struct RefUpdateInsertTabContext;
37 struct RefUpdateDeleteTabContext;
38 struct RefUpdateMoveTabContext;
39 struct RefUpdateResult;
40 struct TokenStringContext;
41 class ColRowReorderMapType;
42 
43 }
44 
45 struct ScRawToken;
46 struct ScSingleRefData;
47 struct ScComplexRefData;
48 
50 {
51  friend class ScCompiler;
52 
53  bool ImplGetReference( ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const;
54 
55  // hold a reference to the limits because sometimes our lifetime exceeds the lifetime of the associated ScDocument
57  size_t mnHashValue;
58  ScFormulaVectorState meVectorState : 4; // Only 4 bits
59  bool mbOpenCLEnabled : 1;
60  bool mbThreadingEnabled : 1;
61 
62  void CheckForThreading( const formula::FormulaToken& r );
63 
64 public:
69  ScTokenArray( const 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 
77  void GenHash();
78  size_t GetHash() const { return mnHashValue;}
79 
80  ScFormulaVectorState GetVectorState() const { return meVectorState;}
81  void ResetVectorState();
82  bool IsFormulaVectorDisabled() const;
83 
88  bool IsInvariant() const;
89 
91  bool IsReference( ScRange& rRange, const ScAddress& rPos ) const;
93  bool IsValidReference( ScRange& rRange, const ScAddress& rPos ) const;
94 
98  bool GetAdjacentExtendOfOuterFuncRefs(
99  SCCOLROW& nExtend,
100  const ScAddress& rPos, ScDirection );
101 
102  formula::FormulaToken* AddRawToken( const ScRawToken& );
103  virtual bool AddFormulaToken(
104  const css::sheet::FormulaToken& rToken,
105  svl::SharedStringPool& rSPool,
106  formula::ExternalReferenceHelper* _pRef) override;
107  virtual void CheckToken( const formula::FormulaToken& r ) override;
108  virtual formula::FormulaToken* AddOpCode( OpCode eCode ) override;
110  formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );
112  formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
113  formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
114  void AddRangeName( sal_uInt16 n, sal_Int16 nSheet );
115  formula::FormulaToken* AddDBRange( sal_uInt16 n );
116  formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName );
117  void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef );
118  formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef );
119  formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
121  formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
122  virtual formula::FormulaToken* MergeArray( ) override;
123 
126  void MergeRangeReference( const ScAddress & rPos );
127 
129  void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
130 
134 
143  void ReadjustAbsolute3DReferences( const ScDocument& rOldDoc, ScDocument& rNewDoc, const ScAddress& rPos, bool bRangeName = false );
144 
149  void AdjustAbsoluteRefs( const ScDocument& rOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bCheckCopyArea );
150 
154  void AdjustSheetLocalNameReferences( SCTAB nOldTab, SCTAB nNewTab );
155 
159  bool ReferencesSheet( SCTAB nTab, SCTAB nPosTab ) const;
160 
168  sc::RefUpdateResult AdjustReferenceOnShift( const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos );
169 
170  sc::RefUpdateResult AdjustReferenceOnMove(
171  const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos, const ScAddress& rNewPos );
172 
183  void MoveReferenceColReorder(
184  const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2,
185  const sc::ColRowReorderMapType& rColMap );
186 
187  void MoveReferenceRowReorder(
188  const ScAddress& rPos, SCTAB nTab, SCCOL nCol1, SCCOL nCol2,
189  const sc::ColRowReorderMapType& rRowMap );
190 
199  sc::RefUpdateResult AdjustReferenceInName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
200 
201  sc::RefUpdateResult AdjustReferenceInMovedName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
202 
212  sc::RefUpdateResult AdjustReferenceOnDeletedTab( const sc::RefUpdateDeleteTabContext& rCxt, const ScAddress& rOldPos );
213 
214  sc::RefUpdateResult AdjustReferenceOnInsertedTab( const sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos );
215 
216  sc::RefUpdateResult AdjustReferenceOnMovedTab( const sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos );
217 
221  void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos );
222 
227  void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos );
228 
233  void AdjustReferenceOnCopy( const ScAddress& rNewPos );
234 
245  void ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab );
246 
247  void CheckRelativeReferenceBounds(
248  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
249 
250  void CheckRelativeReferenceBounds(
251  const ScAddress& rPos, SCROW nGroupLen, const ScRange& rRange, std::vector<SCROW>& rBounds ) const;
252 
253  void CheckExpandReferenceBounds(
254  const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
255 
260  OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
261 
262  void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
263  bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
264 
265  sal_Int32 GetWeight() const;
266 
267  bool IsEnabledForOpenCL() const { return mbOpenCLEnabled; }
268  bool IsEnabledForThreading() const { return mbThreadingEnabled; }
269 
270 #if DEBUG_FORMULA_COMPILER
271  void Dump() const;
272 #endif
273 };
274 
275 #endif // INCLUDED_SC_INC_TOKENARRAY_HXX
276 
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Single reference (one address) into the sheet.
Definition: refdata.hxx:30
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:57
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:24
ScFormulaVectorState GetVectorState() const
Definition: tokenarray.hxx:80
OpCode
virtual FormulaToken * MergeArray()
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:26
bool IsEnabledForOpenCL() const
Definition: tokenarray.hxx:267
size_t GetHash() const
Definition: tokenarray.hxx:78
bool IsEnabledForThreading() const
Definition: tokenarray.hxx:268
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:22
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:18
rtl::Reference< ScSheetLimits > mxSheetLimits
Definition: tokenarray.hxx:56
virtual FormulaToken * AddOpCode(OpCode e)
Complex reference (a range) into the sheet.
Definition: refdata.hxx:123
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:52
bool IsReference(const OUString &rSymbol, const OUString *pErrRef=nullptr)
Definition: compiler.cxx:3326
ScDocument & rDoc
Definition: compiler.hxx:270
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 SCTAB
Definition: types.hxx:23