- Timestamp:
- 03/05/13 16:37:17 (11 years ago)
- Location:
- branches/ImprovingStringConvertibleMatrix
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ImprovingStringConvertibleMatrix
-
Property
svn:ignore
set to
*.suo
-
Property
svn:ignore
set to
-
branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/IntMatrix.cs
r7259 r9286 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using System.Text; 24 26 using HeuristicLab.Common; … … 29 31 [Item("IntMatrix", "Represents a matrix of integer values.")] 30 32 [StorableClass] 31 public class IntMatrix : ValueTypeMatrix<int> , IStringConvertibleMatrix{33 public class IntMatrix : ValueTypeMatrix<int> { 32 34 [StorableConstructor] 33 35 protected IntMatrix(bool deserializing) : base(deserializing) { } … … 38 40 public IntMatrix(int rows, int columns) : base(rows, columns) { } 39 41 public IntMatrix(int rows, int columns, IEnumerable<string> columnNames) : base(rows, columns, columnNames) { } 40 public IntMatrix(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(rows, columns, columnNames,rowNames) { }42 public IntMatrix(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(rows, columns, columnNames, rowNames) { } 41 43 public IntMatrix(int[,] elements) : base(elements) { } 42 public IntMatrix(int[,] elements, IEnumerable<string> columnNames) : base(elements, columnNames) { }43 public IntMatrix(int[,] elements, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(elements, columnNames,rowNames) { }44 public IntMatrix(int[,] elements, IEnumerable<string> columnNames) : base(elements, columnNames) { } 45 public IntMatrix(int[,] elements, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(elements, columnNames, rowNames) { } 44 46 45 47 public override IDeepCloneable Clone(Cloner cloner) { … … 47 49 } 48 50 49 protected virtualbool Validate(string value, out string errorMessage) {51 protected override bool Validate(string value, out string errorMessage) { 50 52 int val; 51 53 bool valid = int.TryParse(value, out val); … … 60 62 return valid; 61 63 } 62 protected virtualstring GetValue(int rowIndex, int columIndex) {64 protected override string GetValue(int rowIndex, int columIndex) { 63 65 return this[rowIndex, columIndex].ToString(); 64 66 } 65 protected virtualbool SetValue(string value, int rowIndex, int columnIndex) {67 protected override bool SetValue(string value, int rowIndex, int columnIndex) { 66 68 int val; 67 69 if (int.TryParse(value, out val)) { … … 72 74 } 73 75 } 74 75 #region IStringConvertibleMatrix Members 76 int IStringConvertibleMatrix.Rows { 77 get { return Rows; } 78 set { Rows = value; } 76 protected override bool SetValue(IEnumerable<RowColumnValue> rowColumnValues) { 77 if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringMatrix is read-only."); 78 List<Tuple<Position, int>> newValues = new List<Tuple<Position, int>>(); 79 int parsed; 80 foreach (var curValue in rowColumnValues) { 81 if (int.TryParse(curValue.Value, out parsed)) { 82 newValues.Add(new Tuple<Position, int>(curValue.Position, parsed)); 83 } else { 84 return false; 85 } 86 } 87 Position pos; 88 foreach (var curValue in newValues) { 89 pos = curValue.Item1; 90 matrix[pos.Row, pos.Column] = curValue.Item2; 91 } 92 OnItemsChanged(rowColumnValues.Select(x => x.Position)); 93 return true; 79 94 } 80 int IStringConvertibleMatrix.Columns {81 get { return Columns; }82 set { Columns = value; }83 }84 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {85 return Validate(value, out errorMessage);86 }87 string IStringConvertibleMatrix.GetValue(int rowIndex, int columIndex) {88 return GetValue(rowIndex, columIndex);89 }90 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {91 return SetValue(value, rowIndex, columnIndex);92 }93 #endregion94 95 } 95 96 }
Note: See TracChangeset
for help on using the changeset viewer.