Changeset 1669 for trunk/sources/HeuristicLab.Data/3.3/IntMatrixData.cs
- Timestamp:
- 04/27/09 14:45:44 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data/3.3/IntMatrixData.cs
r1529 r1669 66 66 67 67 /// <summary> 68 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.69 /// </summary>70 /// <remarks>The dimensions of the matrix are saved as attributes (<c>Dimension1</c>,<c>Dimension2</c>),71 /// formatted according to the local culture info and its number format.<br/>72 /// The elements of the matrix are saved as string in the node's inner text,73 /// each element separated by a semicolon, all line by line, formatted according to74 /// the local number format.</remarks>75 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>76 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>77 /// <param name="persistedObjects">The dictionary of all already persisted objects.78 /// (Needed to avoid cycles.)</param>79 /// <returns>The saved <see cref="XmlNode"/>.</returns>80 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {81 XmlNode node = base.GetXmlNode(name, document, persistedObjects);82 XmlAttribute dim1 = document.CreateAttribute("Dimension1");83 dim1.Value = Data.GetLength(0).ToString(CultureInfo.InvariantCulture.NumberFormat);84 node.Attributes.Append(dim1);85 XmlAttribute dim2 = document.CreateAttribute("Dimension2");86 dim2.Value = Data.GetLength(1).ToString(CultureInfo.InvariantCulture.NumberFormat);87 node.Attributes.Append(dim2);88 node.InnerText = ToString(CultureInfo.InvariantCulture.NumberFormat);89 return node;90 }91 /// <summary>92 /// Loads the persisted int matrix from the specified <paramref name="node"/>.93 /// </summary>94 /// <remarks>The dimensions of the matrix must be saved as Attributes95 /// (<c>Dimension1</c>, <c>Dimension2</c>), formatted in the local number format. <br/>96 /// The elements of the matrix must be saved in the node's inner text as string,97 /// each element separated by a semicolon, line by line, formatted according to98 /// the local number format (see <see cref="GetXmlNode"/>).</remarks>99 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>100 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>101 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {102 base.Populate(node, restoredObjects);103 int dim1 = int.Parse(node.Attributes["Dimension1"].Value, CultureInfo.InvariantCulture.NumberFormat);104 int dim2 = int.Parse(node.Attributes["Dimension2"].Value, CultureInfo.InvariantCulture.NumberFormat);105 string[] tokens = node.InnerText.Split(';');106 int[,] data = new int[dim1, dim2];107 for (int i = 0; i < dim1; i++) {108 for (int j = 0; j < dim2; j++) {109 data[i, j] = int.Parse(tokens[i * dim2 + j], CultureInfo.InvariantCulture.NumberFormat);110 }111 }112 Data = data;113 }114 115 /// <summary>116 68 /// The string representation of the matrix. 117 69 /// </summary>
Note: See TracChangeset
for help on using the changeset viewer.