Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / Runtime / XmlNavigatorStack.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlNavigatorStack.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Xml;
9 using System.Xml.XPath;
10 using System.Diagnostics;
11
12 namespace System.Xml.Xsl.Runtime {
13
14     /// <summary>
15     /// A dynamic stack of IXmlNavigators.
16     /// </summary>
17     internal struct XmlNavigatorStack {
18         private XPathNavigator[] stkNav;    // Stack of XPathNavigators
19         private int sp;                     // Stack pointer (size of stack)
20
21     #if DEBUG
22         private const int InitialStackSize = 2;
23     #else
24         private const int InitialStackSize = 8;
25     #endif
26
27         /// <summary>
28         /// Push a navigator onto the stack
29         /// </summary>
30         public void Push(XPathNavigator nav) {
31             if (this.stkNav == null)
32             {
33                 this.stkNav = new XPathNavigator[InitialStackSize];
34             }
35             else
36             {
37                 if (this.sp >= this.stkNav.Length)
38                 {
39                     // Resize the stack
40                     XPathNavigator[] stkOld = this.stkNav;
41                     this.stkNav = new XPathNavigator[2 * this.sp];
42                     Array.Copy(stkOld, this.stkNav, this.sp);
43                 }
44             }
45
46             this.stkNav[this.sp++] = nav;
47         }
48
49         /// <summary>
50         /// Pop the topmost navigator and return it
51         /// </summary>
52         public XPathNavigator Pop() {
53             Debug.Assert(!IsEmpty);
54             return this.stkNav[--this.sp];
55         }
56
57         /// <summary>
58         /// Returns the navigator at the top of the stack without adjusting the stack pointer
59         /// </summary>
60         public XPathNavigator Peek() {
61             Debug.Assert(!IsEmpty);
62             return this.stkNav[this.sp - 1];
63         }
64
65         /// <summary>
66         /// Remove all navigators from the stack
67         /// </summary>
68         public void Reset() {
69             this.sp = 0;
70         }
71
72         /// <summary>
73         /// Returns true if there are no navigators in the stack
74         /// </summary>
75         public bool IsEmpty {
76             get { return this.sp == 0; }
77         }
78     }
79 }