Changeset 1667 for trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs
- Timestamp:
- 04/27/09 14:18:39 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public abstract class OperatorBase : ConstrainedItemBase, IOperator { 33 34 [Storable] 32 35 private string myName; 33 36 /// <summary> … … 59 62 get { return myCanceled; } 60 63 } 64 65 [Storable] 61 66 private bool myBreakpoint; 62 67 /// <inheritdoc/> … … 72 77 } 73 78 79 [Storable] 74 80 private List<IOperator> mySubOperators; 75 81 /// <summary> … … 80 86 get { return mySubOperators.AsReadOnly(); } 81 87 } 88 89 [Storable] 82 90 private Dictionary<string, IVariableInfo> myVariableInfos; 83 91 /// <inheritdoc/> … … 85 93 get { return myVariableInfos.Values; } 86 94 } 95 96 [Storable] 87 97 private Dictionary<string, IVariable> myVariables; 88 98 /// <inheritdoc/> … … 589 599 } 590 600 } 591 592 #region Persistence Methods593 /// <summary>594 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.595 /// </summary>596 /// <remarks>597 /// Calls <see cref="ConstrainedItemBase.GetXmlNode"/> of base class <see cref="ConstrainedItemBase"/>.598 /// <br/>A quick overview how the single elements of the current instance are saved:599 /// <list type="bullet">600 /// <item>601 /// <term>Name: </term>602 /// <description>Saved as an <see cref="XmlAttribute"/> with the name <c>Name</c>.</description>603 /// </item>604 /// <item>605 /// <term>Breakpoint: </term>606 /// <description>Is only saved if it set to <c>true</c>.607 /// Saved as an <see cref="XmlAttribute"/> with the name <c>Breakpoint</c>.</description>608 /// </item>609 /// <item>610 /// <term>Sub operators: </term>611 /// <description>Saved as child node with tag name <c>SubOperators</c>. All sub operators are themselves612 /// saved as child nodes.</description>613 /// </item>614 /// <item>615 /// <term>Variable infos: </term>616 /// <description>Saved as child node with tag name <c>VariableInfos</c>. All variable infos are themselves617 /// saved as child nodes.</description>618 /// </item>619 /// <item>620 /// <term>Variables: </term>621 /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves622 /// saved as child nodes.</description>623 /// </item>624 /// </list>625 /// </remarks>626 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>627 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>628 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>629 /// <returns>The saved <see cref="XmlNode"/>.</returns>630 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {631 XmlNode node = base.GetXmlNode(name, document, persistedObjects);632 XmlAttribute nameAttribute = document.CreateAttribute("Name");633 nameAttribute.Value = Name;634 node.Attributes.Append(nameAttribute);635 if (Breakpoint) {636 XmlAttribute breakpointAttribute = document.CreateAttribute("Breakpoint");637 breakpointAttribute.Value = Breakpoint.ToString();638 node.Attributes.Append(breakpointAttribute);639 }640 XmlNode subOperatorsNode = document.CreateNode(XmlNodeType.Element, "SubOperators", null);641 for (int i = 0; i < SubOperators.Count; i++)642 subOperatorsNode.AppendChild(PersistenceManager.Persist(SubOperators[i], document, persistedObjects));643 node.AppendChild(subOperatorsNode);644 XmlNode infosNode = document.CreateNode(XmlNodeType.Element, "VariableInfos", null);645 foreach (IVariableInfo info in myVariableInfos.Values)646 infosNode.AppendChild(PersistenceManager.Persist(info, document, persistedObjects));647 node.AppendChild(infosNode);648 XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null);649 foreach (IVariable variable in myVariables.Values)650 variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects));651 node.AppendChild(variablesNode);652 return node;653 }654 /// <summary>655 /// Loads the persisted operation from the specified <paramref name="node"/>.656 /// </summary>657 /// <remarks>Calls <see cref="ConstrainedItemBase.Populate"/> of base class658 /// <see cref="ConstrainedItemBase"/>.659 /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks>660 /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>661 /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>662 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {663 base.Populate(node, restoredObjects);664 myName = node.Attributes["Name"].Value;665 if (node.Attributes["Breakpoint"] != null)666 myBreakpoint = bool.Parse(node.Attributes["Breakpoint"].Value);667 XmlNode subOperatorsNode = node.SelectSingleNode("SubOperators");668 for (int i = 0; i < subOperatorsNode.ChildNodes.Count; i++)669 AddSubOperator((IOperator)PersistenceManager.Restore(subOperatorsNode.ChildNodes[i], restoredObjects));670 XmlNode infosNode = node.SelectSingleNode("VariableInfos");671 myVariableInfos.Clear();672 foreach (XmlNode infoNode in infosNode.ChildNodes)673 AddVariableInfo((IVariableInfo)PersistenceManager.Restore(infoNode, restoredObjects));674 XmlNode variablesNode = node.SelectSingleNode("Variables");675 myVariables.Clear();676 foreach (XmlNode variableNode in variablesNode.ChildNodes)677 AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects));678 }679 #endregion680 601 } 681 602 }
Note: See TracChangeset
for help on using the changeset viewer.