Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / recursionhelper.hxx
blobb8ca1d087509c949e41b636b8ac51f7ed051658f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_RECURSIONHELPER_HXX
21 #define INCLUDED_SC_INC_RECURSIONHELPER_HXX
23 #include "formularesult.hxx"
25 #include <list>
26 #include <vector>
27 #include <stack>
29 class ScFormulaCell;
30 struct ScFormulaCellGroup;
32 struct ScFormulaRecursionEntry
34 ScFormulaCell* pCell;
35 bool bOldRunning;
36 ScFormulaResult aPreviousResult;
37 ScFormulaRecursionEntry(
38 ScFormulaCell* p, bool bR, const ScFormulaResult & rRes ) :
39 pCell(p), bOldRunning(bR), aPreviousResult( rRes)
44 typedef ::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList;
46 class ScRecursionHelper
48 typedef ::std::stack< ScFormulaCell* > ScRecursionInIterationStack;
49 typedef ::std::vector< ScFormulaCellGroup* > ScFGList;
50 ScFormulaRecursionList aRecursionFormulas;
51 ScFormulaRecursionList::iterator aInsertPos;
52 ScFormulaRecursionList::iterator aLastIterationStart;
53 ScRecursionInIterationStack aRecursionInIterationStack;
54 ScFGList aFGList;
55 sal_uInt16 nRecursionCount;
56 sal_uInt16 nIteration;
57 bool bInRecursionReturn;
58 bool bDoingRecursion;
59 bool bInIterationReturn;
60 bool bConverging;
62 void Init();
63 void ResetIteration();
65 public:
67 ScRecursionHelper();
68 sal_uInt16 GetRecursionCount() const { return nRecursionCount; }
69 void IncRecursionCount() { ++nRecursionCount; }
70 void DecRecursionCount() { --nRecursionCount; }
71 /// A pure recursion return, no iteration.
72 bool IsInRecursionReturn() const { return bInRecursionReturn &&
73 !bInIterationReturn; }
74 void SetInRecursionReturn( bool b );
75 bool IsDoingRecursion() const { return bDoingRecursion; }
76 void SetDoingRecursion( bool b ) { bDoingRecursion = b; }
78 void Insert( ScFormulaCell* p, bool bOldRunning, const ScFormulaResult & rRes );
80 bool IsInIterationReturn() const { return bInIterationReturn; }
81 void SetInIterationReturn( bool b );
82 bool IsDoingIteration() const { return nIteration > 0; }
83 sal_uInt16 GetIteration() const { return nIteration; }
84 bool & GetConvergingReference() { return bConverging; }
85 void StartIteration();
86 void ResumeIteration();
87 void IncIteration();
88 void EndIteration();
90 const ScFormulaRecursionList::iterator& GetLastIterationStart() { return aLastIterationStart; }
91 ScFormulaRecursionList::iterator GetIterationStart();
92 ScFormulaRecursionList::iterator GetIterationEnd();
93 /** Any return, recursion or iteration, iteration is always coupled with
94 recursion. */
95 bool IsInReturn() const { return bInRecursionReturn; }
96 const ScFormulaRecursionList& GetList() const { return aRecursionFormulas; }
97 ScFormulaRecursionList& GetList() { return aRecursionFormulas; }
98 ScRecursionInIterationStack& GetRecursionInIterationStack() { return aRecursionInIterationStack; }
100 void Clear();
102 /** Detects whether the formula-group is part of a simple cycle of formula-groups. */
103 bool PushFormulaGroup(ScFormulaCellGroup* pGrp);
104 void PopFormulaGroup();
107 #endif // INCLUDED_SC_INC_RECURSIONHELPER_HXX
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */