forked from LegacyNsfw/TimingEditor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Table.cs
141 lines (121 loc) · 4.07 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NSFW.TimingEditor
{
public class Table : ITable
{
private bool isPopulated;
private bool isReadOnly;
private double[][] cells;
private IList<double> rowHeaders;
private IList<double> columnHeaders;
public bool IsReadOnly { get { return this.isReadOnly; } set { this.isReadOnly = value; } }
public bool IsPopulated { get { return this.isPopulated; } }
public IList<double> RowHeaders { get { return this.rowHeaders; } }
public IList<double> ColumnHeaders { get { return this.columnHeaders; } }
public Table()
{
this.isPopulated = false;
//this.isReadOnly = isReadOnly;
}
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;
}
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;
}
}
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();
}
}
public void Populated()
{
this.isPopulated = true;
}
public double GetCell(int x, int y) { return this.cells[x][y]; }
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;
}
}
}