Lean  $LEAN_TAG$
OptimizationParameterEnumerator.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System.Collections;
17 using System.Collections.Generic;
18 
20 {
21  /// <summary>
22  /// Enumerates all possible values for specific optimization parameter
23  /// </summary>
24  public abstract class OptimizationParameterEnumerator<T> : IEnumerator<string> where T: OptimizationParameter
25  {
26  /// <summary>
27  /// The target optimization parameter to enumerate
28  /// </summary>
29  protected T OptimizationParameter { get; }
30 
31  /// <summary>
32  /// The current enumeration state
33  /// </summary>
34  protected int Index { get; set; } = -1;
35 
36  protected OptimizationParameterEnumerator(T optimizationParameter)
37  {
38  OptimizationParameter = optimizationParameter;
39  }
40 
41  /// <summary>
42  /// Gets the element in the collection at the current position of the enumerator.
43  /// </summary>
44  /// <returns>The element in the collection at the current position of the enumerator.</returns>
45  public abstract string Current { get; }
46 
47  /// <summary>
48  /// Gets the current element in the collection.
49  /// </summary>
50  /// <returns>The current element in the collection.</returns>
51  object IEnumerator.Current => Current;
52 
53  /// <summary>
54  /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
55  /// </summary>
56  public void Dispose() { }
57 
58  /// <summary>
59  /// Advances the enumerator to the next element of the collection.
60  /// </summary>
61  /// <returns> true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
62  /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created.</exception>
63  public abstract bool MoveNext();
64 
65  /// <summary>
66  /// Sets the enumerator to its initial position, which is before the first element in the collection.
67  /// </summary>
68  /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created.</exception>
69  public void Reset()
70  {
71  Index = -1;
72  }
73  }
74 }