WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
TableConfigColumnList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 
5 namespace DirectOutput.LedControl.Loader
6 {
11  public class TableConfigColumnList : List<TableConfigColumn>
12  {
13 
24  public void ParseControlData(string LedControlData, bool ThrowExceptions = false)
25  {
26  string[] Cols = SplitColumns(LedControlData);
27  if (Cols.Length < 2)
28  {
29  Log.Warning("No data to parse found in LedControlData: {0}".Build(LedControlData));
30  if (ThrowExceptions)
31  {
32  throw new Exception("No data to parse found in LedControlData: {0}".Build(LedControlData));
33  }
34  return;
35  }
36  int FirstOutputNumber = 1;
37  int LastColumnWithData = -1;
38  for (int i = 1; i < Cols.Length; i++)
39  {
40  if (!Cols[i].IsNullOrWhiteSpace())
41  {
42  LastColumnWithData = i;
43  }
44  }
45  for (int i = 1; i <= LastColumnWithData; i++)
46  {
48  C.Number = i;
49  C.FirstOutputNumber = FirstOutputNumber;
50  bool ParseOK=C.ParseColumnData(Cols[i], false);
51  if (!ParseOK)
52  {
53  Log.Warning("Previous exceptions occured in the line {0} of the ledcontrol file".Build(LedControlData));
54  if (ThrowExceptions)
55  {
56  throw new Exception("Exception(s) occured when parsing {0}".Build(LedControlData));
57  }
58  }
59 
60 
61 
62  Add(C);
63 
64  FirstOutputNumber += C.RequiredOutputCount;
65 
66  }
67 
68  }
69 
70 
71  private string[] SplitColumns(string ConfigData)
72  {
73  List<string> L = new List<string>();
74 
75  int BracketCount = 0;
76 
77  int LP = 0;
78 
79  for (int P = 0; P < ConfigData.Length; P++)
80  {
81  if (ConfigData[P] == '(')
82  {
83  BracketCount++;
84  }
85  else if (ConfigData[P] == ')')
86  {
87  BracketCount--;
88  } if (ConfigData[P] == ',' && BracketCount <= 0)
89  {
90  L.Add(ConfigData.Substring(LP, P - LP));
91  LP = P + 1;
92  BracketCount = 0;
93  }
94 
95  }
96 
97  if (LP < ConfigData.Length)
98  {
99  L.Add(ConfigData.Substring(LP));
100  }
101 
102  return L.ToArray();
103  }
104 
105 
109  public new void Sort()
110  {
111  base.Sort((a, b) => a.Number.CompareTo(b.Number));
112  }
113 
114 
125  public TableConfigColumnList(string LedControlData, bool ThrowExceptions = false) {
126  ParseControlData(LedControlData, ThrowExceptions);
127  }
128 
129  }
130 }
static void Warning(string Message)
Writes a warning message to the log.
Definition: Log.cs:134
new void Sort()
Sorts the elements in the list on the column number.
Column in a LedControl.ini file. Is a list of TableConfigSettingObjects for that column...
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
bool ParseColumnData(string ColumnData, bool ThrowExceptions=false)
Parses data for a column from a LedControl.ini file.
TableConfigColumnList()
Initializes a new instance of the TableConfigColumnList class.
void ParseControlData(string LedControlData, bool ThrowExceptions=false)
Parses a line of LedControl data.
List of columns of a LedCOntrol.ini file. Inherits List>T<.
int FirstOutputNumber
Gets or sets the number of the first ouput for this column.
int Number
Gets or sets the number of the column.
int RequiredOutputCount
Gets the number of required outputs for the column.
TableConfigColumnList(string LedControlData, bool ThrowExceptions=false)
Initializes a new instance of the TableConfigColumnList class and parses a line of LedCOntrolData...