OSDN Git Service

コンパイルエラーを修正した
[fooeditengine/FooEditEngine.git] / Core / GapBuffer+Enumerator.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11 #region Using Directives
12
13 using System;
14 using System.Collections.Generic;
15 using System.Collections.ObjectModel;
16 using System.Text;
17 using System.Diagnostics;
18 using System.Runtime.InteropServices;
19 using System.Collections;
20 using System.Threading;
21 using System.Globalization;
22
23 #endregion Using Directives
24
25
26 namespace Slusser.Collections.Generic
27 {
28     sealed partial class GapBuffer<T>
29         {
30                 /// <summary>
31                 /// Enumerates the elements of a <see cref="GapBuffer{T}"/>. 
32                 /// </summary>
33                 public struct Enumerator : IEnumerator<T>, IEnumerator
34                 {
35                         #region Fields
36
37                         private T _current;
38                         private int _index;
39                         private GapBuffer<T> _gapBuffer;
40                         private int _version;
41
42                         #endregion Fields
43
44
45                         #region Constructors
46
47                         internal Enumerator(GapBuffer<T> buffer)
48                         {
49                                 this._gapBuffer = buffer;
50                                 this._index = 0;
51                                 this._version = _gapBuffer._version;
52                                 this._current = default(T);
53                         }
54
55                         #endregion Constructors
56
57
58                         #region Properties
59
60                         /// <summary>
61                         /// Gets the element at the current position of the enumerator.
62                         /// </summary>
63                         /// <value>The element in the <see cref="GapBuffer{T}"/> at the current 
64                         /// position of the enumerator.</value>
65                         public T Current
66                         {
67                                 get { return _current; }
68                         }
69
70
71                         // Explicit IEnumerator implementation
72                         object IEnumerator.Current
73                         {
74                                 get
75                                 {
76                                         // Is it possible to have a current item?
77                                         if (this._index == 0 || this._index == (this._gapBuffer.Count + 1))
78                                                 throw new InvalidOperationException("");
79
80                                         return Current;
81                                 }
82                         }
83
84                         #endregion Properties
85
86
87                         #region Methods
88
89                         /// <summary>
90                         /// Advances the enumerator to the next element of the <see cref="GapBuffer{T}"/>.
91                         /// </summary>
92                         /// <returns><b>true</b> if the enumerator was successfully advanced to the next element; 
93                         /// <b>false</b> if the enumerator has passed the end of the collection.</returns>
94                         /// <exception cref="InvalidOperationException">
95                         /// The collection was modified after the enumerator was created. 
96                         /// </exception>
97                         public bool MoveNext()
98                         {
99                                 // Check version numbers
100                                 if (this._version != this._gapBuffer._version)
101                                         throw new InvalidOperationException("");
102
103                                 // Advance the index
104                                 if (this._index < this._gapBuffer.Count)
105                                 {
106                                         this._current = this._gapBuffer[this._index];
107                                         this._index++;
108                                         return true;
109                                 }
110
111                                 // The pointer is at the end of the collection
112                                 this._index = this._gapBuffer.Count + 1;
113                                 this._current = default(T);
114                                 return false;
115                         }
116
117
118                         /// <summary>
119                         /// Releases all resources used by the <see cref="GapBuffer{T}.Enumerator"/>. 
120                         /// </summary>
121                         public void Dispose()
122                         {
123                                 // Nothing to release here
124                         }
125
126
127                         // Explicit IEnumerator implementation
128                         void IEnumerator.Reset()
129                         {
130                                 // Check the version
131                                 if (this._version != this._gapBuffer._version)
132                                         throw new InvalidOperationException("");
133
134                                 // Reset the pointer
135                                 this._index = 0;
136                                 this._current = default(T);
137                         }
138
139                         #endregion Methods
140                 }
141         }
142 }