Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 21:10:17 (16 years ago)
Author:
gkronber
Message:

Refactored cloning in all plugins except: HL.Communication, HL.Hive, HL.GP, HL.Routing, HL.Scheduling, HL.SimOpt, HL.Visualization

#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.Operators.Programmable/ProgrammableOperator.cs

    r694 r887  
    5555    }
    5656
     57    /// <summary>
     58    /// Default constructor.
     59    /// </summary>
    5760    public ProgrammableOperator() {
    5861      myCode = "Result.Data = true;";
     
    6063      AddVariableInfo(new VariableInfo("Result", "A computed variable", typeof(BoolData), VariableKind.New | VariableKind.Out));
    6164      executeMethod = null;
     65    }
     66
     67
     68    /// <summary>
     69    /// Copy constructor to create deep clones.
     70    /// </summary>
     71    /// <param name="original">The instance to be cloned.</param>
     72    public ProgrammableOperator(ProgrammableOperator original) : this(original, new Dictionary<Guid, object>()) { }
     73    /// <summary>
     74    /// Copy constructor to create a deep clone of an ProgrammableOperator instance.
     75    /// </summary>
     76    /// <param name="original">The original instance to be cloned.</param>
     77    /// <param name="clonedObjects">Already cloned object references.</param>
     78    protected ProgrammableOperator(ProgrammableOperator original, IDictionary<Guid, object> clonedObjects)
     79      : base(original, clonedObjects) {
     80      this.myDescription = original.Description;
     81      this.myCode = original.Code;
     82      this.executeMethod = original.executeMethod;
    6283    }
    6384
     
    143164    }
    144165
    145     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    146       ProgrammableOperator clone = (ProgrammableOperator)base.Clone(clonedObjects);
    147       clone.myDescription = Description;
    148       clone.myCode = Code;
    149       clone.executeMethod = executeMethod;
    150       return clone;
    151     }
    152 
    153166    public override IOperation Apply(IScope scope) {
    154167      if (executeMethod == null) {
     
    196209    }
    197210
     211
     212    /// <summary>
     213    /// Creates a deep clone with the copy constructor reusing already cloned
     214    /// object references.
     215    /// </summary>
     216    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     217    /// <returns>The cloned instance.</returns>
     218    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     219      return new ProgrammableOperator(this, clonedObjects);
     220    }
    198221    #region Persistence Methods
    199222    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
Note: See TracChangeset for help on using the changeset viewer.