Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
XPathMultyIterator.cs
Go to the documentation of this file.
1using System;
3using System.Xml;
5
7
8internal sealed class XPathMultyIterator : ResetableIterator
9{
11
12 private int firstNotEmpty;
13
14 private int position;
15
17
18 public override int CurrentPosition => position;
19
21 {
22 arr = new ResetableIterator[inputArray.Count];
23 for (int i = 0; i < arr.Length; i++)
24 {
26 arr[i] = new XPathArrayIterator(list);
27 }
28 Init();
29 }
30
31 private void Init()
32 {
33 for (int i = 0; i < arr.Length; i++)
34 {
35 Advance(i);
36 }
37 int num = arr.Length - 2;
38 while (firstNotEmpty <= num)
39 {
40 if (SiftItem(num))
41 {
42 num--;
43 }
44 }
45 }
46
47 private bool Advance(int pos)
48 {
49 if (!arr[pos].MoveNext())
50 {
51 if (firstNotEmpty != pos)
52 {
56 }
58 return false;
59 }
60 return true;
61 }
62
63 private bool SiftItem(int item)
64 {
66 while (item + 1 < arr.Length)
67 {
70 {
71 case XmlNodeOrder.After:
73 item++;
74 continue;
75 default:
77 if (!Advance(item))
78 {
79 return false;
80 }
82 continue;
83 case XmlNodeOrder.Before:
84 break;
85 }
86 break;
87 }
89 return true;
90 }
91
92 public override void Reset()
93 {
94 firstNotEmpty = 0;
95 position = 0;
96 for (int i = 0; i < arr.Length; i++)
97 {
98 arr[i].Reset();
99 }
100 Init();
101 }
102
104 {
105 arr = (ResetableIterator[])it.arr.Clone();
106 firstNotEmpty = it.firstNotEmpty;
107 position = it.position;
108 }
109
110 public override XPathNodeIterator Clone()
111 {
112 return new XPathMultyIterator(this);
113 }
114
115 public override bool MoveNext()
116 {
117 if (firstNotEmpty >= arr.Length)
118 {
119 return false;
120 }
121 if (position != 0)
122 {
124 {
126 }
127 if (firstNotEmpty >= arr.Length)
128 {
129 return false;
130 }
131 }
132 position++;
133 return true;
134 }
135}
static XmlNodeOrder CompareNodes(XPathNavigator l, XPathNavigator r)
Definition Query.cs:127
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624