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