WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
CabinetOutputList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Runtime.Serialization;
6 using DirectOutput.Cab.Out;
7 namespace DirectOutput.Cab
8 {
12  public class CabinetOutputList : IEnumerable<IOutput>
13  {
14  private Cabinet _Cabinet;
15  private OutputControllerList OutputControllers { get { return _Cabinet.OutputControllers; } }
16  #region Enumerator
17 
22  public IEnumerator<IOutput> GetEnumerator()
23  {
24  return new Enumerator(this);
25  }
26 
27  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
28  {
29  return this.GetEnumerator();
30  }
31 
32 
36  public class Enumerator : IEnumerator<IOutput>
37  {
38  private CabinetOutputList _CabinetOutputList;
39  private int _Index;
40  private IOutput _Current;
41 
43  {
44  this._CabinetOutputList = CabinetOutputList;
45  this._Index = 0;
46  this._Current = null;
47  }
48 
49  public IOutput Current
50  {
51  get { return this._Current; }
52  }
53 
54  public void Dispose()
55  {
56  this.Reset();
57  }
58 
59  object System.Collections.IEnumerator.Current
60  {
61  get { return this.Current; }
62  }
63 
64  public bool MoveNext()
65  {
66 
67  if (_Index < _CabinetOutputList.Count)
68  {
69  _Current = _CabinetOutputList[_Index];
70  _Index++;
71  return true;
72  }
73  return false;
74  }
75 
76  public void Reset()
77  {
78  this._Index = 0;
79  this._Current = null;
80  }
81  }
82  #endregion
83  #region Indexer
84 
92  public IOutput this[string Name]
93  {
94  get
95  {
96  string OutputName = "";
97 
98  string[] N = Name.Replace("/", "\\").Split('\\');
99  if (N.Length == 2)
100  {
101  //it is a path
102  if (OutputControllers.Contains(N[0]))
103  {
104  OutputName = N[1];
105  }
106  }
107  else
108  {
109  //just a simple name
110  OutputName = Name;
111  }
112 
113 
114  string[] NameParts = OutputName.Split('.');
115  if (NameParts.Length == 2)
116  {
117  int Nr = 0;
118  if (this.OutputControllers.Contains(NameParts[0]) && int.TryParse(NameParts[1], out Nr))
119  {
120  IOutputController OC = this.OutputControllers[NameParts[0]];
121 
122  IOutput O = OC.Outputs.FirstOrDefault(OP => OP.Number == Nr);
123  if (O != null)
124  {
125  return O;
126  }
127  }
128  }
129 
130 
131  foreach (IOutputController OC in this.OutputControllers)
132  {
133  if (OC.Outputs.Contains(OutputName))
134  {
135  return (IOutput)OC.Outputs[OutputName];
136  }
137  }
138  return null;
139  }
140  }
141 
142 
148  public IOutput this[int Index]
149  {
150  get
151  {
152  int Cnt = this.Count;
153  if (Index < Cnt)
154  {
155  foreach (IOutputController OC in this.OutputControllers)
156  {
157  if (Index < OC.Outputs.Count)
158  {
159  return OC.Outputs[Index];
160  }
161  Cnt -= OC.Outputs.Count;
162  if (Cnt < 0) break;
163  }
164  }
165  throw new Exception("Enumeration index of CabinateOutputList out of range");
166  }
167  }
168  #endregion
169 
170  #region Contains
171  public bool Contains(IOutput Output)
177  {
178  foreach (IOutputController OC in this.OutputControllers)
179  {
180  if (OC.Outputs.Contains(Output)) return true;
181 
182  }
183  return false;
184  }
191  public bool Contains(string Name)
192  {
193  return (this[Name] != null);
194 
195  }
196 
197 
198  #endregion
199 
200 
201  #region Count
202  public int Count
206  {
207  get
208  {
209  int Cnt = 0;
210  foreach (IOutputController OC in OutputControllers)
211  {
212  Cnt += OC.Outputs.Count;
213  }
214  return Cnt;
215  }
216  }
217  #endregion
218 
224  {
225  _Cabinet = Cabinet;
226  }
227 
228 
229  }
230 }
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
Definition: Cabinet.cs:17
int Count
Returns the number of outputs for all output controlers.
IEnumerator< IOutput > GetEnumerator()
Returns the enumerator for this collection. Required for the implementation of IEnumerable...
bool Contains(string Name)
Checks if a INamedItem object with the specified name exists in the list.
OutputList Outputs
OutputList containing the IOutput objects for a IOutputController.
Readonly list containing all IOutput objects of all IOutputController objects in a cabinet...
Out.OutputControllerList OutputControllers
List of IOutputController objects representing the output controllers in the cabinet.
Definition: Cabinet.cs:179
List of IOutputController objects
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
DirectOutput.Cab.Out is the namespace for all output controller related classes like different output...
Common interface for outputs of any output controller. The Output class implements this interface and...
Definition: IOutput.cs:10
Common interface for all outputcontrollers. Only classes implementing this interface can be used as o...
bool Contains(string Name)
Checks if a IOutput with a specific name exists in the list. Instead of a name and path consisting o...
Enumerator class for IEnumerable.
CabinetOutputList(Cabinet Cabinet)
Initializes a new instance of the CabinetOutputList class.
Basic IOutput implementation.
Definition: Output.cs:14