- Timestamp:
- 12/02/08 14:13:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactorBranch/HeuristicLab.Data/DoubleArrayData.cs
r763 r885 56 56 Data = data; 57 57 } 58 /// <summary> 59 /// Copy constructor to create clones (deep). 60 /// </summary> 61 /// <param name="original">The original instance to be cloned.</param> 62 public DoubleArrayData(DoubleArrayData original) : this(original, new Dictionary<Guid, object>()) { } 63 /// <summary> 64 /// Copy constructor to create clones (deep) reusing already cloned object references. 65 /// </summary> 66 /// <param name="original">The instance to be cloned.</param> 67 /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param> 68 protected DoubleArrayData(DoubleArrayData original, IDictionary<Guid, object> clonedObjects) 69 : base(original, clonedObjects) { } 58 70 59 71 /// <summary> … … 63 75 public override IView CreateView() { 64 76 return new DoubleArrayDataView(this); 77 } 78 79 /// <summary> 80 /// Clones an instance using the copy constructor 81 /// reusing already cloned object references. 82 /// </summary> 83 /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param> 84 /// <returns>A cloned (deep) instance</returns> 85 public override object Clone(IDictionary<Guid, object> clonedObjects) { 86 return new DoubleArrayData(this, clonedObjects); 65 87 } 66 88 … … 74 96 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 75 97 /// <returns>The saved <see cref="XmlNode"></see>.</returns> 76 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {98 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 77 99 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 78 100 node.InnerText = ToString(CultureInfo.InvariantCulture.NumberFormat); 79 101 return node; 80 102 } 81 103 82 104 /// <summary> 83 105 /// Loads the persisted double array from the specified <paramref name="node"/>. … … 89 111 /// <param name="node">The <see cref="XmlNode"></see> where the instance is saved.</param> 90 112 /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param> 91 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {113 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 92 114 base.Populate(node, restoredObjects); 93 115 string[] tokens = node.InnerText.Split(';'); 94 116 double[] data = new double[tokens.Length]; 95 for (int i = 0; i < data.Length; i++)96 if (double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == false) {117 for (int i = 0; i < data.Length; i++) 118 if (double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == false) { 97 119 throw new FormatException("Can't parse " + tokens[i] + " as double value."); 98 120 } … … 109 131 private string ToString(NumberFormatInfo format) { 110 132 StringBuilder builder = new StringBuilder(); 111 for (int i = 0; i < Data.Length; i++) {133 for (int i = 0; i < Data.Length; i++) { 112 134 builder.Append(";"); 113 135 builder.Append(Data[i].ToString("r", format)); 114 136 } 115 if (builder.Length > 0)137 if (builder.Length > 0) 116 138 builder.Remove(0, 1); 117 139 return builder.ToString();
Note: See TracChangeset
for help on using the changeset viewer.