- Timestamp:
- 03/05/13 16:37:17 (12 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/DoubleMatrix.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("DoubleMatrix", "Represents a matrix of double values.")] 30 32 [StorableClass] 31 public class DoubleMatrix : ValueTypeMatrix<double> , IStringConvertibleMatrix{33 public class DoubleMatrix : ValueTypeMatrix<double> { 32 34 [StorableConstructor] 33 35 protected DoubleMatrix(bool deserializing) : base(deserializing) { } … … 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 double val; 51 53 bool valid = double.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 double val; 67 69 if (double.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, double>> newValues = new List<Tuple<Position, double>>(); 79 double parsed; 80 foreach (var curValue in rowColumnValues) { 81 if (double.TryParse(curValue.Value, out parsed)) { 82 newValues.Add(new Tuple<Position, double>(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.