-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTable.cs
200 lines (172 loc) · 5.64 KB
/
Table.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NSFW.TimingEditor
{
/// <summary>
/// Represents a single table direct from the ECU image.
/// </summary>
public class Table : ITable
{
/// <summary>
/// Indicates whether the table is fully populated.
/// </summary>
private bool isPopulated;
/// <summary>
/// Indicates whether the table is read-only.
/// </summary>
private bool isReadOnly;
/// <summary>
/// Contains the raw values of the table cells.
/// </summary>
private double[][] cells;
/// <summary>
/// Row header values.
/// </summary>
private IList<double> rowHeaders;
/// <summary>
/// Column header values.
/// </summary>
private IList<double> columnHeaders;
/// <summary>
/// Indicates whether the table is read-only.
/// </summary>
public bool IsReadOnly { get { return this.isReadOnly; } set { this.isReadOnly = value; } }
/// <summary>
/// Indicates whether the table is fully populated.
/// </summary>
public bool IsPopulated { get { return this.isPopulated; } }
/// <summary>
/// Gets the row header values.
/// </summary>
public IList<double> RowHeaders { get { return this.rowHeaders; } }
/// <summary>
/// Gets the column header values.
/// </summary>
public IList<double> ColumnHeaders { get { return this.columnHeaders; } }
/// <summary>
/// Constructor.
/// </summary>
public Table()
{
this.isPopulated = false;
//this.isReadOnly = isReadOnly;
}
/// <summary>
/// Clone the table.
/// </summary>
public ITable Clone()
{
Table result = new Table();
result.isPopulated = this.isPopulated;
result.isReadOnly = this.isReadOnly;
result.cells = new double[cells.Length][];
for (int x = 0; x < this.cells.Length; x++)
{
result.cells[x] = new double[this.cells[0].Length];
for (int y = 0; y < this.cells.Length; y++)
{
result.cells[x][y] = this.cells[x][y];
}
}
result.rowHeaders = new List<double>(this.rowHeaders.Count);
for (int i = 0; i < this.rowHeaders.Count; i++)
{
result.rowHeaders[i] = this.rowHeaders[i];
}
result.columnHeaders = new List<double>(this.columnHeaders.Count);
for (int i = 0; i < this.columnHeaders.Count; i++)
{
result.columnHeaders[i] = this.columnHeaders[i];
}
return result;
}
/// <summary>
/// Copy the table contents into another table.
/// </summary>
public void CopyTo(ITable other)
{
other.Reset();
bool wasReadOnly = other.IsReadOnly;
if (wasReadOnly)
{
other.IsReadOnly = false;
}
for (int i = 0; i < this.rowHeaders.Count; i++)
{
other.RowHeaders.Add(this.rowHeaders[i]);
}
for (int i = 0; i < this.columnHeaders.Count; i++)
{
other.ColumnHeaders.Add(this.columnHeaders[i]);
}
for (int x = 0; x < this.cells.Length; x++)
{
for (int y = 0; y < this.cells[0].Length; y++)
{
other.SetCell(x, y, this.cells[x][y]);
}
}
other.Populated();
if (wasReadOnly)
{
other.IsReadOnly = true;
}
}
/// <summary>
/// Reset the table contents.
/// </summary>
public void Reset()
{
this.cells = null;
if (this.rowHeaders == null)
{
this.rowHeaders = new List<double>();
}
else
{
this.rowHeaders.Clear();
}
if (this.columnHeaders == null)
{
this.columnHeaders = new List<double>();
}
else
{
this.columnHeaders.Clear();
}
}
/// <summary>
/// Indicates whether the table is populated.
/// </summary>
public void Populated()
{
this.isPopulated = true;
}
/// <summary>
/// Get the value of a single cell.
/// </summary>
public double GetCell(int x, int y) { return this.cells[x][y]; }
/// <summary>
/// Set the value of a single cell.
/// </summary>
public void SetCell(int x, int y, double value)
{
if (this.isReadOnly)
{
throw new InvalidOperationException("This table is read-only");
}
if (this.cells == null)
{
this.cells = new double[this.columnHeaders.Count][];
for (int i = 0; i < this.cells.Length; i++)
{
this.cells[i] = new double[this.rowHeaders.Count];
}
}
double[] column = this.cells[x];
column[y] = value;
}
}
}