Changeset 836
- Timestamp:
- 11/27/08 00:52:23 (16 years ago)
- Location:
- branches/CloningRefactorBranch
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactorBranch/HeuristicLab.Core/AtomicOperation.cs
r776 r836 47 47 /// <summary> 48 48 /// Initializes a new instance of <see cref="AtomicOperation"/>. 49 /// Empty constructor is needed for the persistence mechanism. 49 50 /// </summary> 50 51 public AtomicOperation() { } -
branches/CloningRefactorBranch/HeuristicLab.Core/ConstrainedItemBase.cs
r776 r836 47 47 48 48 /// <summary> 49 /// C lones the current instance (deep clone).49 /// Copy constructor for deep cloning. 50 50 /// </summary> 51 /// <remarks>Calls <see cref="StorableBase.Clone 52 /// (System.Collections.Generic.IDictionary<System.Guid, object>)"/> 53 /// of base class <see cref="ItemBase"/>.<br/> 54 /// Deep clone through <see cref="Auxiliary.Clone"/> method of helper class 55 /// <see cref="Auxiliary"/>.</remarks> 56 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 57 /// <returns>The cloned object as <see cref="ConstrainedItemBase"/>.</returns> 58 public override object Clone(IDictionary<Guid, object> clonedObjects) { 59 ConstrainedItemBase clone = (ConstrainedItemBase)base.Clone(clonedObjects); 60 clone.myConstraints.Clear(); 61 foreach (IConstraint constraint in Constraints) 62 clone.AddConstraint((IConstraint)Auxiliary.Clone(constraint, clonedObjects)); 63 return clone; 51 /// <param name="original"></param> 52 /// <param name="clonedObjects"></param> 53 protected ConstrainedItemBase(ConstrainedItemBase original, IDictionary<Guid, object> clonedObjects) 54 : base(original, clonedObjects) { 55 myConstraints = new List<IConstraint>(); 56 foreach (IConstraint constraint in original.myConstraints) 57 AddConstraint((IConstraint)Auxiliary.Clone(constraint, clonedObjects)); 64 58 } 65 59 … … 145 139 } 146 140 147 #region Persistence Methods 141 #region Persistence Methods 148 142 /// <summary> 149 143 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. … … 157 151 /// (Needed to avoid cycles.)</param> 158 152 /// <returns>The saved <see cref="XmlNode"/>.</returns> 159 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {153 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 160 154 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 161 155 if (Constraints.Count > 0) { … … 176 170 /// <param name="restoredObjects">The dictionary of all already restored objects. 177 171 /// (Needed to avoid cycles.)</param> 178 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {172 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 179 173 base.Populate(node, restoredObjects); 180 174 XmlNode constraintsNode = node.SelectSingleNode("Constraints"); -
branches/CloningRefactorBranch/HeuristicLab.Core/EngineBase.cs
r776 r836 118 118 119 119 /// <summary> 120 /// Copy constructor. 121 /// </summary> 122 /// <param name="original"></param> 123 /// <param name="clonedObjects"></param> 124 protected EngineBase(EngineBase original, IDictionary<Guid, object> clonedObjects) 125 : base(original, clonedObjects) { 126 this.myOperatorGraph = (IOperatorGraph)Auxiliary.Clone(original.OperatorGraph, clonedObjects); 127 this.myGlobalScope = (IScope)Auxiliary.Clone(original.GlobalScope, clonedObjects); 128 this.myExecutionTime = original.ExecutionTime; 129 IOperation[] operations = new IOperation[original.ExecutionStack.Count]; 130 original.ExecutionStack.CopyTo(operations, 0); 131 for (int i = operations.Length - 1; i >= 0; i--) 132 this.myExecutionStack.Push((IOperation)Auxiliary.Clone(operations[i], clonedObjects)); 133 this.myRunning = original.Running; 134 this.myCanceled = original.Canceled; 135 } 136 137 /// <summary> 120 138 /// Clones the current instance (deep clone). 121 139 /// </summary> … … 125 143 /// <returns>The cloned object as <see cref="EngineBase"/>.</returns> 126 144 public override object Clone(IDictionary<Guid, object> clonedObjects) { 127 EngineBase clone = (EngineBase)base.Clone(clonedObjects); 128 clone.myOperatorGraph = (IOperatorGraph)Auxiliary.Clone(OperatorGraph, clonedObjects); 129 clone.myGlobalScope = (IScope)Auxiliary.Clone(GlobalScope, clonedObjects); 130 clone.myExecutionTime = ExecutionTime; 131 IOperation[] operations = new IOperation[ExecutionStack.Count]; 132 ExecutionStack.CopyTo(operations, 0); 133 for (int i = operations.Length - 1; i >= 0; i--) 134 clone.myExecutionStack.Push((IOperation)Auxiliary.Clone(operations[i], clonedObjects)); 135 clone.myRunning = Running; 136 clone.myCanceled = Canceled; 137 return clone; 138 145 return new EngineBase(this, clonedObjects); 139 146 } 140 147 -
branches/CloningRefactorBranch/HeuristicLab.Core/ItemBase.cs
r776 r836 30 30 /// </summary> 31 31 public abstract class ItemBase : StorableBase, IItem { 32 /// <summary> 33 /// Creates an instance of an ItemBase. 34 /// </summary> 35 protected ItemBase() { } 36 37 /// <summary> 38 /// Copy constructor for deep cloning of items. 39 /// </summary> 40 /// <param name="original"></param> 41 /// <param name="clonedObjects"></param> 42 protected ItemBase(ItemBase original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { } 43 32 44 /// <summary> 33 45 /// Creates a new instance of <see cref="ItemBaseView"/> for -
branches/CloningRefactorBranch/HeuristicLab.Core/OperatorBase.cs
r776 r836 105 105 106 106 /// <summary> 107 /// Clones the current instance (deep clone). 108 /// </summary> 109 /// <remarks>Clones also sub operators, variables and variable infos.</remarks> 110 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 111 /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns> 112 public override object Clone(IDictionary<Guid, object> clonedObjects) { 113 OperatorBase clone = (OperatorBase)base.Clone(clonedObjects); 114 clone.myName = Name; 115 clone.mySubOperators.Clear(); 116 for (int i = 0; i < SubOperators.Count; i++) 117 clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects)); 118 clone.myVariableInfos.Clear(); 119 foreach (IVariableInfo variableInfo in myVariableInfos.Values) 120 clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects)); 121 clone.myVariables.Clear(); 122 foreach (IVariable variable in myVariables.Values) 123 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 124 return clone; 107 /// Copy constructor 108 /// </summary> 109 /// <param name="original"></param> 110 /// <param name="clonedObjects"></param> 111 protected OperatorBase(OperatorBase original, IDictionary<Guid, object> clonedObjects) 112 : base(original, clonedObjects) { 113 this.myName = original.Name; 114 this.mySubOperators = new List<IOperator>(); 115 for (int i = 0; i < original.SubOperators.Count; i++) 116 AddSubOperator((IOperator)Auxiliary.Clone(original.SubOperators[i], clonedObjects)); 117 this.myVariableInfos = new Dictionary<string, IVariableInfo>(); 118 foreach (IVariableInfo variableInfo in original.myVariableInfos.Values) 119 AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects)); 120 this.myVariables = new Dictionary<string, IVariable>(); 121 foreach (IVariable variable in original.myVariables.Values) 122 AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 125 123 } 126 124 … … 628 626 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 629 627 /// <returns>The saved <see cref="XmlNode"/>.</returns> 630 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {628 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 631 629 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 632 630 XmlAttribute nameAttribute = document.CreateAttribute("Name"); … … 660 658 /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param> 661 659 /// <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) {660 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 663 661 base.Populate(node, restoredObjects); 664 662 myName = node.Attributes["Name"].Value; -
branches/CloningRefactorBranch/HeuristicLab.Core/OperatorGroup.cs
r776 r836 71 71 72 72 /// <summary> 73 /// Copy constructor for deep cloning 74 /// </summary> 75 /// <param name="original"></param> 76 /// <param name="clonedObjects"></param> 77 protected OperatorGroup(OperatorGroup original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { 78 this.myName = original.myName; 79 mySubGroups = new List<IOperatorGroup>(); 80 myOperators = new List<IOperator>(); 81 foreach (IOperatorGroup group in original.SubGroups) 82 AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects)); 83 foreach (IOperator op in original.Operators) 84 AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects)); 85 } 86 87 /// <summary> 73 88 /// Clones the current instance (deep clone). 74 89 /// </summary> … … 78 93 /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns> 79 94 public override object Clone(IDictionary<Guid, object> clonedObjects) { 80 OperatorGroup clone = (OperatorGroup)base.Clone(clonedObjects); 81 clone.myName = Name; 82 foreach (IOperatorGroup group in SubGroups) 83 clone.AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects)); 84 foreach (IOperator op in Operators) 85 clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects)); 95 OperatorGroup clone = new OperatorGroup(this, clonedObjects); 86 96 return clone; 87 97 } -
branches/CloningRefactorBranch/HeuristicLab.Core/Scope.cs
r776 r836 32 32 private IScope parent; 33 33 34 private string myName; 34 private string myName; 35 35 /// <summary> 36 36 /// Gets the name of the current scope. … … 75 75 : this() { 76 76 if (name != null) myName = name; 77 } 78 79 /// <summary> 80 /// Copy constructor to create deep clones. 81 /// </summary> 82 /// <param name="original"></param> 83 /// <param name="clonedObjects"></param> 84 protected Scope(Scope original, IDictionary<Guid, object> clonedObjects) 85 : base(original, clonedObjects) { 86 this.myName = original.Name; 87 foreach (IVariable variable in original.myVariables.Values) 88 AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 89 foreach (KeyValuePair<string, string> alias in original.myAliases) 90 AddAlias(alias.Key, alias.Value); 91 for (int i = 0; i < original.SubScopes.Count; i++) 92 AddSubScope((IScope)Auxiliary.Clone(original.SubScopes[i], clonedObjects)); 77 93 } 78 94 … … 238 254 RemoveVariable(variableNames[j]); 239 255 240 KeyValuePair<string, string>[] aliases = new KeyValuePair<string, string>[myAliases.Count];256 KeyValuePair<string, string>[] aliases = new KeyValuePair<string, string>[myAliases.Count]; 241 257 myAliases.CopyTo(aliases, 0); 242 258 for (int j = 0; j < aliases.Length; j++) … … 249 265 /// <inheritdoc/> 250 266 public override object Clone(IDictionary<Guid, object> clonedObjects) { 251 Scope clone = (Scope)base.Clone(clonedObjects); 252 clone.myName = Name; 253 254 foreach (IVariable variable in myVariables.Values) 255 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 256 foreach (KeyValuePair<string, string> alias in myAliases) 257 clone.AddAlias(alias.Key, alias.Value); 258 for (int i = 0; i < SubScopes.Count; i++) 259 clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects)); 260 261 return clone; 267 return new Scope(this, clonedObjects); 262 268 } 263 269 … … 369 375 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 370 376 /// <returns>The saved <see cref="XmlNode"/>.</returns> 371 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {377 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 372 378 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 373 379 XmlAttribute nameAttribute = document.CreateAttribute("Name"); … … 409 415 /// <param name="restoredObjects">The dictionary of all already restored objects. 410 416 /// (Needed to avoid cycles.)</param> 411 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {417 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 412 418 base.Populate(node, restoredObjects); 413 419 myName = node.Attributes["Name"].Value; -
branches/CloningRefactorBranch/HeuristicLab.Core/StorableBase.cs
r776 r836 46 46 47 47 /// <summary> 48 /// Copy constructor to create a deep clone of the original object 49 /// </summary> 50 /// <param name="original">The object to be cloned</param> 51 protected StorableBase(StorableBase original, IDictionary<Guid, object> clonedObjects) : this() { 52 clonedObjects.Add(myGuid, this); 53 } 54 55 /// <summary> 48 56 /// Clones the current instance (deep clone). 49 57 /// </summary> … … 54 62 } 55 63 /// <summary> 56 /// Clones the current instance with the <see cref="M:Activator.CreateInstance"/>57 /// method of <see cref="Activator"/>.64 /// Default implementation of clone throws NotSupportedException. 65 /// All actually cloneable objects must override this method. 58 66 /// </summary> 59 67 /// <param name="clonedObjects">All already cloned objects.</param> 60 /// <returns> The clone.</returns>68 /// <returns>Nothing</returns> 61 69 public virtual object Clone(IDictionary<Guid, object> clonedObjects) { 62 object clone = Activator.CreateInstance(this.GetType()); 63 clonedObjects.Add(Guid, clone); 64 return clone; 70 throw new NotSupportedException("Can't clone abstract type StorableBase."); 65 71 } 66 72 … … 74 80 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 75 81 /// <returns>The saved <see cref="XmlNode"/>.</returns> 76 public virtual XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {82 public virtual XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 77 83 XmlNode node = document.CreateNode(XmlNodeType.Element, name, null); 78 84 XmlAttribute typeAttribute = document.CreateAttribute("Type"); … … 91 97 /// <param name="restoredObjects">The dictionary of all already restored objects. 92 98 /// (Needed to avoid cycles.)</param> 93 public virtual void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {99 public virtual void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 94 100 myGuid = new Guid(node.Attributes["GUID"].Value); 95 101 } -
branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedDoubleData.cs
r763 r836 56 56 } 57 57 58 /// <summary> 59 /// Copy constructor for deep cloning of ConstrainedDoubleData items. 60 /// </summary> 61 /// <param name="original"></param> 62 /// <param name="clonedObjects"></param> 63 protected ConstrainedDoubleData(ConstrainedDoubleData original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { } 64 58 65 /// <inheritdoc cref="ConstrainedObjectData.TrySetData(object)"/> 59 66 public virtual bool TrySetData(double data) { … … 80 87 /// <returns>The cloned instance as <see cref="ConstrainedDoubleData"/>.</returns> 81 88 public override object Clone(IDictionary<Guid, object> clonedObjects) { 82 ConstrainedDoubleData clone = (ConstrainedDoubleData)base.Clone(clonedObjects); 83 return clone; 89 return new ConstrainedDoubleData(this, clonedObjects); 84 90 } 85 91 -
branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedIntData.cs
r763 r836 56 56 } 57 57 58 /// <summary> 59 /// Copy constructor for deep cloning of ConstrainedDoubleData items. 60 /// </summary> 61 /// <param name="original"></param> 62 /// <param name="clonedObjects"></param> 63 protected ConstrainedIntData(ConstrainedIntData original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { } 64 58 65 /// <inheritdoc cref="ConstrainedObjectData.TrySetData(object)"/> 59 66 public virtual bool TrySetData(int data) { … … 80 87 /// <returns>The clone instance as <see cref="ConstrainedIntData"/>.</returns> 81 88 public override object Clone(IDictionary<Guid, object> clonedObjects) { 82 ConstrainedIntData clone = (ConstrainedIntData)base.Clone(clonedObjects); 83 return clone; 89 return new ConstrainedIntData(this, clonedObjects); 84 90 } 85 91
Note: See TracChangeset
for help on using the changeset viewer.