Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/ParsingScopes.cs @ 15899

Last change on this file since 15899 was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using OfficeOpenXml.FormulaParsing.ExcelUtilities;
6
7namespace OfficeOpenXml.FormulaParsing
8{
9    /// <summary>
10    /// This class implements a stack on which instances of <see cref="ParsingScope"/>
11    /// are put. Each ParsingScope represents the parsing of an address in the workbook.
12    /// </summary>
13    public class ParsingScopes
14    {
15        private readonly IParsingLifetimeEventHandler _lifetimeEventHandler;
16
17        public ParsingScopes(IParsingLifetimeEventHandler lifetimeEventHandler)
18        {
19            _lifetimeEventHandler = lifetimeEventHandler;
20        }
21        private Stack<ParsingScope> _scopes = new Stack<ParsingScope>();
22
23        /// <summary>
24        /// Creates a new <see cref="ParsingScope"/> and puts it on top of the stack.
25        /// </summary>
26        /// <param name="address"></param>
27        /// <returns></returns>
28        public virtual ParsingScope NewScope(RangeAddress address)
29        {
30            ParsingScope scope;
31            if (_scopes.Count() > 0)
32            {
33                scope = new ParsingScope(this, _scopes.Peek(), address);
34            }
35            else
36            {
37                scope = new ParsingScope(this, address);
38            }
39            _scopes.Push(scope);
40            return scope;
41        }
42
43
44        /// <summary>
45        /// The current parsing scope.
46        /// </summary>
47        public virtual ParsingScope Current
48        {
49            get { return _scopes.Count() > 0 ? _scopes.Peek() : null; }
50        }
51
52        /// <summary>
53        /// Removes the current scope, setting the calling scope to current.
54        /// </summary>
55        /// <param name="parsingScope"></param>
56        public virtual void KillScope(ParsingScope parsingScope)
57        {
58            _scopes.Pop();
59            if (_scopes.Count() == 0)
60            {
61                _lifetimeEventHandler.ParsingCompleted();
62            }
63        }
64    }
65}
Note: See TracBrowser for help on using the repository browser.