Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sc / inc / recursionhelper.hxx
blob141b2e7cf4cf5ab5ad55b370e624912f9f551286
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_RECURSIONHELPER_HXX
21 #define INCLUDED_RECURSIONHELPER_HXX
23 #include "formularesult.hxx"
25 #include <list>
26 #include <stack>
27 #include <tools/solar.h>
29 class ScFormulaCell;
31 struct ScFormulaRecursionEntry
33 ScFormulaCell* pCell;
34 bool bOldRunning;
35 ScFormulaResult aPreviousResult;
36 ScFormulaRecursionEntry(
37 ScFormulaCell* p, bool bR, const ScFormulaResult & rRes ) :
38 pCell(p), bOldRunning(bR), aPreviousResult( rRes)
43 typedef ::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList;
45 class ScRecursionHelper
47 typedef ::std::stack< ScFormulaCell* > ScRecursionInIterationStack;
48 ScFormulaRecursionList aRecursionFormulas;
49 ScFormulaRecursionList::iterator aInsertPos;
50 ScFormulaRecursionList::iterator aLastIterationStart;
51 ScRecursionInIterationStack aRecursionInIterationStack;
52 sal_uInt16 nRecursionCount;
53 sal_uInt16 nIteration;
54 bool bInRecursionReturn;
55 bool bDoingRecursion;
56 bool bInIterationReturn;
57 bool bConverging;
59 void Init();
60 void ResetIteration();
62 public:
64 ScRecursionHelper();
65 sal_uInt16 GetRecursionCount() const { return nRecursionCount; }
66 void IncRecursionCount() { ++nRecursionCount; }
67 void DecRecursionCount() { --nRecursionCount; }
68 /// A pure recursion return, no iteration.
69 bool IsInRecursionReturn() const { return bInRecursionReturn &&
70 !bInIterationReturn; }
71 void SetInRecursionReturn( bool b );
72 bool IsDoingRecursion() const { return bDoingRecursion; }
73 void SetDoingRecursion( bool b ) { bDoingRecursion = b; }
75 void Insert( ScFormulaCell* p, bool bOldRunning, const ScFormulaResult & rRes );
77 bool IsInIterationReturn() const { return bInIterationReturn; }
78 void SetInIterationReturn( bool b );
79 bool IsDoingIteration() const { return nIteration > 0; }
80 sal_uInt16 GetIteration() const { return nIteration; }
81 bool & GetConvergingReference() { return bConverging; }
82 void StartIteration();
83 void ResumeIteration();
84 void IncIteration();
85 void EndIteration();
87 ScFormulaRecursionList::iterator GetLastIterationStart() { return aLastIterationStart; }
88 ScFormulaRecursionList::iterator GetIterationStart();
89 ScFormulaRecursionList::iterator GetIterationEnd();
90 /** Any return, recursion or iteration, iteration is always coupled with
91 recursion. */
92 bool IsInReturn() const { return bInRecursionReturn; }
93 const ScFormulaRecursionList& GetList() const { return aRecursionFormulas; }
94 ScFormulaRecursionList& GetList() { return aRecursionFormulas; }
95 ScRecursionInIterationStack& GetRecursionInIterationStack() { return aRecursionInIterationStack; }
97 void Clear();
100 #endif // INCLUDED_RECURSIONHELPER_HXX
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */