1 //------------------------------------------------------------------------------ 2 // <copyright file="CacheAxisQuery.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 // <owner current="true" primary="true">Microsoft</owner> 6 //------------------------------------------------------------------------------ 7 8 namespace MS.Internal.Xml.XPath { 9 using System; 10 using System.Xml; 11 using System.Xml.XPath; 12 using System.Diagnostics; 13 using System.Collections.Generic; 14 15 internal abstract class CacheAxisQuery : BaseAxisQuery { 16 // int count; -- we reusing it here 17 protected List<XPathNavigator> outputBuffer; 18 CacheAxisQuery(Query qyInput, string name, string prefix, XPathNodeType typeTest)19 public CacheAxisQuery(Query qyInput, string name, string prefix, XPathNodeType typeTest) : base(qyInput, name, prefix, typeTest) { 20 this.outputBuffer = new List<XPathNavigator>(); 21 this.count = 0; 22 } CacheAxisQuery(CacheAxisQuery other)23 protected CacheAxisQuery(CacheAxisQuery other) : base(other) { 24 this.outputBuffer = new List<XPathNavigator>(other.outputBuffer); 25 this.count = other.count; 26 } 27 Reset()28 public override void Reset() { 29 this.count = 0; 30 } 31 Evaluate(XPathNodeIterator context)32 public override object Evaluate(XPathNodeIterator context) { 33 base.Evaluate(context); 34 outputBuffer.Clear(); 35 return this; 36 } 37 Advance()38 public override XPathNavigator Advance() { 39 Debug.Assert(0 <= count && count <= outputBuffer.Count); 40 if (count < outputBuffer.Count) { 41 return outputBuffer[count++]; 42 } 43 return null; 44 } 45 46 public override XPathNavigator Current { 47 get { 48 Debug.Assert(0 <= count && count <= outputBuffer.Count); 49 if (count == 0) { 50 return null; 51 } 52 return outputBuffer[count - 1]; 53 } 54 } 55 56 public override int CurrentPosition { get { return count; } } 57 public override int Count { get { return outputBuffer.Count; } } 58 public override QueryProps Properties { get { return QueryProps.Merge | QueryProps.Cached | QueryProps.Position | QueryProps.Count; } } 59 } 60 } 61