Changeset 3430 for trunk/sources/HeuristicLab.Data/3.3/ValueTypeMatrix.cs
- Timestamp:
- 04/20/10 02:02:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data/3.3/ValueTypeMatrix.cs
r3320 r3430 33 33 [Item("ValueTypeMatrix<T>", "An abstract base class for representing matrices of value types.")] 34 34 [StorableClass] 35 public abstract class ValueTypeMatrix<T> : Item, IEnumerable where T : struct {35 public abstract class ValueTypeMatrix<T> : Item, IEnumerable<T> where T : struct { 36 36 public override Image ItemImage { 37 37 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; } … … 42 42 43 43 [Storable] 44 pr ivateList<string> columnNames;45 public IEnumerable<string> ColumnNames {44 protected List<string> columnNames; 45 public virtual IEnumerable<string> ColumnNames { 46 46 get { return this.columnNames; } 47 47 set { 48 if (ReadOnly) throw new NotSupportedException("ColumnNames cannot be set. ValueTypeMatrix is read-only."); 48 49 if (value == null || value.Count() == 0) 49 50 columnNames = new List<string>(); … … 55 56 } 56 57 [Storable] 57 pr ivateList<string> rowNames;58 public IEnumerable<string> RowNames {58 protected List<string> rowNames; 59 public virtual IEnumerable<string> RowNames { 59 60 get { return this.rowNames; } 60 61 set { 62 if (ReadOnly) throw new NotSupportedException("RowNames cannot be set. ValueTypeMatrix is read-only."); 61 63 if (value == null || value.Count() == 0) 62 64 rowNames = new List<string>(); … … 68 70 } 69 71 [Storable] 70 pr ivatebool sortableView;71 public bool SortableView {72 protected bool sortableView; 73 public virtual bool SortableView { 72 74 get { return sortableView; } 73 75 set { 76 if (ReadOnly) throw new NotSupportedException("SortableView cannot be set. ValueTypeMatrix is read-only."); 74 77 if (value != sortableView) { 75 78 sortableView = value; … … 82 85 get { return matrix.GetLength(0); } 83 86 protected set { 87 if (ReadOnly) throw new NotSupportedException("Rows cannot be set. ValueTypeMatrix is read-only."); 84 88 if (value != Rows) { 85 89 T[,] newArray = new T[value, Columns]; … … 97 101 get { return matrix.GetLength(1); } 98 102 protected set { 103 if (ReadOnly) throw new NotSupportedException("Columns cannot be set. ValueTypeMatrix is read-only."); 99 104 if (value != Columns) { 100 105 T[,] newArray = new T[Rows, value]; … … 113 118 get { return matrix[rowIndex, columnIndex]; } 114 119 set { 120 if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeMatrix is read-only."); 115 121 if (!value.Equals(matrix[rowIndex, columnIndex])) { 116 122 matrix[rowIndex, columnIndex] = value; … … 118 124 } 119 125 } 126 } 127 128 [Storable] 129 protected bool readOnly; 130 public virtual bool ReadOnly { 131 get { return readOnly; } 120 132 } 121 133 … … 125 137 rowNames = new List<string>(); 126 138 sortableView = false; 139 readOnly = false; 127 140 } 128 141 protected ValueTypeMatrix(int rows, int columns) { … … 131 144 rowNames = new List<string>(); 132 145 sortableView = false; 146 readOnly = false; 133 147 } 134 148 protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames) … … 136 150 ColumnNames = columnNames; 137 151 } 138 protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames)152 protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames) 139 153 : this(rows, columns, columnNames) { 140 154 RowNames = rowNames; … … 146 160 rowNames = new List<string>(); 147 161 sortableView = false; 162 readOnly = false; 148 163 } 149 164 protected ValueTypeMatrix(T[,] elements, IEnumerable<string> columnNames) … … 158 173 public override IDeepCloneable Clone(Cloner cloner) { 159 174 ValueTypeMatrix<T> clone = (ValueTypeMatrix<T>)base.Clone(cloner); 160 clone.SortableView = SortableView;161 175 clone.matrix = (T[,])matrix.Clone(); 162 176 clone.columnNames = new List<string>(columnNames); 163 177 clone.rowNames = new List<string>(rowNames); 178 clone.sortableView = sortableView; 179 clone.readOnly = readOnly; 164 180 return clone; 181 } 182 183 public virtual ValueTypeMatrix<T> AsReadOnly() { 184 ValueTypeMatrix<T> readOnlyValueTypeMatrix = (ValueTypeMatrix<T>)this.Clone(); 185 readOnlyValueTypeMatrix.readOnly = true; 186 return readOnlyValueTypeMatrix; 165 187 } 166 188 … … 180 202 } 181 203 182 public virtual IEnumerator GetEnumerator() { 183 return matrix.GetEnumerator(); 204 public virtual IEnumerator<T> GetEnumerator() { 205 return matrix.Cast<T>().GetEnumerator(); 206 } 207 208 IEnumerator IEnumerable.GetEnumerator() { 209 return GetEnumerator(); 184 210 } 185 211
Note: See TracChangeset
for help on using the changeset viewer.