Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 14:13:06 (15 years ago)
Author:
gkronber
Message:

Refactored cloning in HL.Core, HL.Data and HL.Constraints

#285 (Cloning could be improved by creating objects at the bottom of the cloning chain with 'new' instead of the top with Activator.CreateInstance())

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Core/CompositeOperation.cs

    r776 r885  
    5959
    6060    /// <summary>
     61    /// Copy constructor to create a deep clone of a CompositeOperation instance.
     62    /// <remarks>Calls <see cref="CompositeOperation(CompositeOperation original,
     63    /// IDictionary<Guid, object> clonedObjects)"/></remarks> with an initially
     64    /// empty dictionary of cloned objects to create the clone.
     65    /// </summary>
     66    /// <param name="original">The original instance to be cloned.</param>
     67    public CompositeOperation(CompositeOperation original) : this(original, new Dictionary<Guid, object>()) { }
     68
     69    /// <summary>
     70    /// Copy constructor to create a deep clone of a CompositeOperation instance
     71    /// automatically reusing references of already cloned objects.
     72    /// </summary>
     73    /// <param name="original">The original instance to be cloned</param>
     74    /// <param name="clonedObjects">Already cloned object references</param>
     75    protected CompositeOperation(CompositeOperation original, IDictionary<Guid, object> clonedObjects)
     76      : base(original, clonedObjects) {
     77      this.myExecuteInParallel = original.ExecuteInParallel;
     78      for (int i = 0; i < original.Operations.Count; i++)
     79        this.AddOperation((IOperation)Auxiliary.Clone(original.Operations[i], clonedObjects));
     80    }
     81
     82    /// <summary>
    6183    /// Adds an operation to the current list of operations.
    6284    /// </summary>
     
    7799    /// </summary>
    78100    /// <remarks>All operations of the current instance are cloned, too (deep clone), with the
    79     /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>
    80     /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     101    /// copy consturctor <see cref="HeuristicLab.Core.CompositeOperation(
     102    /// CompositeOperation original, IDictionary<Guid, object> clonedObjects)"/>.</remarks>
     103    /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed for referential integrity.)</param>
    81104    /// <returns>The cloned operation as <see cref="CompositeOperation"/>.</returns>
    82105    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    83       CompositeOperation clone = new CompositeOperation();
    84       clonedObjects.Add(Guid, clone);
    85       clone.myExecuteInParallel = ExecuteInParallel;
    86       for (int i = 0; i < Operations.Count; i++)
    87         clone.AddOperation((IOperation)Auxiliary.Clone(Operations[i], clonedObjects));
    88       return clone;
     106      return new CompositeOperation(this, clonedObjects);
    89107    }
    90108
Note: See TracChangeset for help on using the changeset viewer.