Free cookie consent management tool by TermsFeed Policy Generator

Changeset 885


Ignore:
Timestamp:
12/02/08 14:13:06 (16 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())

Location:
branches/CloningRefactorBranch
Files:
44 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/AllSubOperatorsTypeConstraint.cs

    r764 r885  
    4242    }
    4343
    44     public AllSubOperatorsTypeConstraint()
    45       : base() {
     44    /// <summary>
     45    /// Default constructor for an empty AllSubOperatorsTypeConstraint.
     46    /// </summary>
     47    public AllSubOperatorsTypeConstraint() {
    4648      groupConstraint = new SubOperatorTypeConstraint();
     49    }
     50    /// <summary>
     51    /// Copy constructor to create clones (deep).
     52    /// </summary>
     53    /// <param name="original">The original instance to be cloned.</param>
     54    public AllSubOperatorsTypeConstraint(AllSubOperatorsTypeConstraint original)
     55      : this(original, new Dictionary<Guid, object>()) { }
     56    /// <summary>
     57    /// Copy constructor to create clones (deep) reusing already cloned object references.
     58    /// </summary>
     59    /// <param name="original">The instance to be cloned.</param>
     60    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     61    protected AllSubOperatorsTypeConstraint(AllSubOperatorsTypeConstraint original, IDictionary<Guid, object> clonedObjects)
     62      : base(original, clonedObjects) {
     63      this.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(original.groupConstraint, clonedObjects);
    4764    }
    4865
     
    5976    public override bool Check(IItem data) {
    6077      IOperator op = data as IOperator;
    61       if(data == null) return false;
     78      if (data == null) return false;
    6279
    63       for(int i = 0; i < op.SubOperators.Count; i++) {
     80      for (int i = 0; i < op.SubOperators.Count; i++) {
    6481        groupConstraint.SubOperatorIndex.Data = i;
    65         if(groupConstraint.Check(data) == false) {
     82        if (groupConstraint.Check(data) == false) {
    6683          return false;
    6784        }
     
    7592
    7693    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    77       AllSubOperatorsTypeConstraint clone = new AllSubOperatorsTypeConstraint();
    78       clonedObjects.Add(Guid, clone);
    79       clone.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(groupConstraint, clonedObjects);
    80       return clone;
     94      return new AllSubOperatorsTypeConstraint(this);
    8195    }
    8296
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/AndConstraint.cs

    r764 r885  
    4444    }
    4545
     46    /// <summary>
     47    /// Default constructor for an empty AndConstraint.
     48    /// </summary>
    4649    public AndConstraint() {
    4750      clauses = new ItemList<IConstraint>();
     51    }
     52
     53    /// <summary>
     54    /// Copy constructor to create clones (deep).
     55    /// </summary>
     56    /// <param name="original">The original instance to be cloned.</param>
     57    public AndConstraint(AndConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     58   /// <summary>
     59    /// Copy constructor to create clones (deep) reusing already cloned object references.
     60    /// </summary>
     61    /// <param name="original">The instance to be cloned.</param>
     62    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     63    protected AndConstraint(AndConstraint original, IDictionary<Guid, object> clonedObjects)
     64      : base(original, clonedObjects) {
     65      this.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(original.Clauses, clonedObjects);
    4866    }
    4967
     
    6078      return new AndConstraintView(this);
    6179    }
    62 
     80    /// <summary>
     81    /// Uses copy constructor to create a deep clone reusing already cloned object references.
     82    /// </summary>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     84    /// <returns></returns>
    6385    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       AndConstraint clone = new AndConstraint();
    65       clonedObjects.Add(Guid, clone);
    66       clone.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(Clauses, clonedObjects);
    67       return clone;
     86      return new AndConstraint(this, clonedObjects);
    6887    }
    6988
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/ConstraintBase.cs

    r764 r885  
    3232    }
    3333
     34    /// <summary>
     35    /// Default constructor
     36    /// </summary>
     37    protected ConstraintBase() { }
     38
     39    /// <summary>
     40    /// Copy constructor to create clones (deep) reusing already cloned object references.
     41    /// </summary>
     42    /// <param name="original">The instance to be cloned.</param>
     43    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     44    protected ConstraintBase(ConstraintBase original, IDictionary<Guid, object> clonedObjects)
     45      : base(original, clonedObjects) { }
     46
    3447    public abstract bool Check(IItem data);
    3548  }
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/DoubleBoundedConstraint.cs

    r764 r885  
    101101    }
    102102
     103    /// <summary>
     104    /// Copy constructor to create clones (deep).
     105    /// </summary>
     106    /// <param name="original">The original instance to be cloned.</param>
     107    public DoubleBoundedConstraint(DoubleBoundedConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     108   /// <summary>
     109    /// Copy constructor to create clones (deep) reusing already cloned object references.
     110    /// </summary>
     111    /// <param name="original">The instance to be cloned.</param>
     112    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     113    protected DoubleBoundedConstraint(DoubleBoundedConstraint original, IDictionary<Guid, object> clonedObjects)
     114      : base(original, clonedObjects) {
     115      this.upperBound = original.UpperBound;
     116      this.upperBoundIncluded = original.UpperBoundIncluded;
     117      this.upperBoundEnabled = original.UpperBoundEnabled;
     118      this.lowerBound = original.LowerBound;
     119      this.lowerBoundIncluded = original.LowerBoundIncluded;
     120      this.lowerBoundEnabled = original.LowerBoundEnabled;
     121    }
    103122
    104123    public override bool Check(IItem data) {
     
    116135    }
    117136
     137    /// <summary>
     138    /// Clones an instance using the copy constructor
     139    /// reusing already cloned object references.
     140    /// </summary>
     141    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     142    /// <returns>A cloned (deep) instance</returns>
    118143    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    119       DoubleBoundedConstraint clone = new DoubleBoundedConstraint();
    120       clonedObjects.Add(Guid, clone);
    121       clone.upperBound = UpperBound;
    122       clone.upperBoundIncluded = UpperBoundIncluded;
    123       clone.upperBoundEnabled = UpperBoundEnabled;
    124       clone.lowerBound = LowerBound;
    125       clone.lowerBoundIncluded = LowerBoundIncluded;
    126       clone.lowerBoundEnabled = LowerBoundEnabled;
    127       return clone;
     144      return new DoubleBoundedConstraint(this, clonedObjects);
    128145    }
    129146
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/FalseConstraint.cs

    r764 r885  
    3131      get { return "This constraint is always false."; }
    3232    }
     33    /// <summary>
     34    /// Default constructor.
     35    /// </summary>
     36    public FalseConstraint() { }
     37    /// <summary>
     38    /// Copy constructor to create clones (deep).
     39    /// </summary>
     40    /// <param name="original">The original instance to be cloned.</param>
     41    public FalseConstraint(FalseConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     42    /// <summary>
     43    /// Copy constructor to create clones (deep) reusing already cloned object references.
     44    /// </summary>
     45    /// <param name="original">The instance to be cloned.</param>
     46    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     47    protected FalseConstraint(FalseConstraint original, IDictionary<Guid, object> clonedObjects)
     48      : base(original, clonedObjects) { }
    3349
    3450    public override IView CreateView() {
     
    3652    }
    3753
     54    /// <summary>
     55    /// Clones an instance using the copy constructor
     56    /// reusing already cloned object references.
     57    /// </summary>
     58    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     59    /// <returns>A cloned (deep) instance</returns>
    3860    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    39       FalseConstraint clone = new FalseConstraint();
    40       clonedObjects.Add(Guid, clone);
    41       return clone;
     61      return new FalseConstraint(this, clonedObjects);
    4262    }
    4363
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/IntBoundedConstraint.cs

    r764 r885  
    8686    }
    8787
    88     public IntBoundedConstraint(int low, int high) : base() {
     88    public IntBoundedConstraint(int low, int high)
     89      : base() {
    8990      lowerBound = low;
    9091      lowerBoundIncluded = false;
     
    9394      upperBoundIncluded = false;
    9495      upperBoundEnabled = true;
     96    }
     97    /// <summary>
     98    /// Copy constructor to create clones (deep).
     99    /// </summary>
     100    /// <param name="original">The original instance to be cloned.</param>
     101    public IntBoundedConstraint(IntBoundedConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     102    /// <summary>
     103    /// Copy constructor to create clones (deep) reusing already cloned object references.
     104    /// </summary>
     105    /// <param name="original">The instance to be cloned.</param>
     106    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     107    protected IntBoundedConstraint(IntBoundedConstraint original, IDictionary<Guid, object> clonedObjects)
     108      : base(original, clonedObjects) {
     109      this.upperBound = original.UpperBound;
     110      this.upperBoundIncluded = original.UpperBoundIncluded;
     111      this.upperBoundEnabled = original.UpperBoundEnabled;
     112      this.lowerBound = original.LowerBound;
     113      this.lowerBoundIncluded = original.LowerBoundIncluded;
     114      this.lowerBoundEnabled = original.LowerBoundEnabled;
    95115    }
    96116
     
    109129    }
    110130
     131    /// <summary>
     132    /// Clones an instance using the copy constructor
     133    /// reusing already cloned object references.
     134    /// </summary>
     135    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     136    /// <returns>A cloned (deep) instance</returns>
    111137    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    112       IntBoundedConstraint clone = new IntBoundedConstraint();
    113       clonedObjects.Add(Guid, clone);
    114       clone.upperBound = UpperBound;
    115       clone.upperBoundIncluded = UpperBoundIncluded;
    116       clone.upperBoundEnabled = UpperBoundEnabled;
    117       clone.lowerBound = LowerBound;
    118       clone.lowerBoundIncluded = LowerBoundIncluded;
    119       clone.lowerBoundEnabled = LowerBoundEnabled;
    120       return clone;
     138      return new IntBoundedConstraint(this, clonedObjects);
    121139    }
    122140
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/IsIntegerConstraint.cs

    r764 r885  
    2727
    2828namespace HeuristicLab.Constraints {
    29   public class IsIntegerConstraint : ConstraintBase{
     29  public class IsIntegerConstraint : ConstraintBase {
    3030    public override string Description {
    3131      get { return "Allows only integer values."; }
    3232    }
     33    /// <summary>
     34    /// Default constructor.
     35    /// </summary>
     36    public IsIntegerConstraint() { }
     37
     38    /// <summary>
     39    /// Copy constructor to create clones (deep).
     40    /// </summary>
     41    /// <param name="original">The original instance to be cloned.</param>
     42    public IsIntegerConstraint(IsIntegerConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     43    /// <summary>
     44    /// Copy constructor to create clones (deep) reusing already cloned object references.
     45    /// </summary>
     46    /// <param name="original">The instance to be cloned.</param>
     47    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     48    protected IsIntegerConstraint(IsIntegerConstraint original, IDictionary<Guid, object> clonedObjects)
     49      : base(original, clonedObjects) { }
    3350
    3451    public override bool Check(IItem item) {
    3552      // ConstrainedIntData is always integer => just return true
    36       if(item is ConstrainedIntData)
     53      if (item is ConstrainedIntData)
    3754        return true;
    3855
    3956      // if we have an item of ConstrainedDoubleData then we check if it is integer or not
    40       if(item is ConstrainedDoubleData) {
     57      if (item is ConstrainedDoubleData) {
    4158        ConstrainedDoubleData d = (ConstrainedDoubleData)item;
    42         if(d.Data == Math.Truncate(d.Data)) {
     59        if (d.Data == Math.Truncate(d.Data)) {
    4360          return true;
    4461        } else {
     
    5067      return false;
    5168    }
     69
     70    /// <summary>
     71    /// Clones an instance using the copy constructor
     72    /// reusing already cloned object references.
     73    /// </summary>
     74    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     75    /// <returns>A cloned (deep) instance</returns>
     76    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     77      return new IsIntegerConstraint(this, clonedObjects);
     78    }
    5279  }
    5380}
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/ItemTypeConstraint.cs

    r764 r885  
    5353    }
    5454
     55    /// <summary>
     56    /// Copy constructor to create clones (deep).
     57    /// </summary>
     58    /// <param name="original">The original instance to be cloned.</param>
     59    public ItemTypeConstraint(ItemTypeConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     60
     61    /// <summary>
     62    /// Copy constructor to create clones (deep) reusing already cloned object references.
     63    /// </summary>
     64    /// <param name="original">The instance to be cloned.</param>
     65    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     66    protected ItemTypeConstraint(ItemTypeConstraint original, IDictionary<Guid, object> clonedObjects)
     67      : base(original, clonedObjects) { }
     68
    5569    public override bool Check(IItem data) {
    5670      ConstrainedItemList list = (data as ConstrainedItemList);
     
    6882
    6983    #region clone & persistence
     84    /// <summary>
     85    /// Clones an instance using the copy constructor
     86    /// reusing already cloned object references.
     87    /// </summary>
     88    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     89    /// <returns>A cloned (deep) instance</returns>
    7090    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    71       ItemTypeConstraint clone = new ItemTypeConstraint(type);
    72       clonedObjects.Add(Guid, clone);
    73       return clone;
     91      return new ItemTypeConstraint(this, clonedObjects);
    7492    }
    7593
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/NotConstraint.cs

    r764 r885  
    4747    }
    4848
     49    /// <summary>
     50    /// Copy constructor to create clones (deep).
     51    /// </summary>
     52    /// <param name="original">The original instance to be cloned.</param>
     53    public NotConstraint(NotConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     54    /// <summary>
     55    /// Copy constructor to create clones (deep) reusing already cloned object references.
     56    /// </summary>
     57    /// <param name="original">The instance to be cloned.</param>
     58    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     59    protected NotConstraint(NotConstraint original, IDictionary<Guid, object> clonedObjects)
     60      : base(original, clonedObjects) {
     61      this.subConstraint = (ConstraintBase)Auxiliary.Clone(original.SubConstraint, clonedObjects);
     62    }
     63
    4964    public override bool Check(IItem data) {
    5065      return !subConstraint.Check(data);
     
    5570    }
    5671
     72    /// <summary>
     73    /// Clones an instance using the copy constructor
     74    /// reusing already cloned object references.
     75    /// </summary>
     76    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     77    /// <returns>A cloned (deep) instance</returns>
    5778    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    58       NotConstraint clone = new NotConstraint();
    59       clonedObjects.Add(Guid, clone);
    60       clone.SubConstraint = (ConstraintBase)SubConstraint.Clone();
    61       return clone;
     79      return new NotConstraint(this, clonedObjects);
    6280    }
    6381
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/NumberOfSubOperatorsConstraint.cs

    r764 r885  
    5454    }
    5555
     56    /// <summary>
     57    /// Copy constructor to create clones (deep).
     58    /// </summary>
     59    /// <param name="original">The original instance to be cloned.</param>
     60    public NumberOfSubOperatorsConstraint(NumberOfSubOperatorsConstraint original)
     61      : this(original, new Dictionary<Guid, object>()) { }
     62
     63    /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected NumberOfSubOperatorsConstraint(NumberOfSubOperatorsConstraint original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      this.maxOperators.Data = original.maxOperators.Data;
     71      this.minOperators.Data = original.minOperators.Data;
     72    }
     73
    5674    public override bool Check(IItem data) {
    5775      IOperator op = data as IOperator;
     
    6179    }
    6280
     81    /// <summary>
     82    /// Clones an instance using the copy constructor
     83    /// reusing already cloned object references.
     84    /// </summary>
     85    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     86    /// <returns>A cloned (deep) instance</returns>
    6387    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       NumberOfSubOperatorsConstraint clone = new NumberOfSubOperatorsConstraint();
    65       clonedObjects.Add(Guid, clone);
    66       clone.maxOperators.Data = maxOperators.Data;
    67       clone.minOperators.Data = minOperators.Data;
    68       return clone;
     88      return new NumberOfSubOperatorsConstraint(this, clonedObjects);
    6989    }
    7090
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/OrConstraint.cs

    r764 r885  
    4848    }
    4949
     50    /// <summary>
     51    /// Copy constructor to create clones (deep).
     52    /// </summary>
     53    /// <param name="original">The original instance to be cloned.</param>
     54    public OrConstraint(OrConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     55    /// <summary>
     56    /// Copy constructor to create clones (deep) reusing already cloned object references.
     57    /// </summary>
     58    /// <param name="original">The instance to be cloned.</param>
     59    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     60    protected OrConstraint(OrConstraint original, IDictionary<Guid, object> clonedObjects)
     61      : base(original, clonedObjects) {
     62      this.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(original.Clauses, clonedObjects);
     63    }
     64
    5065    public override bool Check(IItem data) {
    5166      bool result = false;
    52       for (int i = 0 ; i < clauses.Count ; i++) {
     67      for (int i = 0; i < clauses.Count; i++) {
    5368        result = clauses[i].Check(data);
    5469        if (result) return true;
     
    6176    }
    6277
     78    /// <summary>
     79    /// Clones an instance using the copy constructor
     80    /// reusing already cloned object references.
     81    /// </summary>
     82    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     83    /// <returns>A cloned (deep) instance</returns>
    6384    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       OrConstraint clone = new OrConstraint();
    65       clonedObjects.Add(Guid, clone);
    66       clone.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(Clauses, clonedObjects);
    67       return clone;
     85      return new OrConstraint(this, clonedObjects);
    6886    }
    6987
    7088    #region persistence
    71     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     89    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    7290      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    7391      XmlNode clausesNode = PersistenceManager.Persist("Clauses", Clauses, document, persistedObjects);
     
    7795    }
    7896
    79     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     97    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    8098      base.Populate(node, restoredObjects);
    8199      clauses = (ItemList<IConstraint>)PersistenceManager.Restore(node.SelectSingleNode("Clauses"), restoredObjects);
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/SubOperatorsTypeConstraint.cs

    r764 r885  
    5252    }
    5353
    54     public SubOperatorTypeConstraint(int index) : base() {
     54    public SubOperatorTypeConstraint(int index)
     55      : base() {
    5556      subOperatorIndex = new IntData(index);
    5657      subOperators = new List<IOperator>();
    5758    }
    5859
     60    /// Copy constructor to create clones (deep).
     61    /// </summary>
     62    /// <param name="original">The original instance to be cloned.</param>
     63    public SubOperatorTypeConstraint(SubOperatorTypeConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     64
     65    /// <summary>
     66    /// Copy constructor to create clones (deep) reusing already cloned object references.
     67    /// </summary>
     68    /// <param name="original">The instance to be cloned.</param>
     69    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     70    /// <summary>
     71    protected SubOperatorTypeConstraint(SubOperatorTypeConstraint original, IDictionary<Guid, object> clonedObjects)
     72      : base(original, clonedObjects) {
     73      this.subOperatorIndex.Data = original.subOperatorIndex.Data;
     74      foreach (IOperator op in original.subOperators) {
     75        this.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
     76      }
     77    }
     78
    5979    public void AddOperator(IOperator op) {
    60       if(!subOperators.Contains(op)) {
     80      if (!subOperators.Contains(op)) {
    6181        subOperators.Add(op);
    6282        FireChanged();
     
    6585
    6686    public void RemoveOperator(IOperator op) {
    67       if(subOperators.Contains(op)) {
     87      if (subOperators.Contains(op)) {
    6888        subOperators.Remove(op);
    6989        FireChanged();
     
    7797    public override bool Check(IItem data) {
    7898      IOperator op = data as IOperator;
    79       if(data == null) return false;
     99      if (data == null) return false;
    80100
    81       if(op.SubOperators.Count <= subOperatorIndex.Data) {
     101      if (op.SubOperators.Count <= subOperatorIndex.Data) {
    82102        return false;
    83103      }
     
    85105    }
    86106
     107    /// <summary>
     108    /// Clones an instance using the copy constructor
     109    /// reusing already cloned object references.
     110    /// </summary>
     111    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     112    /// <returns>A cloned (deep) instance</returns>
    87113    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    88       SubOperatorTypeConstraint clone = new SubOperatorTypeConstraint();
    89       clonedObjects.Add(Guid, clone);
    90       clone.subOperatorIndex.Data = subOperatorIndex.Data;
    91       foreach(IOperator op in subOperators) {
    92         clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
    93       }
    94       return clone;
     114      return new SubOperatorTypeConstraint(this, clonedObjects);
    95115    }
    96116
     
    105125      node.AppendChild(indexNode);
    106126      XmlNode listNode = document.CreateNode(XmlNodeType.Element, "AllowedSubOperators", document.NamespaceURI);
    107       foreach(IOperator op in subOperators) {
     127      foreach (IOperator op in subOperators) {
    108128        XmlNode opNode = PersistenceManager.Persist(op, document, persistedObjects);
    109129        listNode.AppendChild(opNode);
     
    117137      subOperatorIndex = (IntData)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorIndex"), restoredObjects);
    118138      subOperators = new List<IOperator>();
    119       foreach(XmlNode childNode in node.SelectSingleNode("AllowedSubOperators").ChildNodes) {
     139      foreach (XmlNode childNode in node.SelectSingleNode("AllowedSubOperators").ChildNodes) {
    120140        subOperators.Add((IOperator)PersistenceManager.Restore(childNode, restoredObjects));
    121141      }
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/TrueConstraint.cs

    r764 r885  
    3131      get { return "This constraint is always true."; }
    3232    }
     33    /// <summary>
     34    /// Default constructor.
     35    /// </summary>
     36    public TrueConstraint() { }
     37    /// <summary>
     38    /// Copy constructor to create clones (deep).
     39    /// </summary>
     40    /// <param name="original">The original instance to be cloned.</param>
     41    public TrueConstraint(TrueConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     42    /// <summary>
     43    /// Copy constructor to create clones (deep) reusing already cloned object references.
     44    /// </summary>
     45    /// <param name="original">The instance to be cloned.</param>
     46    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     47    protected TrueConstraint(TrueConstraint original, IDictionary<Guid, object> clonedObjects)
     48      : base(original, clonedObjects) { }
    3349
    3450    public override IView CreateView() {
     
    3652    }
    3753
     54    /// <summary>
     55    /// Clones an instance using the copy constructor
     56    /// reusing already cloned object references.
     57    /// </summary>
     58    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     59    /// <returns>A cloned (deep) instance</returns>
    3860    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    39       TrueConstraint clone = new TrueConstraint();
    40       clonedObjects.Add(Guid, clone);
    41       return clone;
     61      return new TrueConstraint();
    4262    }
    4363
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/VariableComparisonConstraint.cs

    r175 r885  
    5959    }
    6060
     61    /// <summary>
     62    /// Copy constructor to create clones (deep).
     63    /// </summary>
     64    /// <param name="original">The original instance to be cloned.</param>
     65    public VariableComparisonConstraint(VariableComparisonConstraint original)
     66      : this(original, new Dictionary<Guid, object>()) { }
     67
     68    /// <summary>
     69    /// Copy constructor to create clones (deep) reusing already cloned object references.
     70    /// </summary>
     71    /// <param name="original">The instance to be cloned.</param>
     72    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     73    protected VariableComparisonConstraint(VariableComparisonConstraint original, IDictionary<Guid, object> clonedObjects)
     74      : base(original, clonedObjects) {
     75      this.LeftVarName = (StringData)Auxiliary.Clone(original.LeftVarName, clonedObjects);
     76      this.RightVarName = (StringData)Auxiliary.Clone(original.RightVarName, clonedObjects);
     77      this.Comparer = (IntData)Auxiliary.Clone(original.Comparer, clonedObjects);
     78    }
     79
    6180    public override bool Check(IItem data) {
    6281      ConstrainedItemList list = (data as ConstrainedItemList);
     
    97116
    98117    #region clone & persistence
     118    /// <summary>
     119    /// Clones an instance using the copy constructor
     120    /// reusing already cloned object references.
     121    /// </summary>
     122    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     123    /// <returns>A cloned (deep) instance</returns>
    99124    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    100       VariableComparisonConstraint clone = new VariableComparisonConstraint();
    101       clonedObjects.Add(Guid, clone);
    102       clone.LeftVarName = (StringData)Auxiliary.Clone(LeftVarName, clonedObjects);
    103       clone.RightVarName = (StringData)Auxiliary.Clone(RightVarName, clonedObjects);
    104       clone.Comparer = (IntData)Auxiliary.Clone(Comparer, clonedObjects);
    105       return clone;
     125      return new VariableComparisonConstraint(this, clonedObjects);
    106126    }
    107127
  • branches/CloningRefactorBranch/HeuristicLab.Core/AtomicOperation.cs

    r836 r885  
    6262
    6363    /// <summary>
     64    /// Copy constructor to create a deep clone of an AtomicOperation instance.
     65    /// <remarks>Calls <see cref="AtomicOperation(AtomicOperation original,
     66    /// IDictionary<Guid, object> clonedObjects)"/></remarks> with an initially
     67    /// empty dictionary of cloned objects to create the clone.
     68    /// </summary>
     69    /// <param name="original">The original instance to be cloned.</param>
     70    public AtomicOperation(AtomicOperation original) : this(original, new Dictionary<Guid, object>()) { }
     71
     72    /// <summary>
     73    /// Copy constructor to create a deep clone of an AtomicOperation instance
     74    /// automatically reusing references of already cloned objects.
     75    /// </summary>
     76    /// <param name="original">The original instance to be cloned</param>
     77    /// <param name="clonedObjects">Already cloned object references</param>
     78    protected AtomicOperation(AtomicOperation original, IDictionary<Guid, object> clonedObjects)
     79      : base(original, clonedObjects) {
     80      this.myOperator = (IOperator)Auxiliary.Clone(original.Operator, clonedObjects);
     81      this.myScope = (IScope)Auxiliary.Clone(original.Scope, clonedObjects);
     82    }
     83
     84    /// <summary>
    6485    /// Clones the current instance.
    6586    /// </summary>
    66     /// <remarks>The operator and the scope objects are cloned with the
    67     /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the <see cref="Auxiliary"/> class.</remarks>
    68     /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param>
     87    /// <remarks>The operator and the scope objects are cloned with the copy constructor
     88    /// <see cref="HeuristicLab.Core.AtomicOperation(AtomicOperation original, IDictionary<Guid, object> clonedObjects"/>
     89    /// copy constructor.</remarks>
     90    /// <param name="clonedObjects">All already cloned objects. (Needed for referential integrity)</param>
    6991    /// <returns>The cloned object as <see cref="AtomicOperation"/>.</returns>
    7092    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    71       AtomicOperation clone = new AtomicOperation();
    72       clonedObjects.Add(Guid, clone);
    73       clone.myOperator = (IOperator)Auxiliary.Clone(Operator, clonedObjects);
    74       clone.myScope = (IScope)Auxiliary.Clone(Scope, clonedObjects);
    75       return clone;
     93      return new AtomicOperation(this, clonedObjects);
    7694    }
    7795
  • 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
  • branches/CloningRefactorBranch/HeuristicLab.Core/EngineBase.cs

    r836 r885  
    118118
    119119    /// <summary>
    120     /// Copy constructor.
    121     /// </summary>
    122     /// <param name="original"></param>
    123     /// <param name="clonedObjects"></param>
     120    /// Copy constructor to create a deep clone of an EngineBase instance.
     121    /// </summary>
     122    /// <remarks>Calls the copy constructor of the base class <see cref="ItemBase"/>
     123    /// and <see cref="Auxiliary.Clone"/> to clone contained objects</remarks>
     124    /// <param name="original">The instance to be cloned.</param>
     125    /// <param name="clonedObjects">Already cloned object references</param>
    124126    protected EngineBase(EngineBase original, IDictionary<Guid, object> clonedObjects)
    125127      : base(original, clonedObjects) {
     
    133135      this.myRunning = original.Running;
    134136      this.myCanceled = original.Canceled;
    135     }
    136 
    137     /// <summary>
    138     /// Clones the current instance (deep clone).
    139     /// </summary>
    140     /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
    141     /// <see cref="Auxiliary"/>.</remarks>
    142     /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
    143     /// <returns>The cloned object as <see cref="EngineBase"/>.</returns>
    144     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    145       return new EngineBase(this, clonedObjects);
    146137    }
    147138
  • branches/CloningRefactorBranch/HeuristicLab.Core/OperatorBase.cs

    r836 r885  
    105105
    106106    /// <summary>
    107     /// Copy constructor
    108     /// </summary>
    109     /// <param name="original"></param>
    110     /// <param name="clonedObjects"></param>
     107    /// Copy constructor.
     108    /// </summary>
     109    /// <param name="original">The original instance to be cloned</param>
     110    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
    111111    protected OperatorBase(OperatorBase original, IDictionary<Guid, object> clonedObjects)
    112112      : base(original, clonedObjects) {
  • branches/CloningRefactorBranch/HeuristicLab.Core/OperatorGraph.cs

    r776 r885  
    6060
    6161    /// <summary>
     62    /// Copy constructor to create a deep clone of an OperatorGraph instance.
     63    /// </summary>
     64    /// <param name="original">The original instance to be cloned.</param>
     65    public OperatorGraph(OperatorGraph original) : this(original, new Dictionary<Guid, object>()) { }
     66
     67    /// <summary>
     68    /// Copy constructor to create a deep clone of an OperatorGraph instance
     69    /// reusing already cloned objects.
     70    /// </summary>
     71    /// <param name="original">The original instance to be cloned</param>
     72    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     73    protected OperatorGraph(OperatorGraph original, IDictionary<Guid, object> clonedObjects)
     74      : base(original, clonedObjects) {
     75      foreach (IOperator op in original.Operators)
     76        this.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
     77      if (original.InitialOperator != null)
     78        this.myInitialOperator = (IOperator)Auxiliary.Clone(original.InitialOperator, clonedObjects);
     79    }
     80
     81    /// <summary>
    6282    /// Creates a new instance of <see cref="OperatorGraphView"/> to represent the current instance
    6383    /// visually.
     
    7191    /// Clones the current instance (deep clone).
    7292    /// </summary>
    73     /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
    74     /// <see cref="Auxiliary"/>.</remarks>
     93    /// <remarks>Deep clone using the copy constructor.</remarks>
    7594    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    7695    /// <returns>The cloned object as <see cref="OperatorGraph"/>.</returns>
    7796    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    78       OperatorGraph clone = new OperatorGraph();
    79       clonedObjects.Add(Guid, clone);
    80       foreach (IOperator op in Operators)
    81         clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
    82       if (InitialOperator != null)
    83         clone.myInitialOperator = (IOperator)Auxiliary.Clone(InitialOperator, clonedObjects);
    84       return clone;
     97      return new OperatorGraph(this, clonedObjects);
    8598    }
    8699
     
    179192    /// (Needed to avoid cycles.)</param>
    180193    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    181     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     194    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    182195      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    183196      XmlNode ops = document.CreateNode(XmlNodeType.Element, "Operators", null);
     
    197210    /// <param name="restoredObjects">The dictionary of all already restored objects.
    198211    /// (Needed to avoid cycles.)</param>
    199     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     212    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    200213      base.Populate(node, restoredObjects);
    201214
  • branches/CloningRefactorBranch/HeuristicLab.Core/OperatorGroup.cs

    r836 r885  
    7171
    7272    /// <summary>
    73     /// Copy constructor for deep cloning
    74     /// </summary>
    75     /// <param name="original"></param>
    76     /// <param name="clonedObjects"></param>
     73    /// Copy constructor to create a deep clone of an OperatorGroup instance.
     74    /// </summary>
     75    /// <param name="original">The instance to be cloned.</param>
     76    public OperatorGroup(OperatorGroup original) : this(original, new Dictionary<Guid, object>()) {}
     77
     78    /// <summary>
     79    /// Copy constructor to create a deep clone of an OperatorGroup instance reusing
     80    /// already cloned object references.
     81    /// </summary>
     82    /// <param name="original">The original instance to be cloned</param>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
    7784    protected OperatorGroup(OperatorGroup original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) {
    7885      this.myName = original.myName;
     
    8895    /// Clones the current instance (deep clone).
    8996    /// </summary>
    90     /// <remarks>Deep clone with <see cref="Auxiliary.Clone"/> method of helper class
    91     /// <see cref="Auxiliary"/>.</remarks>
    92     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     97    /// <remarks>Uses copy constructor to create the deep clone.</remarks>
     98    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed for referential integrity.)</param>
    9399    /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns>
    94100    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    95       OperatorGroup clone = new OperatorGroup(this, clonedObjects);
    96       return clone;
     101      return new OperatorGroup(this, clonedObjects);
    97102    }
    98103
  • branches/CloningRefactorBranch/HeuristicLab.Core/OperatorLibrary.cs

    r776 r885  
    4646
    4747    /// <summary>
     48    /// Copy constructor to create a deep clone of an OperatorLibrary instance.
     49    /// </summary>
     50    /// <param name="original">The instance to be cloned.</param>
     51    public OperatorLibrary(OperatorLibrary original) : this(original, new Dictionary<Guid, object>()) { }
     52
     53    /// <summary>
     54    /// Copy constructor to create a deep clone of an OperatorLibrary instance reusing
     55    /// already cloned object references.
     56    /// </summary>
     57    /// <param name="original">The original instance to be cloned</param>
     58    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     59    protected OperatorLibrary(OperatorLibrary original, IDictionary<Guid, object> clonedObjects)
     60      : base(original, clonedObjects) {
     61      this.myGroup = (IOperatorGroup)Auxiliary.Clone(original.Group, clonedObjects);
     62    }
     63
     64    /// <summary>
    4865    /// Creates a new instance of <see cref="OperatorLibraryEditor"/> to display the current instance.
    4966    /// </summary>
     
    6380    /// Clones the current instance (deep clone).
    6481    /// </summary>
    65     /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
    66     /// <see cref="Auxiliary"/>.</remarks>
    67     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     82    /// <remarks>Deep clone through the copy constructor.</remarks>
     83    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed for referential integrity.)</param>
    6884    /// <returns>The cloned object as <see cref="OperatorLibrary"/>.</returns>
    6985    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    70       OperatorLibrary clone = new OperatorLibrary();
    71       clonedObjects.Add(Guid, clone);
    72       clone.myGroup = (IOperatorGroup)Auxiliary.Clone(Group, clonedObjects);
    73       return clone;
     86      return new OperatorLibrary(this, clonedObjects);
    7487    }
    7588
  • branches/CloningRefactorBranch/HeuristicLab.Core/Scope.cs

    r836 r885  
    7878
    7979    /// <summary>
    80     /// Copy constructor to create deep clones.
     80    /// Copy constructor to clone (deep) a Scope instance.
    8181    /// </summary>
    8282    /// <param name="original"></param>
    83     /// <param name="clonedObjects"></param>
     83    public Scope(Scope original) : this(original, new Dictionary<Guid, object>()) { }
     84
     85    /// <summary>
     86    /// Copy constructor to clone (deep) a Scope instance reusing
     87    /// already cloned object references.
     88    /// </summary>
     89    /// <param name="original">The original instance to be cloned.</param>
     90    /// <param name="clonedObjects">Already cloned object references (for referential integrity).</param>
    8491    protected Scope(Scope original, IDictionary<Guid, object> clonedObjects)
    8592      : base(original, clonedObjects) {
  • branches/CloningRefactorBranch/HeuristicLab.Core/Variable.cs

    r801 r885  
    7979    }
    8080
     81    /// <summary>
     82    /// Copy constructor to deep clone Variable instances.
     83    /// </summary>
     84    /// <param name="original">The instance to be cloned.</param>
     85    public Variable(Variable original) : this(original, new Dictionary<Guid, object>()) { }
     86
     87    /// <summary>
     88    /// Copy constructor to deep clone Variable instances reusing
     89    /// already cloned object references.
     90    /// </summary>
     91    /// <param name="original">The instance to be cloned.</param>
     92    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     93    protected Variable(Variable original, IDictionary<Guid, object> clonedObjects)
     94      : base(original, clonedObjects) {
     95      this.myName = original.Name;
     96      if (original.Value != null)
     97        this.myValue = (IItem)Auxiliary.Clone(original.Value, clonedObjects);
     98    }
     99
    81100    /// <inheritdoc cref="IVariable.GetValue&lt;T&gt;"/>
    82101    public T GetValue<T>() where T : class, IItem {
     
    95114    /// Clones the current instance (deep clone).
    96115    /// </summary>
    97     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     116    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed for referential integrity.)</param>
    98117    /// <returns>The cloned object as <see cref="Variable"/>.</returns>
    99118    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    100       Variable clone = new Variable();
    101       clonedObjects.Add(Guid, clone);
    102       clone.myName = Name;
    103       if (Value != null)
    104         clone.myValue = (IItem)Auxiliary.Clone(Value, clonedObjects);
    105       return clone;
     119      return new Variable(this, clonedObjects);
    106120    }
    107121
  • branches/CloningRefactorBranch/HeuristicLab.Core/VariableInfo.cs

    r776 r885  
    119119
    120120    /// <summary>
     121    /// Copy constructor to deep clone VariableInfo instances.
     122    /// </summary>
     123    /// <param name="original">The instance to be cloned.</param>
     124    public VariableInfo(VariableInfo original) : this(original, new Dictionary<Guid, object>()) { }
     125
     126    /// <summary>
     127    /// Copy constructor to deep clone VariableInfo instances
     128    /// reusing already cloned object references.
     129    /// </summary>
     130    /// <param name="original">The instance to be cloned.</param>
     131    /// <param name="clonedObjects">Already cloned instances (for referential integrity).</param>
     132    protected VariableInfo(VariableInfo original, IDictionary<Guid, object> clonedObjects)
     133      : base(original, clonedObjects) {
     134      this.myActualName = original.ActualName;
     135      this.myFormalName = original.FormalName;
     136      this.myDescription = original.Description;
     137      this.myDataType = original.DataType;
     138      this.myKind = original.Kind;
     139      this.myLocal = original.Local;
     140    }
     141
     142    /// <summary>
    121143    /// Creates a new instance of <see cref="VariableInfoView"/> to represent the current instance
    122144    /// visually.
     
    130152    /// Clones the current instance (deep clone).
    131153    /// </summary>
    132     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     154    /// <remarks>Uses the copy constructor to create the deep clone.</remarks>
     155    /// <param name="clonedObjects">Dictionary of all already cloned objects (for referential integrity.)</param>
    133156    /// <returns>The cloned object as <see cref="VariableInfo"/>.</returns>
    134157    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    135       VariableInfo clone = new VariableInfo();
    136       clonedObjects.Add(Guid, clone);
    137       clone.myActualName = ActualName;
    138       clone.myFormalName = FormalName;
    139       clone.myDescription = Description;
    140       clone.myDataType = DataType;
    141       clone.myKind = Kind;
    142       clone.myLocal = Local;
    143       return clone;
     158      return new VariableInfo(this, clonedObjects);
    144159    }
    145160
  • branches/CloningRefactorBranch/HeuristicLab.Data/ArrayDataBase.cs

    r737 r885  
    4242
    4343    /// <summary>
     44    /// Default constructor.
     45    /// </summary>
     46    protected ArrayDataBase() { }
     47
     48    /// <summary>
     49    /// Copy constructor to create clones (deep) reusing already cloned object references.
     50    /// </summary>
     51    /// <param name="original">The instance to be cloned.</param>
     52    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     53    protected ArrayDataBase(ArrayDataBase original, IDictionary<Guid, object> clonedObjects)
     54      : base(original, clonedObjects) { }
     55
     56    /// <summary>
    4457    /// The string representation of the array.
    4558    /// </summary>
  • branches/CloningRefactorBranch/HeuristicLab.Data/BoolArrayData.cs

    r763 r885  
    5555      Data = data;
    5656    }
     57    /// <summary>
     58    /// Copy constructor to create clones (deep).
     59    /// </summary>
     60    /// <param name="original">The original instance to be cloned.</param>
     61    public BoolArrayData(BoolArrayData original) : this(original, new Dictionary<Guid, object>()) { }
     62    /// <summary>
     63    /// Copy constructor to create clones (deep) reusing already cloned object references.
     64    /// </summary>
     65    /// <param name="original">The instance to be cloned.</param>
     66    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     67    protected BoolArrayData(BoolArrayData original, IDictionary<Guid, object> clonedObjects)
     68      : base(original, clonedObjects) { }
    5769
    5870    /// <summary>
     
    6274    public override IView CreateView() {
    6375      return new BoolArrayDataView(this);
     76    }
     77
     78    /// <summary>
     79    /// Clones an instance using the copy constructor
     80    /// reusing already cloned object references.
     81    /// </summary>
     82    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     83    /// <returns>A cloned (deep) instance</returns>
     84    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     85      return new BoolArrayData(this, clonedObjects);
    6486    }
    6587
     
    7395    /// (Needed to avoid cycles.)</param>
    7496    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    75     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     97    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    7698      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    7799      node.InnerText = ToString();
     
    87109    /// <param name="restoredObjects">A Dictionary of all already restored objects.
    88110    /// (Needed to avoid cycles.)</param>
    89     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     111    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    90112      base.Populate(node, restoredObjects);
    91113      string[] tokens = node.InnerText.Split(';');
  • branches/CloningRefactorBranch/HeuristicLab.Data/BoolData.cs

    r776 r885  
    5454      Data = data;
    5555    }
     56
     57    /// <summary>
     58    /// Copy constructor to create deep clones.
     59    /// </summary>
     60    /// <param name="original">The instance to be cloned.</param>
     61    public BoolData(BoolData original) : this(original, new Dictionary<Guid, object>()) { }
     62
     63    /// <summary>
     64    /// Copy constructor to create deep clones reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected BoolData(BoolData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      this.Data = original.Data;
     71    }
    5672    /// <summary>
    5773    /// Creates a new instance of the <see cref="BoolDataView"/> class.
     
    6379
    6480    /// <summary>
    65     /// Clones the current instance.
     81    /// Clones the current instance using the copy constructor.
    6682    /// </summary>
    67     /// <remarks>The cloned instance is added to the <paramref name="dictionary"/>.</remarks>
    6883    /// <param name="clonedObjects">Dictionary of all already cloned objects.</param>
    6984    /// <returns>The cloned instance as <see cref="BoolData"/>.</returns>
    7085    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    71       BoolData clone = new BoolData();
    72       clonedObjects.Add(Guid, clone);
    73       clone.Data = Data;
    74       return clone;
     86      return new BoolData(this, clonedObjects);
    7587    }
    7688    /// <summary>
     
    8294    /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    8395    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    84     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     96    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    8597      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    8698      node.InnerText = ToString();
     
    95107    /// <param name="restoredObjects">The dictionary of all already restored objects.
    96108    /// (Needed to avoid cycles.)</param>
    97     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     109    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    98110      base.Populate(node, restoredObjects);
    99111      Data = bool.Parse(node.InnerText);
  • branches/CloningRefactorBranch/HeuristicLab.Data/BoolMatrixData.cs

    r763 r885  
    5858
    5959    /// <summary>
     60    /// Copy constructor to create clones (deep).
     61    /// </summary>
     62    /// <param name="original">The original instance to be cloned.</param>
     63    public BoolMatrixData(BoolMatrixData original) : this(original, new Dictionary<Guid, object>()) { }
     64    /// <summary>
     65    /// Copy constructor to create clones (deep) reusing already cloned object references.
     66    /// </summary>
     67    /// <param name="original">The instance to be cloned.</param>
     68    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     69    protected BoolMatrixData(BoolMatrixData original, IDictionary<Guid, object> clonedObjects)
     70      : base(original, clonedObjects) { }
     71
     72    /// <summary>
    6073    /// Creates a new instance of the <see cref="BoolMatrixDataView"/> class.
    6174    /// </summary>
     
    6376    public override IView CreateView() {
    6477      return new BoolMatrixDataView(this);
     78    }
     79
     80    /// <summary>
     81    /// Clones the instance using the copy constructor
     82    /// reusing already cloned object references.
     83    /// </summary>
     84    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     85    /// <returns>A cloned (deep) instance</returns>
     86    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     87      return new BoolMatrixData(this, clonedObjects);
    6588    }
    6689
     
    7598    /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    7699    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    77     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     100    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    78101      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    79102      XmlAttribute dim1 = document.CreateAttribute("Dimension1");
     
    94117    /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    95118    /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    96     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     119    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    97120      base.Populate(node, restoredObjects);
    98121      int dim1 = int.Parse(node.Attributes["Dimension1"].Value, CultureInfo.InvariantCulture.NumberFormat);
  • branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedDoubleData.cs

    r836 r885  
    5757
    5858    /// <summary>
     59    ///  Copy constructor to create deep clones.
     60    /// </summary>
     61    /// <param name="original"></param>
     62    public ConstrainedDoubleData(ConstrainedDoubleData original) : this(original, new Dictionary<Guid, object>()) { }
     63
     64    /// <summary>
    5965    /// Copy constructor for deep cloning of ConstrainedDoubleData items.
    6066    /// </summary>
    6167    /// <param name="original"></param>
    6268    /// <param name="clonedObjects"></param>
    63     protected ConstrainedDoubleData(ConstrainedDoubleData original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { }
     69    protected ConstrainedDoubleData(ConstrainedDoubleData original, IDictionary<Guid, object> clonedObjects)
     70      : base(original, clonedObjects) { }
    6471
    6572    /// <inheritdoc cref="ConstrainedObjectData.TrySetData(object)"/>
     
    8390    /// Clones the current instance.
    8491    /// </summary>
    85     /// <remarks>Uses the <see cref="ConstrainedObjectData.Clone"/> implementation of base class <see cref="ConstrainedObjectData"/>.</remarks>
     92    /// <remarks>Uses the copy constructor <see cref="ConstrainedDoubleData.ctor"/> to create a deep clone of the ConstrainedDoubleData instance.</remarks>
    8693    /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
    8794    /// <returns>The cloned instance as <see cref="ConstrainedDoubleData"/>.</returns>
  • branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedIntData.cs

    r836 r885  
    5757
    5858    /// <summary>
    59     /// Copy constructor for deep cloning of ConstrainedDoubleData items.
     59    /// Copy constructor to create clones (deep).
    6060    /// </summary>
    61     /// <param name="original"></param>
    62     /// <param name="clonedObjects"></param>
    63     protected ConstrainedIntData(ConstrainedIntData original, IDictionary<Guid, object> clonedObjects) : base(original, clonedObjects) { }
     61    /// <param name="original">The original instance to be cloned.</param>
     62    public ConstrainedIntData(ConstrainedIntData original) : this(original, new Dictionary<Guid, object>()) { }
     63
     64    /// <summary>
     65    /// Copy constructor to create clones (deep) reusing already cloned object references.
     66    /// </summary>
     67    /// <param name="original">The instance to be cloned.</param>
     68    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     69    protected ConstrainedIntData(ConstrainedIntData original, IDictionary<Guid, object> clonedObjects)
     70      : base(original, clonedObjects) { }
    6471
    6572    /// <inheritdoc cref="ConstrainedObjectData.TrySetData(object)"/>
     
    8390    /// Clones the current instance.
    8491    /// </summary>
    85     /// <remarks>Uses the <see cref="ConstrainedObjectData.Clone"/> implementation of base class <see cref="ConstrainedObjectData"/>.</remarks>
     92    /// <remarks>Uses the copy constructor <see cref="ConstrainedIntData.ctor"/> to create a deep clone of the ConstrainedIntData instance.</remarks>
    8693    /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
    8794    /// <returns>The clone instance as <see cref="ConstrainedIntData"/>.</returns>
  • branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedItemList.cs

    r737 r885  
    5353
    5454    /// <summary>
     55    /// Copy constructor to create clones (deep).
     56    /// </summary>
     57    /// <param name="original">The original instance to be cloned.</param>
     58    public ConstrainedItemList(ConstrainedItemList original) : this(original, new Dictionary<Guid, object>()) { }
     59
     60    /// <summary>
     61    /// Copy constructor to create clones (deep) reusing already cloned object references.
     62    /// </summary>
     63    /// <param name="original">The instance to be cloned.</param>
     64    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     65    protected ConstrainedItemList(ConstrainedItemList original, IDictionary<Guid, object> clonedObjects)
     66      : base(original, clonedObjects) {
     67      foreach (IConstraint constraint in original.Constraints)
     68        this.AddConstraint((IConstraint)Auxiliary.Clone(constraint, clonedObjects));
     69      this.suspendConstraintCheck = original.suspendConstraintCheck;
     70      foreach (IItem item in original.list) {
     71        this.list.Add((IItem)Auxiliary.Clone(item, clonedObjects));
     72      }
     73    }
     74
     75    /// <summary>
    5576    /// Creates a new instance of <see cref="ConstrainedItemListView"/>.
    5677    /// </summary>
     
    6485    /// Clones the current instance.
    6586    /// </summary>
    66     /// <remarks>The elements of the current instance are cloned with the
    67     /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>
     87    /// <remarks>The elements of the current instance are cloned with the copy constructor.</remarks>
    6888    /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
    6989    /// <returns>The cloned instance as <see cref="ConstrainedItemList"/>.</returns>
    7090    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    71       ConstrainedItemList clone = new ConstrainedItemList();
    72       clonedObjects.Add(Guid, clone);
    73       foreach (IConstraint constraint in Constraints)
    74         clone.AddConstraint((IConstraint)Auxiliary.Clone(constraint, clonedObjects));
    75       clone.suspendConstraintCheck = suspendConstraintCheck;
    76       foreach (IItem item in list) {
    77         clone.list.Add((IItem)Auxiliary.Clone(item, clonedObjects));
    78       }
    79       return clone;
     91      return new ConstrainedItemList(this, clonedObjects);
    8092    }
    8193
     
    94106    /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    95107    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    96     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     108    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    97109      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    98110      XmlNode listNode = document.CreateNode(XmlNodeType.Element, "ListItems", null);
     
    115127    /// <param name="node">The <see cref="XmlNode"/> where the int is saved.</param>
    116128    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    117     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     129    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    118130      base.Populate(node, restoredObjects);
    119131      XmlNode listNode = node.SelectSingleNode("ListItems");
  • branches/CloningRefactorBranch/HeuristicLab.Data/ConstrainedObjectData.cs

    r763 r885  
    4848
    4949    /// <summary>
     50    /// Default constructor
     51    /// </summary>
     52    public ConstrainedObjectData() { }
     53
     54    /// <summary>
     55    /// Copy constructor to create clones (deep) .
     56    /// </summary>
     57    /// <param name="original">The instance to be cloned.</param>
     58    public ConstrainedObjectData(ConstrainedObjectData original) : this(original, new Dictionary<Guid, object>()) { }
     59
     60    /// <summary>
     61    /// Copy constructor to create a cloned instance.
     62    /// </summary>
     63    /// <remarks>HeuristicLab data items are cloned with the <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of
     64    /// class <see cref="Auxiliary"/> (deep copy), all other items (like basic data types)
     65    /// are cloned with their own <c>Clone</c> methods (shadow copy).</remarks>
     66    /// <param name="clonedObjects">All already cloned objects.</param>
     67    /// <returns>The cloned object as <see cref="ConstrainedObjectData"/>.</returns>
     68    protected ConstrainedObjectData(ConstrainedObjectData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      if (original.Data is IStorable)
     71        this.myData = Auxiliary.Clone((IStorable)original.Data, clonedObjects);
     72      else if (original.Data is ICloneable)
     73        this.myData = ((ICloneable)original.Data).Clone();
     74      else
     75        throw new InvalidOperationException("contained object is not cloneable");
     76    }
     77
     78    /// <summary>
    5079    /// Assigns the new <paramref name="data"/> if it is valid according to the constraints.
    5180    /// </summary>
     
    89118
    90119    /// <summary>
    91     /// Clones the current object.
    92     /// </summary>
    93     /// <remarks>HeuristicLab data items are cloned with the <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of
    94     /// class <see cref="Auxiliary"/> (deep copy), all other items (like basic data types)
    95     /// are cloned with their own <c>Clone</c> methods (shadow copy).</remarks>
    96     /// <param name="clonedObjects">All already cloned objects.</param>
    97     /// <returns>The cloned object as <see cref="ConstrainedObjectData"/>.</returns>
    98     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    99       ConstrainedObjectData clone = (ConstrainedObjectData)base.Clone(clonedObjects);
    100       if (Data is IStorable)
    101         clone.myData = Auxiliary.Clone((IStorable)Data, clonedObjects);
    102       else if (Data is ICloneable)
    103         clone.myData = ((ICloneable)Data).Clone();
    104       else
    105         throw new InvalidOperationException("contained object is not cloneable");
    106       return clone;
    107     }
    108 
    109     /// <summary>
    110120    /// Compares the current instance to the given <paramref name="obj"/>.
    111121    /// </summary>
     
    131141
    132142    /// <summary>
     143    /// Clones an instance using the copy constructor
     144    /// reusing already cloned object references.
     145    /// </summary>
     146    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     147    /// <returns>A cloned (deep) instance</returns>
     148    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     149      return new ConstrainedObjectData(this, clonedObjects);
     150    }
     151
     152    /// <summary>
    133153    /// The string representation of the current instance.
    134154    /// </summary>
  • branches/CloningRefactorBranch/HeuristicLab.Data/DoubleArrayData.cs

    r763 r885  
    5656      Data = data;
    5757    }
     58    /// <summary>
     59    /// Copy constructor to create clones (deep).
     60    /// </summary>
     61    /// <param name="original">The original instance to be cloned.</param>
     62    public DoubleArrayData(DoubleArrayData original) : this(original, new Dictionary<Guid, object>()) { }
     63    /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected DoubleArrayData(DoubleArrayData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) { }
    5870
    5971    /// <summary>
     
    6375    public override IView CreateView() {
    6476      return new DoubleArrayDataView(this);
     77    }
     78
     79    /// <summary>
     80    /// Clones an instance using the copy constructor
     81    /// reusing already cloned object references.
     82    /// </summary>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     84    /// <returns>A cloned (deep) instance</returns>
     85    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     86      return new DoubleArrayData(this, clonedObjects);
    6587    }
    6688
     
    7496    /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    7597    /// <returns>The saved <see cref="XmlNode"></see>.</returns>
    76     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     98    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    7799      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    78100      node.InnerText = ToString(CultureInfo.InvariantCulture.NumberFormat);
    79101      return node;
    80102    }
    81    
     103
    82104    /// <summary>
    83105    /// Loads the persisted double array from the specified <paramref name="node"/>.
     
    89111    /// <param name="node">The <see cref="XmlNode"></see> where the instance is saved.</param>
    90112    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    91     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     113    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    92114      base.Populate(node, restoredObjects);
    93115      string[] tokens = node.InnerText.Split(';');
    94116      double[] data = new double[tokens.Length];
    95       for(int i = 0; i < data.Length; i++)
    96         if(double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == false) {
     117      for (int i = 0; i < data.Length; i++)
     118        if (double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == false) {
    97119          throw new FormatException("Can't parse " + tokens[i] + " as double value.");
    98120        }
     
    109131    private string ToString(NumberFormatInfo format) {
    110132      StringBuilder builder = new StringBuilder();
    111       for(int i = 0; i < Data.Length; i++) {
     133      for (int i = 0; i < Data.Length; i++) {
    112134        builder.Append(";");
    113135        builder.Append(Data[i].ToString("r", format));
    114136      }
    115       if(builder.Length > 0)
     137      if (builder.Length > 0)
    116138        builder.Remove(0, 1);
    117139      return builder.ToString();
  • branches/CloningRefactorBranch/HeuristicLab.Data/DoubleData.cs

    r763 r885  
    5858
    5959    /// <summary>
     60    /// Copy constructor to create clones (deep).
     61    /// </summary>
     62    /// <param name="original">The original instance to be cloned.</param>
     63    public DoubleData(DoubleData original) : this(original, new Dictionary<Guid, object>()) { }
     64
     65    /// <summary>
     66    /// Copy constructor to create clones (deep) reusing already cloned object references.
     67    /// </summary>
     68    /// <param name="original">The instance to be cloned.</param>
     69    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     70    protected DoubleData(DoubleData original, IDictionary<Guid, object> clonedObjects)
     71      : base(original, clonedObjects) {
     72      this.Data = original.Data;
     73    }
     74
     75    /// <summary>
    6076    /// Creates a new instance of the <see cref="DoubleDataView"/> class.
    6177    /// </summary>
     
    6682
    6783    /// <summary>
    68     /// Clones the current instance and adds it to the dictionary <paramref name="clonedObjects"/>.
     84    /// Clones the current instance using the copy constructor.
    6985    /// </summary>
    7086    /// <param name="clonedObjects">Dictionary of all already cloned objects.</param>
    7187    /// <returns>The cloned instance as <see cref="DoubleData"/>.</returns>
    7288    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    73       DoubleData clone = new DoubleData();
    74       clonedObjects.Add(Guid, clone);
    75       clone.Data = Data;
    76       return clone;
     89      return new DoubleData(this, clonedObjects);
    7790    }
    7891
     
    8699    /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    87100    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    88     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     101    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    89102      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    90103      node.InnerText = Data.ToString("r", CultureInfo.InvariantCulture.NumberFormat);
     
    100113    /// <param name="node">The <see cref="XmlNode"/> where the double is saved.</param>
    101114    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    102     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     115    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    103116      base.Populate(node, restoredObjects);
    104117      double data;
    105       if(double.TryParse(node.InnerText, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data) == true) {
     118      if (double.TryParse(node.InnerText, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data) == true) {
    106119        Data = data;
    107120      } else {
    108         throw new FormatException("Can't parse " + node.InnerText + " as double value.");       
     121        throw new FormatException("Can't parse " + node.InnerText + " as double value.");
    109122      }
    110123    }
  • branches/CloningRefactorBranch/HeuristicLab.Data/DoubleMatrixData.cs

    r737 r885  
    5858
    5959    /// <summary>
     60    /// Copy constructor to create clones (deep).
     61    /// </summary>
     62    /// <param name="original">The original instance to be cloned.</param>
     63    public DoubleMatrixData(DoubleMatrixData original) : this(original, new Dictionary<Guid, object>()) { }
     64
     65    /// <summary>
     66    /// Copy constructor to create clones (deep) reusing already cloned object references.
     67    /// </summary>
     68    /// <param name="original">The instance to be cloned.</param>
     69    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     70    protected DoubleMatrixData(DoubleMatrixData original, IDictionary<Guid, object> clonedObjects)
     71      : base(original, clonedObjects) { }
     72
     73    /// <summary>
    6074    /// Creates a new instance of the <see cref="DoubleMatrixDataView"/> class.
    6175    /// </summary>
     
    6377    public override IView CreateView() {
    6478      return new DoubleMatrixDataView(this);
     79    }
     80
     81    /// <summary>
     82    /// Clones an instance using the copy constructor
     83    /// reusing already cloned object references.
     84    /// </summary>
     85    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     86    /// <returns>A cloned (deep) instance</returns>
     87    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     88      return new DoubleMatrixData(this, clonedObjects);
    6589    }
    6690
     
    77101    /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    78102    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    79     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     103    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    80104      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    81105      XmlAttribute dim1 = document.CreateAttribute("Dimension1");
     
    99123    /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    100124    /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    101     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     125    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    102126      base.Populate(node, restoredObjects);
    103127      int dim1 = int.Parse(node.Attributes["Dimension1"].Value, CultureInfo.InvariantCulture.NumberFormat);
     
    107131      for (int i = 0; i < dim1; i++) {
    108132        for (int j = 0; j < dim2; j++) {
    109           if(double.TryParse(tokens[i * dim2 + j], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i, j])==false) {
     133          if (double.TryParse(tokens[i * dim2 + j], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i, j]) == false) {
    110134            throw new FormatException("Can't parse " + tokens[i * dim2 + j] + " as double value.");
    111135          }
     
    123147      return ToString(CultureInfo.CurrentCulture.NumberFormat);
    124148    }
    125    
     149
    126150    /// <summary>
    127151    /// The string representation of the matrix, considering a specified <paramref name="format"/>.
  • branches/CloningRefactorBranch/HeuristicLab.Data/IntArrayData.cs

    r737 r885  
    5656      Data = data;
    5757    }
     58        /// <summary>
     59    /// Copy constructor to create clones (deep).
     60    /// </summary>
     61    /// <param name="original">The original instance to be cloned.</param>
     62    public IntArrayData(IntArrayData original) : this(original, new Dictionary<Guid, object>()) { }
     63    /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected IntArrayData(IntArrayData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) { }
    5870
    5971    /// <summary>
     
    6375    public override IView CreateView() {
    6476      return new IntArrayDataView(this);
     77    }
     78
     79    /// <summary>
     80    /// Clones an instance using the copy constructor
     81    /// reusing already cloned object references.
     82    /// </summary>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     84    /// <returns>A cloned (deep) instance</returns>
     85    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     86      return new IntArrayData(this, clonedObjects);
    6587    }
    6688
  • branches/CloningRefactorBranch/HeuristicLab.Data/IntData.cs

    r763 r885  
    5555      Data = data;
    5656    }
     57    /// <summary>
     58    /// Copy constructor to create clones (deep).
     59    /// </summary>
     60    /// <param name="original">The original instance to be cloned.</param>
     61    public IntData(IntData original) : this(original, new Dictionary<Guid, object>()) { }
     62
     63    /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected IntData(IntData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      this.Data = original.Data;
     71    }
    5772
    5873    /// <summary>
     
    6580
    6681    /// <summary>
    67     /// Clones the current instance.
     82    /// Clones the current instance using the copy constructor.
    6883    /// </summary>
    6984    /// <remarks>Adds the cloned instance to the dictionary <paramref name="clonedObjects"/>.</remarks>
     
    7186    /// <returns>The cloned instance as <see cref="IntData"/>.</returns>
    7287    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    73       IntData clone = new IntData();
    74       clonedObjects.Add(Guid, clone);
    75       clone.Data = Data;
    76       return clone;
     88      return new IntData(this, clonedObjects);
    7789    }
    7890
     
    8698    /// <param name="persistedObjects">A dictionary of all already persisted objects.(Needed to avoid cycles.)</param>
    8799    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    88     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     100    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    89101      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    90102      node.InnerText = Data.ToString(CultureInfo.InvariantCulture.NumberFormat);
     
    99111    /// <param name="node">The <see cref="XmlNode"/> where the int is saved.</param>
    100112    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    101     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     113    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    102114      base.Populate(node, restoredObjects);
    103115      Data = int.Parse(node.InnerText, CultureInfo.InvariantCulture.NumberFormat);
  • branches/CloningRefactorBranch/HeuristicLab.Data/IntMatrixData.cs

    r763 r885  
    5858
    5959    /// <summary>
     60    /// Copy constructor to create clones (deep).
     61    /// </summary>
     62    /// <param name="original">The original instance to be cloned.</param>
     63    public IntMatrixData(IntMatrixData original) : this(original, new Dictionary<Guid, object>()) { }
     64
     65    /// <summary>
     66    /// Copy constructor to create clones (deep) reusing already cloned object references.
     67    /// </summary>
     68    /// <param name="original">The instance to be cloned.</param>
     69    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     70    protected IntMatrixData(IntMatrixData original, IDictionary<Guid, object> clonedObjects)
     71      : base(original, clonedObjects) { }
     72
     73    /// <summary>
    6074    /// Creates a new instance of <see cref="IntMatrixDataView"/>.
    6175    /// </summary>
     
    6579    }
    6680
     81    /// <summary>
     82    /// Clones an instance using the copy constructor
     83    /// reusing already cloned object references.
     84    /// </summary>
     85    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     86    /// <returns>A cloned (deep) instance</returns>
     87    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     88      return new IntMatrixData(this, clonedObjects);
     89    }
    6790    /// <summary>
    6891    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
     
    78101    /// (Needed to avoid cycles.)</param>
    79102    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    80     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     103    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    81104      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    82105      XmlAttribute dim1 = document.CreateAttribute("Dimension1");
     
    99122    /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    100123    /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    101     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     124    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    102125      base.Populate(node, restoredObjects);
    103126      int dim1 = int.Parse(node.Attributes["Dimension1"].Value, CultureInfo.InvariantCulture.NumberFormat);
  • branches/CloningRefactorBranch/HeuristicLab.Data/ItemDictionary_T.cs

    r737 r885  
    11using System;
    2 using System.Collections; 
     2using System.Collections;
    33using System.Collections.Generic;
    44using System.Text;
     
    1212  /// <typeparam name="K">The type of the keys, which must implement the interface <see cref="IItem"/>.</typeparam>
    1313  /// <typeparam name="V">The type of the values, which must imlement the interface <see cref="IItem"/>.</typeparam>
    14   public class ItemDictionary<K,V> : ItemBase, IDictionary<K,V>
     14  public class ItemDictionary<K, V> : ItemBase, IDictionary<K, V>
    1515    where K : IItem
    16     where V : IItem{
     16    where V : IItem {
    1717    private Dictionary<K, V> dict;
    1818
     
    3434    }
    3535
     36    /// <summary>
     37    /// Copy constructor to create clones (deep).
     38    /// </summary>
     39    /// <param name="original">The original instance to be cloned.</param>
     40    public ItemDictionary(ItemDictionary<K, V> original) : this(original, new Dictionary<Guid, object>()) { }
     41
     42    /// <summary>
     43    /// Copy constructor to create clones (deep) reusing already cloned object references.
     44    /// </summary>
     45    /// <param name="original">The instance to be cloned.</param>
     46    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     47    protected ItemDictionary(ItemDictionary<K, V> original, IDictionary<Guid, object> clonedObjects)
     48      : base(original, clonedObjects) {
     49      foreach (KeyValuePair<K, V> item in original.dict) {
     50        this.dict.Add((K)Auxiliary.Clone(item.Key, clonedObjects), (V)Auxiliary.Clone(item.Value, clonedObjects));
     51      }
     52    }
     53
    3654    #region ItemBase Members
    3755    /// <summary>
     
    4058    /// <returns>The created instance as <see cref="ItemDictionaryView&lt;K,V&gt;"/>.</returns>
    4159    public override IView CreateView() {
    42       return new ItemDictionaryView<K,V>(this);
    43     }
    44 
    45     /// <summary>
    46     /// Clones the current instance and adds it to the dictionary <paramref name="clonedObjects"/>.
     60      return new ItemDictionaryView<K, V>(this);
     61    }
     62
     63    /// <summary>
     64    /// Clones the current instance using the copy constructor.
    4765    /// </summary>
    4866    /// <remarks>Also the keys and values in the dictionary are cloned and saved to the dictionary <paramref name="clonedObjects"/>,
     
    5169    /// <returns>The cloned instance as <see cref="ItemDictionary&lt;K,V&gt;"/>.</returns>
    5270    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    53       ItemDictionary<K,V> clone = new ItemDictionary<K,V>();
    54       clonedObjects.Add(Guid, clone);
    55       foreach (KeyValuePair<K, V> item in dict) {
    56         clone.dict.Add((K) Auxiliary.Clone(item.Key, clonedObjects), (V) Auxiliary.Clone(item.Value, clonedObjects));
    57       }
    58       return clone;
     71      return new ItemDictionary<K, V>(this, clonedObjects);
    5972    }
    6073
     
    7487      foreach (KeyValuePair<K, V> item in dict) {
    7588        XmlNode keyNode = PersistenceManager.Persist("Key", item.Key, document, persistedObjects);
    76         XmlNode valueNode = PersistenceManager.Persist("Val", item.Value, document, persistedObjects); 
    77         XmlNode pairNode = document.CreateNode(XmlNodeType.Element, "KeyValuePair", null); 
    78         pairNode.AppendChild(keyNode); 
    79         pairNode.AppendChild(valueNode); 
    80         node.AppendChild(pairNode); 
    81       }
    82       return node; 
     89        XmlNode valueNode = PersistenceManager.Persist("Val", item.Value, document, persistedObjects);
     90        XmlNode pairNode = document.CreateNode(XmlNodeType.Element, "KeyValuePair", null);
     91        pairNode.AppendChild(keyNode);
     92        pairNode.AppendChild(valueNode);
     93        node.AppendChild(pairNode);
     94      }
     95      return node;
    8396    }
    8497
     
    94107      base.Populate(node, restoredObjects);
    95108      for (int i = 0; i < node.ChildNodes.Count; i++) {
    96         K key = (K) PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Key"), restoredObjects);
    97         V val = (V) PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Val"), restoredObjects);
    98         dict[key] = val; 
     109        K key = (K)PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Key"), restoredObjects);
     110        V val = (V)PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Val"), restoredObjects);
     111        dict[key] = val;
    99112      }
    100113    }
     
    154167    /// <c>false</c> if the key was not found.</returns>
    155168    public bool Remove(K key) {
    156       V value = dict[key]; 
     169      V value = dict[key];
    157170      bool removed = dict.Remove(key);
    158       OnItemRemoved(key, value); 
    159       return removed; 
     171      OnItemRemoved(key, value);
     172      return removed;
    160173    }
    161174
     
    191204    public void Add(KeyValuePair<K, V> item) {
    192205      dict.Add(item.Key, item.Value);
    193       OnItemAdded(item.Key, item.Value); 
     206      OnItemAdded(item.Key, item.Value);
    194207    }
    195208
     
    201214    public void Clear() {
    202215      dict.Clear();
    203       OnCleared(); 
     216      OnCleared();
    204217    }
    205218
     
    220233    /// <param name="arrayIndex"></param>
    221234    public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) {
    222       throw new NotImplementedException(); 
     235      throw new NotImplementedException();
    223236    }
    224237
     
    246259      if (removed) {
    247260        OnItemRemoved(item.Key, item.Value);
    248       } 
    249       return removed; 
     261      }
     262      return removed;
    250263    }
    251264    #endregion
     
    328341      public bool Equals(T x, T y) {
    329342        if (x is IComparable) {
    330           return (((IComparable) x).CompareTo(y) == 0);
     343          return (((IComparable)x).CompareTo(y) == 0);
    331344        }
    332345        if (y is IComparable) {
    333           return (((IComparable) y).CompareTo(x) == 0);
     346          return (((IComparable)y).CompareTo(x) == 0);
    334347        }
    335         return x.Equals(y); 
     348        return x.Equals(y);
    336349      }
    337350
     
    343356      public int GetHashCode(T obj) {
    344357        if (obj is IObjectData) {
    345           return ((IObjectData) obj).Data.GetHashCode();
     358          return ((IObjectData)obj).Data.GetHashCode();
    346359        }
    347         return obj.Guid.GetHashCode(); 
     360        return obj.Guid.GetHashCode();
    348361      }
    349362    }
  • branches/CloningRefactorBranch/HeuristicLab.Data/ItemList.cs

    r737 r885  
    3333  public class ItemList : ItemList<IItem> {
    3434    /// <summary>
     35    /// Default constructor for an empty ItemList.
     36    /// </summary>
     37    public ItemList() { }
     38
     39    /// <summary>
     40    /// Copy constructor to create clones (deep).
     41    /// </summary>
     42    /// <param name="original">The original instance to be cloned.</param>
     43    public ItemList(ItemList original) : this(original, new Dictionary<Guid, object>()) { }
     44    /// <summary>
     45    /// Copy constructor to create clones (deep) reusing already cloned object references.
     46    /// </summary>
     47    /// <param name="original">The instance to be cloned.</param>
     48    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     49    protected ItemList(ItemList original, IDictionary<Guid, object> clonedObjects)
     50      : base(original, clonedObjects) {
     51    }
     52
     53    /// <summary>
    3554    /// Clones the current list and all its elements.
    3655    /// </summary>
     
    3857    /// <returns>The cloned instance as <see cref="ItemList"/>.</returns>
    3958    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    40       ItemList clone = new ItemList();
    41       clonedObjects.Add(Guid, clone);
    42       base.CloneElements(clone, clonedObjects);
    43       return clone;
     59      return new ItemList(this, clonedObjects);
    4460    }
    4561  }
  • branches/CloningRefactorBranch/HeuristicLab.Data/ItemList_T.cs

    r737 r885  
    4141      list = new List<T>();
    4242    }
     43    /// <summary>
     44    /// Copy constructor to create clones (deep).
     45    /// </summary>
     46    /// <param name="original">The original instance to be cloned.</param>
     47    public ItemList(ItemList<T> original) : this(original, new Dictionary<Guid, object>()) { }
     48    /// <summary>
     49    /// Copy constructor to create clones (deep) reusing already cloned object references.
     50    /// </summary>
     51    /// <param name="original">The instance to be cloned.</param>
     52    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     53    protected ItemList(ItemList<T> original, IDictionary<Guid, object> clonedObjects)
     54      : base(original, clonedObjects) {
     55      CloneElements(original, clonedObjects);
     56    }
    4357
    4458    /// <summary>
     
    5165
    5266    /// <summary>
    53     /// Clones the current instance.
     67    /// Clones the current instance using the copy constructor.
    5468    /// </summary>
    5569    /// <remarks>Saves the cloned instance in the dictionary <paramref name="clonedObjects"/>.</remarks>
     
    5771    /// <returns>The cloned instance as <see cref="ItemList&lt;T&gt;"/>.</returns>
    5872    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    59       ItemList<T> clone = new ItemList<T>();
    60       clonedObjects.Add(Guid, clone);
    61       CloneElements(clone, clonedObjects);
    62       return clone;
    63     }
    64 
    65     /// <summary>
    66     /// Clones all elements in the current list.
     73      return new ItemList<T>(this, clonedObjects);
     74    }
     75
     76    /// <summary>
     77    /// Clones all elements from the supplied ItemList"/>.
    6778    /// </summary>
    6879    /// <remarks>Clones only elements that have not already been cloned
    6980    /// (and therefore exist in the dictionary <paramref name="clonedObjects"/>).</remarks>
    70     /// <param name="destination">The <see cref="ItemList&lt;T&gt;"/> where to save the cloned objects.</param>
     81    /// <param name="destination">The <see cref="ItemList&lt;T&gt;"/> from which to cloned objects.</param>
    7182    /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
    72     protected void CloneElements(ItemList<T> destination, IDictionary<Guid, object> clonedObjects) {
    73       for (int i = 0; i < list.Count; i++)
    74         destination.list.Add((T) Auxiliary.Clone(list[i], clonedObjects));
     83    protected void CloneElements(ItemList<T> original, IDictionary<Guid, object> clonedObjects) {
     84      for (int i = 0; i < original.list.Count; i++)
     85        this.list.Add((T)Auxiliary.Clone(original.list[i], clonedObjects));
    7586    }
    7687
     
    99110      base.Populate(node, restoredObjects);
    100111      for (int i = 0; i < node.ChildNodes.Count; i++)
    101         list.Add((T) PersistenceManager.Restore(node.ChildNodes[i], restoredObjects));
     112        list.Add((T)PersistenceManager.Restore(node.ChildNodes[i], restoredObjects));
    102113    }
    103114
  • branches/CloningRefactorBranch/HeuristicLab.Data/NullData.cs

    r763 r885  
    4848
    4949    /// <summary>
    50     /// Clones the current instance.
     50    /// Copy constructor to create clones (deep).
     51    /// </summary>
     52    /// <param name="original">The original instance to be cloned.</param>
     53    public NullData(NullData original) : this(original, new Dictionary<Guid, object>()) { }
     54    /// <summary>
     55    /// Copy constructor to create clones (deep) reusing already cloned object references.
     56    /// </summary>
     57    /// <param name="original">The instance to be cloned.</param>
     58    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     59    protected NullData(NullData original, IDictionary<Guid, object> clonedObjects)
     60      : base(original, clonedObjects) { }
     61
     62    /// <summary>
     63    /// Clones the current instance using the copy constructor
    5164    /// </summary>
    5265    /// <remarks>Adds the cloned instance to the dictionary <paramref name="clonedObjects"/>.</remarks>
     
    5467    /// <returns>The cloned instance as <see cref="NullData"/>.</returns>
    5568    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    56       NullData clone = new NullData();
    57       clonedObjects.Add(Guid, clone);
    58       return clone;
     69      return new NullData(this);
    5970    }
    6071  }
  • branches/CloningRefactorBranch/HeuristicLab.Data/ObjectData.cs

    r763 r885  
    4747
    4848    /// <summary>
    49     /// Clones the current instance.
     49    /// Default constructor to create ObjectData instances
     50    /// </summary>
     51    public ObjectData() { }
     52
     53    /// <summary>
     54    /// Copy constructor to create clones (deep).
     55    /// </summary>
     56    /// <param name="original">The original instance to be cloned.</param>
     57    public ObjectData(ObjectData original) : this(original, new Dictionary<Guid, object>()) { }
     58
     59    /// <summary>
     60    /// Copy constructor, creates a deep copy of the ObjectData instance.
    5061    /// </summary>
    5162    /// <remarks>HeuristicLab data items are cloned with the <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of
     
    5364    /// are cloned with their own <c>Clone</c> methods (shadow copy).</remarks>
    5465    /// <exception cref="InvalidOperationException">Thrown when the current instance is not cloneable.</exception>
    55     /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
    56     /// <returns>The clone instance.</returns>
    57     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    58       ObjectData clone = (ObjectData)base.Clone(clonedObjects);
    59       if (Data is IStorable)
    60         clone.myData = Auxiliary.Clone((IStorable)Data, clonedObjects);
    61       else if (Data is ICloneable)
    62         clone.myData = ((ICloneable)Data).Clone();
     66    /// <param name="clonedObjects">A dictionary of all already cloned objects (for referential integrity).</param>
     67    protected ObjectData(ObjectData original, IDictionary<Guid, object> clonedObjects)
     68      : base(original, clonedObjects) {
     69      if (original.Data is IStorable)
     70        this.myData = Auxiliary.Clone((IStorable)original.Data, clonedObjects);
     71      else if (original.Data is ICloneable)
     72        this.myData = ((ICloneable)original.Data).Clone();
    6373      else
    6474        throw new InvalidOperationException("contained object is not cloneable");
    65       return clone;
    6675    }
    6776
     
    7382    /// the contained data is the same, <c>false</c> otherwise.</returns>
    7483    public override bool Equals(object obj) {
    75       if(obj == this) return true; // same instance
     84      if (obj == this) return true; // same instance
    7685      IObjectData other = obj as IObjectData;
    77       if(other != null)
     86      if (other != null)
    7887        return Data.Equals(other.Data); // are the contained Data the same?
    7988      else
     
    109118    }
    110119
     120    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     121      return new ObjectData(this, clonedObjects);
     122    }
     123
    111124    /// <summary>
    112125    /// The string representation of the current instance.
  • branches/CloningRefactorBranch/HeuristicLab.Data/StringData.cs

    r763 r885  
    5555      Data = data;
    5656    }
     57
     58    /// <summary>
     59    /// Copy constructor to create clones (deep).
     60    /// </summary>
     61    /// <param name="original">The original instance to be cloned.</param>
     62    public StringData(StringData original) : this(original, new Dictionary<Guid, object>()) { }
     63   /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected StringData(StringData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      this.Data = original.Data;
     71    }
    5772   
    5873    /// <summary>
     
    6580
    6681    /// <summary>
    67     /// Clones the current instance.
     82    /// Clones the current instance using the copy constructor.
    6883    /// </summary>
    6984    /// <remarks>The current instance is added to the dictionary <paramref name="clonedObjects"/>.</remarks>
    70     /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
     85    /// <param name="clonedObjects">A dictionary of all already cloned objects (for referential integrity).</param>
    7186    /// <returns>The coned instance as <see cref="StringData"/>.</returns>
    7287    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    73       StringData clone = new StringData();
    74       clonedObjects.Add(Guid, clone);
    75       clone.Data = Data;
    76       return clone;
     88      return new StringData(this, clonedObjects);
    7789    }
    7890
Note: See TracChangeset for help on using the changeset viewer.