Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XmlNavigatorStack.cs « Runtime « Xsl « Xml « System « System.Data.SqlXml « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab5d5cdc8b4f3d97a96215fb3bfd1427eefd49e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//------------------------------------------------------------------------------
// <copyright file="XmlNavigatorStack.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
using System;
using System.Xml;
using System.Xml.XPath;
using System.Diagnostics;

namespace System.Xml.Xsl.Runtime {

    /// <summary>
    /// A dynamic stack of IXmlNavigators.
    /// </summary>
    internal struct XmlNavigatorStack {
        private XPathNavigator[] stkNav;    // Stack of XPathNavigators
        private int sp;                     // Stack pointer (size of stack)

    #if DEBUG
        private const int InitialStackSize = 2;
    #else
        private const int InitialStackSize = 8;
    #endif

        /// <summary>
        /// Push a navigator onto the stack
        /// </summary>
        public void Push(XPathNavigator nav) {
            if (this.stkNav == null)
            {
                this.stkNav = new XPathNavigator[InitialStackSize];
            }
            else
            {
                if (this.sp >= this.stkNav.Length)
                {
                    // Resize the stack
                    XPathNavigator[] stkOld = this.stkNav;
                    this.stkNav = new XPathNavigator[2 * this.sp];
                    Array.Copy(stkOld, this.stkNav, this.sp);
                }
            }

            this.stkNav[this.sp++] = nav;
        }

        /// <summary>
        /// Pop the topmost navigator and return it
        /// </summary>
        public XPathNavigator Pop() {
            Debug.Assert(!IsEmpty);
            return this.stkNav[--this.sp];
        }

        /// <summary>
        /// Returns the navigator at the top of the stack without adjusting the stack pointer
        /// </summary>
        public XPathNavigator Peek() {
            Debug.Assert(!IsEmpty);
            return this.stkNav[this.sp - 1];
        }

        /// <summary>
        /// Remove all navigators from the stack
        /// </summary>
        public void Reset() {
            this.sp = 0;
        }

        /// <summary>
        /// Returns true if there are no navigators in the stack
        /// </summary>
        public bool IsEmpty {
            get { return this.sp == 0; }
        }
    }
}