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

QilList.cs « QIL « 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: 8ac1d26c98906d6a4b8cab2cc7f86aa5af1122f0 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//------------------------------------------------------------------------------
// <copyright file="QilList.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace System.Xml.Xsl.Qil {

    /// <summary>
    /// View over a Qil operator having N children.
    /// </summary>
    /// <remarks>
    /// Don't construct QIL nodes directly; instead, use the <see cref="QilFactory">QilFactory</see>.
    /// </remarks>
    internal class QilList : QilNode {
        private int count;
        private QilNode[] members;


        //-----------------------------------------------
        // Constructor
        //-----------------------------------------------

        /// <summary>
        /// Construct a new (empty) QilList
        /// </summary>
        public QilList(QilNodeType nodeType) : base(nodeType) {
            this.members = new QilNode[4];
            this.xmlType = null;
        }


        //-----------------------------------------------
        // QilNode methods
        //-----------------------------------------------

        /// <summary>
        /// Lazily create the XmlQueryType.
        /// </summary>
        public override XmlQueryType XmlType {
            get {
                if (this.xmlType == null) {
                    XmlQueryType xt = XmlQueryTypeFactory.Empty;

                    if (this.count > 0) {
                        if (this.nodeType == QilNodeType.Sequence) {
                            for (int i = 0; i < this.count; i++)
                                xt = XmlQueryTypeFactory.Sequence(xt, this.members[i].XmlType);

                            Debug.Assert(!xt.IsDod, "Sequences do not preserve DocOrderDistinct");
                        }
                        else if (this.nodeType == QilNodeType.BranchList) {
                            xt = this.members[0].XmlType;
                            for (int i = 1; i < this.count; i++)
                                xt = XmlQueryTypeFactory.Choice(xt, this.members[i].XmlType);
                        }
                    }

                    this.xmlType = xt;
                }

                return this.xmlType;
            }
        }

        /// <summary>
        /// Override in order to clone the "members" array.
        /// </summary>
        public override QilNode ShallowClone(QilFactory f) {
            QilList n = (QilList) MemberwiseClone();
            n.members = (QilNode[]) this.members.Clone();
            f.TraceNode(n);
            return n;
        }


        //-----------------------------------------------
        // IList<QilNode> methods -- override
        //-----------------------------------------------

        public override int Count {
            get { return this.count; }
        }

        public override QilNode this[int index] {
            get {
                if (index >= 0 && index < this.count)
                    return this.members[index];

                throw new IndexOutOfRangeException();
            }
            set {
                if (index >= 0 && index < this.count)
                    this.members[index] = value;
                else
                    throw new IndexOutOfRangeException();

                // Invalidate XmlType
                this.xmlType = null;
            }
        }

        public override void Insert(int index, QilNode node) {
            if (index < 0 || index > this.count)
                throw new IndexOutOfRangeException();

            if (this.count == this.members.Length) {
                QilNode[] membersNew = new QilNode[this.count * 2];
                Array.Copy(this.members, membersNew, this.count);
                this.members = membersNew;
            }

            if (index < this.count)
                Array.Copy(this.members, index, this.members, index + 1, this.count - index);

            this.count++;
            this.members[index] = node;

            // Invalidate XmlType
            this.xmlType = null;
        }

        public override void RemoveAt(int index) {
            if (index < 0 || index >= this.count)
                throw new IndexOutOfRangeException();

            this.count--;
            if (index < this.count)
                Array.Copy(this.members, index + 1, this.members, index, this.count - index);

            this.members[this.count] = null;

            // Invalidate XmlType
            this.xmlType = null;
        }
    }
}