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 #pragma once
21 
22 #include "formularesult.hxx"
23 
24 #include <list>
25 #include <vector>
26 #include <stack>
27 #include <o3tl/sorted_vector.hxx>
28 
29 class ScFormulaCell;
30 
32 {
37  ScFormulaCell* p, bool bR, const ScFormulaResult & rRes ) :
38  pCell(p), bOldRunning(bR), aPreviousResult( rRes)
39  {
40  }
41 };
42 
43 typedef ::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList;
44 
46 {
47  typedef ::std::stack< ScFormulaCell* > ScRecursionInIterationStack;
49  ScFormulaRecursionList::iterator aInsertPos;
50  ScFormulaRecursionList::iterator aLastIterationStart;
51  ScRecursionInIterationStack aRecursionInIterationStack;
52  std::vector< ScFormulaCell* > aFGList;
53  // Flag list corresponding to aFGList to indicate whether each formula-group
54  // is in a dependency evaluation mode or not.
55  std::vector< bool > aInDependencyEvalMode;
56  sal_uInt16 nRecursionCount;
57  sal_uInt16 nIteration;
58  // Count of ScFormulaCell::CheckComputeDependencies in current call-stack.
66  std::vector< ScFormulaCell* > aTemporaryGroupCells;
68 
69  void Init();
70  void ResetIteration();
71 
72 public:
73 
75  sal_uInt16 GetRecursionCount() const { return nRecursionCount; }
78  sal_uInt16 GetDepComputeLevel() const { return nDependencyComputationLevel; }
79  void IncDepComputeLevel();
80  void DecDepComputeLevel();
82  bool IsInRecursionReturn() const { return bInRecursionReturn &&
84  void SetInRecursionReturn( bool b );
85  bool IsDoingRecursion() const { return bDoingRecursion; }
86  void SetDoingRecursion( bool b ) { bDoingRecursion = b; }
87 
88  void Insert( ScFormulaCell* p, bool bOldRunning, const ScFormulaResult & rRes );
89 
90  bool IsInIterationReturn() const { return bInIterationReturn; }
91  void SetInIterationReturn( bool b );
92  bool IsDoingIteration() const { return nIteration > 0; }
93  sal_uInt16 GetIteration() const { return nIteration; }
94  bool & GetConvergingReference() { return bConverging; }
95  void StartIteration();
96  void ResumeIteration();
97  void IncIteration();
98  void EndIteration();
99 
100  const ScFormulaRecursionList::iterator& GetLastIterationStart() const { return aLastIterationStart; }
101  ScFormulaRecursionList::iterator GetIterationStart();
102  ScFormulaRecursionList::iterator GetIterationEnd();
105  bool IsInReturn() const { return bInRecursionReturn; }
108  ScRecursionInIterationStack& GetRecursionInIterationStack() { return aRecursionInIterationStack; }
109 
110  void Clear();
111 
113  bool PushFormulaGroup(ScFormulaCell* pCell);
114  void PopFormulaGroup();
116  bool AnyParentFGInCycle();
117  void SetFormulaGroupDepEvalMode(bool bSet);
118  // When dependency computation detects a cycle, it may not compute proper cell values.
119  // This sets a flag that ScFormulaCell will use to avoid setting those new values
120  // and resetting the dirty flag, until the dependency computation bails out.
123 
126 
128  bool HasFormulaGroupSet() const { return pFGSet != nullptr; }
130  void SetGroupsIndependent(bool bSet) { bGroupsIndependent = bSet; }
132 };
133 
138 {
141 public:
145 
146 };
147 
149 {
151 public:
155 };
156 
158 {
161 public:
162  ScCheckIndependentFGGuard() = delete;
166 
167  bool AreGroupsIndependent();
168 };
169 
170 /* 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