-
Notifications
You must be signed in to change notification settings - Fork 5
/
PassThroughTable.cs
147 lines (129 loc) · 4.34 KB
/
PassThroughTable.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NSFW.TimingEditor
{
/// <summary>
/// Implements a table that passes edits through to another table.
/// </summary>
public class PassThroughTable : ITable
{
/// <summary>
/// The base timing table.
/// </summary>
private ITable baseTable;
/// <summary>
/// The dynamic timing advance table.
/// </summary>
private ITable advanceTable;
/// <summary>
/// Indicates whether the table is fully populated.
/// </summary>
private bool populated;
/// <summary>
/// Indicates whether the table is read-only.
/// </summary>
public bool IsReadOnly { get { return false; } set { throw new InvalidOperationException(); } }
/// <summary>
/// Row headers for the table.
/// </summary>
public IList<double> RowHeaders { get { return this.advanceTable.RowHeaders; } }
/// <summary>
/// Column headers for the table.
/// </summary>
public IList<double> ColumnHeaders { get { return this.advanceTable.ColumnHeaders; } }
/// <summary>
/// Constructor - takes a reference to the base timing table.
/// </summary>
public PassThroughTable(ITable baseTable)
{
this.baseTable = baseTable;
this.advanceTable = new Table();
}
/// <summary>
/// Clone this table.
/// </summary>
public ITable Clone()
{
PassThroughTable result = new PassThroughTable(this.baseTable);
result.advanceTable = this.advanceTable.Clone();
result.populated = this.populated;
return result;
}
/// <summary>
/// Copy the contents of this table into another table.
/// </summary>
public void CopyTo(ITable other)
{
other.Reset();
for (int i = 0; i < this.baseTable.RowHeaders.Count; i++)
{
other.RowHeaders.Add(this.baseTable.RowHeaders[i]);
}
for (int i = 0; i < this.baseTable.ColumnHeaders.Count; i++)
{
other.ColumnHeaders.Add(this.baseTable.ColumnHeaders[i]);
}
for (int x = 0; x < this.baseTable.ColumnHeaders.Count; x++)
{
for (int y = 0; y < this.baseTable.RowHeaders.Count; y++)
{
other.SetCell(x, y, this.GetCell(x, y));
}
}
other.Populated();
}
/// <summary>
/// Indicates whether this table is fully populated.
/// </summary>
public bool IsPopulated
{
get
{
return this.baseTable.IsPopulated && this.advanceTable.IsPopulated;
}
}
/// <summary>
/// Reset this table.
/// </summary>
public void Reset()
{
this.populated = false;
this.advanceTable.Reset();
}
/// <summary>
/// Invoke when fully populated to mark this table and the advance table as populated.
/// </summary>
public void Populated()
{
this.populated = true;
this.advanceTable.Populated();
}
/// <summary>
/// Get the contents of a cell.
/// </summary>
public double GetCell(int x, int y)
{
return this.advanceTable.GetCell(x, y);
}
/// <summary>
/// Set the contents of a cell.
/// </summary>
public void SetCell(int x, int y, double value)
{
if (this.populated)
{
double oldTotalValue = this.advanceTable.GetCell(x, y);
double delta = value - oldTotalValue;
double oldBaseValue = this.baseTable.GetCell(x, y);
this.baseTable.SetCell(x, y, oldBaseValue - delta);
this.advanceTable.SetCell(x, y, oldTotalValue + delta);
}
else
{
this.advanceTable.SetCell(x, y, value);
}
}
}
}