Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/10 01:56:04 (14 years ago)
Author:
swagner
Message:

Merged cloning refactoring branch back into trunk (#922)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Core/3.3/Constraints/ComparisonConstraint.cs

    r4153 r4722  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
     
    3031    [StorableConstructor]
    3132    protected ComparisonConstraint(bool deserializing) : base(deserializing) { }
    32 
     33    protected ComparisonConstraint(ComparisonConstraint original, Cloner cloner) : base(original, cloner) { }
    3334    public ComparisonConstraint() : base() { }
    3435    public ComparisonConstraint(IItem constrainedValue, ConstraintOperation comparisonOperation, object comparisonValue)
     
    4142    public override IEnumerable<ConstraintOperation> AllowedConstraintOperations {
    4243      get { return new ConstraintOperation[6] { ConstraintOperation.Less, ConstraintOperation.LessOrEqual, ConstraintOperation.Equal, ConstraintOperation.GreaterOrEqual, ConstraintOperation.Greater, ConstraintOperation.NotEqual }; }
     44    }
     45
     46    public override IDeepCloneable Clone(Cloner cloner) {
     47      return new ComparisonConstraint(this, cloner);
    4348    }
    4449
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/Constraint.cs

    r4345 r4722  
    3131    [StorableConstructor]
    3232    protected Constraint(bool deserializing) : base(deserializing) { }
     33    protected Constraint(Constraint original, Cloner cloner)
     34      : base(original, cloner) {
     35      constrainedValue = null;  //mkommend: intentionally set to null;
    3336
     37      IDeepCloneable constraintDataDeepCloneable = original.constraintData as IDeepCloneable;
     38      ICloneable constraintDataCloneable = original.constraintData as ICloneable;
     39      if (constraintDataDeepCloneable != null)
     40        constraintData = cloner.Clone(constraintDataDeepCloneable);
     41      else if (constraintDataCloneable != null)
     42        constraintData = constraintDataCloneable.Clone();
     43      else
     44        constraintData = original.constraintData;
     45
     46      constraintOperation = original.constraintOperation;
     47    }
    3448    protected Constraint() {
    3549      this.Active = false;
     
    138152    protected virtual void OnActiveChanged() {
    139153      EventHandler handler = ActiveChanged;
    140       if (handler != null)
    141         handler(this, EventArgs.Empty);
     154      if (handler != null) handler(this, EventArgs.Empty);
    142155    }
    143156
     
    145158    protected virtual void OnConstrainedValueChanged() {
    146159      EventHandler handler = ConstrainedValueChanged;
    147       if (handler != null)
    148         handler(this, EventArgs.Empty);
     160      if (handler != null) handler(this, EventArgs.Empty);
    149161    }
    150162
     
    152164    protected virtual void OnConstraintDataChanged() {
    153165      EventHandler handler = ConstraintDataChanged;
    154       if (handler != null)
    155         handler(this, EventArgs.Empty);
     166      if (handler != null) handler(this, EventArgs.Empty);
    156167    }
    157168
     
    159170    protected virtual void OnConstraintOperationChanged() {
    160171      EventHandler handler = ConstraintOperationChanged;
    161       if (handler != null)
    162         handler(this, EventArgs.Empty);
     172      if (handler != null) handler(this, EventArgs.Empty);
    163173    }
    164174    #endregion
     
    182192      return s;
    183193    }
    184 
    185     public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
    186       Constraint clone = (Constraint)base.Clone(cloner);
    187       clone.constrainedValue = null;  //mkommend: intentionally set to null;
    188 
    189       IItem constraintDataItem = this.constraintData as IItem;
    190       ICloneable constraintDataCloneable = this.constraintData as ICloneable;
    191       if (constraintDataItem != null)
    192         clone.constraintData = cloner.Clone(constraintDataItem);
    193       else if (constraintDataCloneable != null)
    194         clone.constraintData = constraintDataCloneable.Clone();
    195       else
    196         clone.constraintData = constraintData;
    197 
    198       clone.constraintOperation = this.constraintOperation;
    199 
    200       return clone;
    201     }
    202194    #endregion
    203195  }
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/EqualityConstraint.cs

    r4153 r4722  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
     
    3031    [StorableConstructor]
    3132    protected EqualityConstraint(bool deserializing) : base(deserializing) { }
    32 
     33    protected EqualityConstraint(EqualityConstraint original, Cloner cloner) : base(original, cloner) { }
    3334    public EqualityConstraint() : base() { }
    3435    public EqualityConstraint(IItem constrainedValue, ConstraintOperation constraintOperation, object constraintData)
     
    4142    public override IEnumerable<ConstraintOperation> AllowedConstraintOperations {
    4243      get { return new ConstraintOperation[2] { ConstraintOperation.Equal, ConstraintOperation.NotEqual }; }
     44    }
     45
     46    public override IDeepCloneable Clone(Cloner cloner) {
     47      return new EqualityConstraint(this, cloner);
    4348    }
    4449
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/TypeCompatibilityConstraint.cs

    r4153 r4722  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
     
    2829  [Item("TypeCompatibilityConstraint", "A constraint that checks for compatible types.")]
    2930  public class TypeCompatibilityConstraint : Constraint {
    30     public TypeCompatibilityConstraint() {
    31     }
    3231    [StorableConstructor]
    3332    protected TypeCompatibilityConstraint(bool deserializing) : base(deserializing) { }
     33    protected TypeCompatibilityConstraint(TypeCompatibilityConstraint original, Cloner cloner) : base(original, cloner) { }
     34    public TypeCompatibilityConstraint() : base() { }
    3435    public TypeCompatibilityConstraint(IItem constrainedValue, ConstraintOperation constraintOperation, Type constraintData)
    3536      : base(constrainedValue, constraintOperation, constraintData) {
     
    4647    public override IEnumerable<ConstraintOperation> AllowedConstraintOperations {
    4748      get { return new ConstraintOperation[2] { ConstraintOperation.IsTypeCompatible, ConstraintOperation.IsTypeNotCompatible }; }
     49    }
     50
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new TypeCompatibilityConstraint(this, cloner);
    4853    }
    4954
Note: See TracChangeset for help on using the changeset viewer.