Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_RECURSIONHELPER_HXX
30 : : #define INCLUDED_RECURSIONHELPER_HXX
31 : :
32 : : #include "formularesult.hxx"
33 : :
34 : : #include <list>
35 : : #include <stack>
36 : : #include <tools/solar.h>
37 : :
38 : : class ScFormulaCell;
39 : :
40 : 0 : struct ScFormulaRecursionEntry
41 : : {
42 : : ScFormulaCell* pCell;
43 : : bool bOldRunning;
44 : : ScFormulaResult aPreviousResult;
45 : 0 : ScFormulaRecursionEntry(
46 : : ScFormulaCell* p, bool bR, const ScFormulaResult & rRes ) :
47 : 0 : pCell(p), bOldRunning(bR), aPreviousResult( rRes)
48 : : {
49 : 0 : }
50 : : };
51 : :
52 : : typedef ::std::list< ScFormulaRecursionEntry > ScFormulaRecursionList;
53 : :
54 : 100 : class ScRecursionHelper
55 : : {
56 : : typedef ::std::stack< ScFormulaCell* > ScRecursionInIterationStack;
57 : : ScFormulaRecursionList aRecursionFormulas;
58 : : ScFormulaRecursionList::iterator aInsertPos;
59 : : ScFormulaRecursionList::iterator aLastIterationStart;
60 : : ScRecursionInIterationStack aRecursionInIterationStack;
61 : : sal_uInt16 nRecursionCount;
62 : : sal_uInt16 nIteration;
63 : : bool bInRecursionReturn;
64 : : bool bDoingRecursion;
65 : : bool bInIterationReturn;
66 : : bool bConverging;
67 : :
68 : : void Init();
69 : : void ResetIteration();
70 : :
71 : : public:
72 : :
73 : : ScRecursionHelper();
74 : 2659 : sal_uInt16 GetRecursionCount() const { return nRecursionCount; }
75 : 2659 : void IncRecursionCount() { ++nRecursionCount; }
76 : 2659 : void DecRecursionCount() { --nRecursionCount; }
77 : : /// A pure recursion return, no iteration.
78 : 0 : bool IsInRecursionReturn() const { return bInRecursionReturn &&
79 [ # # ][ # # ]: 0 : !bInIterationReturn; }
80 : : void SetInRecursionReturn( bool b );
81 : 0 : bool IsDoingRecursion() const { return bDoingRecursion; }
82 : 0 : void SetDoingRecursion( bool b ) { bDoingRecursion = b; }
83 : :
84 : : void Insert( ScFormulaCell* p, bool bOldRunning, const ScFormulaResult & rRes );
85 : :
86 : 0 : bool IsInIterationReturn() const { return bInIterationReturn; }
87 : : void SetInIterationReturn( bool b );
88 : 2659 : bool IsDoingIteration() const { return nIteration > 0; }
89 : 5318 : sal_uInt16 GetIteration() const { return nIteration; }
90 : 0 : bool & GetConvergingReference() { return bConverging; }
91 : : void StartIteration();
92 : : void ResumeIteration();
93 : : void IncIteration();
94 : : void EndIteration();
95 : :
96 : 0 : ScFormulaRecursionList::iterator GetLastIterationStart() { return aLastIterationStart; }
97 : : ScFormulaRecursionList::iterator GetIterationStart();
98 : : ScFormulaRecursionList::iterator GetIterationEnd();
99 : : /** Any return, recursion or iteration, iteration is always coupled with
100 : : recursion. */
101 : 7946 : bool IsInReturn() const { return bInRecursionReturn; }
102 : : const ScFormulaRecursionList& GetList() const { return aRecursionFormulas; }
103 : 0 : ScFormulaRecursionList& GetList() { return aRecursionFormulas; }
104 : 0 : ScRecursionInIterationStack& GetRecursionInIterationStack() { return aRecursionInIterationStack; }
105 : :
106 : : void Clear();
107 : : };
108 : :
109 : : #endif // INCLUDED_RECURSIONHELPER_HXX
110 : :
111 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|