LibreOffice Module sc (master)  1
recursionhelper.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_RECURSIONHELPER_HXX
21 #define INCLUDED_SC_INC_RECURSIONHELPER_HXX
22 
23 #include "formularesult.hxx"
24 
25 #include <list>
26 #include <vector>
27 #include <stack>
28 #include <o3tl/sorted_vector.hxx>
29 
30 class ScFormulaCell;
31 
33 {
38  ScFormulaCell* p, bool bR, const ScFormulaResult & rRes ) :
39  pCell(p), bOldRunning(bR), aPreviousResult( rRes)
40  {
41  }
42 };
43 
44 typedef ::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList;
45 
47 {
48  typedef ::std::stack< ScFormulaCell* > ScRecursionInIterationStack;
50  ScFormulaRecursionList::iterator aInsertPos;
51  ScFormulaRecursionList::iterator aLastIterationStart;
52  ScRecursionInIterationStack aRecursionInIterationStack;
53  std::vector< ScFormulaCell* > aFGList;
54  // Flag list corresponding to aFGList to indicate whether each formula-group
55  // is in a dependency evaluation mode or not.
56  std::vector< bool > aInDependencyEvalMode;
57  sal_uInt16 nRecursionCount;
58  sal_uInt16 nIteration;
59  // Count of ScFormulaCell::CheckComputeDependencies in current call-stack.
67  std::vector< ScFormulaCell* > aTemporaryGroupCells;
69 
70  void Init();
71  void ResetIteration();
72 
73 public:
74 
76  sal_uInt16 GetRecursionCount() const { return nRecursionCount; }
79  sal_uInt16 GetDepComputeLevel() const { return nDependencyComputationLevel; }
80  void IncDepComputeLevel();
81  void DecDepComputeLevel();
83  bool IsInRecursionReturn() const { return bInRecursionReturn &&
85  void SetInRecursionReturn( bool b );
86  bool IsDoingRecursion() const { return bDoingRecursion; }
87  void SetDoingRecursion( bool b ) { bDoingRecursion = b; }
88 
89  void Insert( ScFormulaCell* p, bool bOldRunning, const ScFormulaResult & rRes );
90 
91  bool IsInIterationReturn() const { return bInIterationReturn; }
92  void SetInIterationReturn( bool b );
93  bool IsDoingIteration() const { return nIteration > 0; }
94  sal_uInt16 GetIteration() const { return nIteration; }
95  bool & GetConvergingReference() { return bConverging; }
96  void StartIteration();
97  void ResumeIteration();
98  void IncIteration();
99  void EndIteration();
100 
101  const ScFormulaRecursionList::iterator& GetLastIterationStart() const { return aLastIterationStart; }
102  ScFormulaRecursionList::iterator GetIterationStart();
103  ScFormulaRecursionList::iterator GetIterationEnd();
106  bool IsInReturn() const { return bInRecursionReturn; }
109  ScRecursionInIterationStack& GetRecursionInIterationStack() { return aRecursionInIterationStack; }
110 
111  void Clear();
112 
114  bool PushFormulaGroup(ScFormulaCell* pCell);
115  void PopFormulaGroup();
117  bool AnyParentFGInCycle();
118  void SetFormulaGroupDepEvalMode(bool bSet);
119  // When dependency computation detects a cycle, it may not compute proper cell values.
120  // This sets a flag that ScFormulaCell will use to avoid setting those new values
121  // and resetting the dirty flag, until the dependency computation bails out.
124 
127 
129  bool HasFormulaGroupSet() const { return pFGSet != nullptr; }
131  void SetGroupsIndependent(bool bSet) { bGroupsIndependent = bSet; }
133 };
134 
139 {
142 public:
146 
147 };
148 
150 {
152 public:
156 };
157 
159 {
162 public:
163  ScCheckIndependentFGGuard() = delete;
167 
168  bool AreGroupsIndependent();
169 };
170 
171 #endif // INCLUDED_SC_INC_RECURSIONHELPER_HXX
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::stack< ScFormulaCell * > ScRecursionInIterationStack
bool IsAbortingDependencyComputation() const
sal_uInt16 GetRecursionCount() const
bool IsInReturn() const
Any return, recursion or iteration, iteration is always coupled with recursion.
void AddTemporaryGroupCell(ScFormulaCell *cell)
void SetInIterationReturn(bool b)
const ScFormulaRecursionList::iterator & GetLastIterationStart() const
bool IsDoingRecursion() const
bool CheckFGIndependence(ScFormulaCellGroup *pFG)
void SetFormulaGroupSet(o3tl::sorted_vector< ScFormulaCellGroup * > *pSet)
bool IsInRecursionReturn() const
A pure recursion return, no iteration.
bool IsDoingIteration() const
bool PushFormulaGroup(ScFormulaCell *pCell)
Detects a simple cycle involving formula-groups and singleton formula-cells.
bool & GetConvergingReference()
bool IsInIterationReturn() const
void SetDoingRecursion(bool b)
Store a variable formula cell result, balancing between runtime performance and memory consumption...
ScRecursionInIterationStack aRecursionInIterationStack
ScFormulaRecursionList aRecursionFormulas
ScFormulaRecursionList::iterator GetIterationEnd()
o3tl::sorted_vector< ScFormulaCellGroup * > * pFGSet
const ScFormulaRecursionList & GetList() const
ScFormulaResult aPreviousResult
bool AnyCycleMemberInDependencyEvalMode(const ScFormulaCell *pCell)
sal_uInt16 nRecursionCount
sal_uInt16 GetDepComputeLevel() const
A class to wrap ScRecursionHelper::PushFormulaGroup(), ScRecursionHelper::PopFormulaGroup() and make ...
ScFormulaRecursionList::iterator GetIterationStart()
void SetFormulaGroupDepEvalMode(bool bSet)
ScFormulaRecursionList & GetList()
void SetGroupsIndependent(bool bSet)
ScFormulaRecursionList::iterator aInsertPos
bool HasFormulaGroupSet() const
sal_uInt16 nDependencyComputationLevel
void SetInRecursionReturn(bool b)
::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList
std::vector< ScFormulaCell * > aFGList
sal_uInt16 GetIteration() const
ScFormulaRecursionEntry(ScFormulaCell *p, bool bR, const ScFormulaResult &rRes)
ScRecursionInIterationStack & GetRecursionInIterationStack()
ScFormulaRecursionList::iterator aLastIterationStart
ScRecursionHelper & mrRecHelper
void Insert(ScFormulaCell *p, bool bOldRunning, const ScFormulaResult &rRes)
std::vector< bool > aInDependencyEvalMode
std::vector< ScFormulaCell * > aTemporaryGroupCells