- Timestamp:
- 12/02/08 21:10:17 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactorBranch/HeuristicLab.Operators.Stopwatch/Stopwatch.cs
r693 r887 40 40 } 41 41 42 /// <summary> 43 /// Copy constructor to create deep clones. 44 /// </summary> 45 /// <param name="original">The instance to be cloned.</param> 46 public Stopwatch(Stopwatch original) : this(original, new Dictionary<Guid, object>()) { } 47 /// <summary> 48 /// Copy constructor to create deep clones reusing already cloned object references. 49 /// </summary> 50 /// <param name="original">The instance to be cloned.</param> 51 /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param> 52 protected Stopwatch(Stopwatch original, IDictionary<Guid, object> clonedObjects) 53 : base(original, clonedObjects) { 54 elapsedTime = original.elapsedTime; 55 if (original.running) this.Start(); 56 } 57 42 58 public void Start() { 43 59 stopwatch.Start(); … … 58 74 } 59 75 76 /// <summary> 77 /// Creates a deep clone with the copy constructor reusing already cloned 78 /// object references. 79 /// </summary> 80 /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param> 81 /// <returns>The cloned instance.</returns> 60 82 public override object Clone(IDictionary<Guid, object> clonedObjects) { 61 Stopwatch clone = (Stopwatch)base.Clone(clonedObjects); 62 if(running) clone.Start(); 63 clone.elapsedTime = elapsedTime; 64 return clone; 83 return new Stopwatch(this, clonedObjects); 65 84 } 66 85 67 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {86 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 68 87 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 69 88 XmlAttribute runningAttr = document.CreateAttribute("Running"); … … 75 94 return node; 76 95 } 77 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {96 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 78 97 long elapsedTicks = long.Parse(node.Attributes["ElapsedTicks"].Value); 79 98 elapsedTime = TimeSpan.FromTicks(elapsedTicks); 80 99 running = bool.Parse(node.Attributes["Running"].Value); 81 if (running) stopwatch.Start();100 if (running) stopwatch.Start(); 82 101 base.Populate(node, restoredObjects); 83 102 }
Note: See TracChangeset
for help on using the changeset viewer.