1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSortKeyAccumulator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Diagnostics;
9 using System.Globalization;
10 using System.ComponentModel;
12 namespace System.Xml.Xsl.Runtime {
15 /// Accumulates a list of sort keys and stores them in an array.
17 [EditorBrowsable(EditorBrowsableState.Never)]
18 public struct XmlSortKeyAccumulator {
19 private XmlSortKey[] keys;
23 private const int DefaultSortKeyCount = 4;
25 private const int DefaultSortKeyCount = 64;
29 /// Initialize the XmlSortKeyAccumulator.
31 public void Create() {
32 if (this.keys == null)
33 this.keys = new XmlSortKey[DefaultSortKeyCount];
40 /// Create a new sort key and append it to the current run of sort keys.
42 public void AddStringSortKey(XmlCollation collation, string value) {
43 AppendSortKey(collation.CreateSortKey(value));
46 public void AddDecimalSortKey(XmlCollation collation, decimal value) {
47 AppendSortKey(new XmlDecimalSortKey(value, collation));
50 public void AddIntegerSortKey(XmlCollation collation, long value) {
51 AppendSortKey(new XmlIntegerSortKey(value, collation));
54 public void AddIntSortKey(XmlCollation collation, int value) {
55 AppendSortKey(new XmlIntSortKey(value, collation));
58 public void AddDoubleSortKey(XmlCollation collation, double value) {
59 AppendSortKey(new XmlDoubleSortKey(value, collation));
62 public void AddDateTimeSortKey(XmlCollation collation, DateTime value) {
63 AppendSortKey(new XmlDateTimeSortKey(value, collation));
66 public void AddEmptySortKey(XmlCollation collation) {
67 AppendSortKey(new XmlEmptySortKey(collation));
71 /// Finish creating the current run of sort keys and begin a new run.
73 public void FinishSortKeys() {
75 if (this.pos >= this.keys.Length) {
76 XmlSortKey[] keysNew = new XmlSortKey[this.pos * 2];
77 Array.Copy(this.keys, 0, keysNew, 0, this.keys.Length);
80 this.keys[this.pos] = null;
84 /// Append new sort key to the current run of sort keys.
86 private void AppendSortKey(XmlSortKey key) {
87 // Ensure that sort will be stable by setting index of key
88 key.Priority = this.pos;
90 if (this.keys[this.pos] == null)
91 this.keys[this.pos] = key;
93 this.keys[this.pos].AddSortKey(key);
97 /// Get array of sort keys that was constructed by this internal class.
100 get { return this.keys; }