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.
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.
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/>.
11 #region Using Directives
14 using System.Collections.Generic;
15 using System.Collections.ObjectModel;
17 using System.Diagnostics;
18 using System.Runtime.InteropServices;
19 using System.Collections;
20 using System.Threading;
21 using System.Globalization;
23 #endregion Using Directives
26 namespace Slusser.Collections.Generic
28 sealed partial class GapBuffer<T>
31 /// Enumerates the elements of a <see cref="GapBuffer{T}"/>.
33 public struct Enumerator : IEnumerator<T>, IEnumerator
39 private GapBuffer<T> _gapBuffer;
47 internal Enumerator(GapBuffer<T> buffer)
49 this._gapBuffer = buffer;
51 this._version = _gapBuffer._version;
52 this._current = default(T);
55 #endregion Constructors
61 /// Gets the element at the current position of the enumerator.
63 /// <value>The element in the <see cref="GapBuffer{T}"/> at the current
64 /// position of the enumerator.</value>
67 get { return _current; }
71 // Explicit IEnumerator implementation
72 object IEnumerator.Current
76 // Is it possible to have a current item?
77 if (this._index == 0 || this._index == (this._gapBuffer.Count + 1))
78 throw new InvalidOperationException("");
90 /// Advances the enumerator to the next element of the <see cref="GapBuffer{T}"/>.
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.
97 public bool MoveNext()
99 // Check version numbers
100 if (this._version != this._gapBuffer._version)
101 throw new InvalidOperationException("");
104 if (this._index < this._gapBuffer.Count)
106 this._current = this._gapBuffer[this._index];
111 // The pointer is at the end of the collection
112 this._index = this._gapBuffer.Count + 1;
113 this._current = default(T);
119 /// Releases all resources used by the <see cref="GapBuffer{T}.Enumerator"/>.
121 public void Dispose()
123 // Nothing to release here
127 // Explicit IEnumerator implementation
128 void IEnumerator.Reset()
131 if (this._version != this._gapBuffer._version)
132 throw new InvalidOperationException("");
136 this._current = default(T);