Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4671


Ignore:
Timestamp:
10/29/10 18:28:32 (14 years ago)
Author:
swagner
Message:

Finished cloning refactoring of HeuristicLab.Parameters and simplified cloning code of HeuristicLab.Core (#922)

Location:
branches/CloningRefactoring
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemCollection.cs

    r4668 r4671  
    5353    protected CheckedItemCollection(CheckedItemCollection<T> original, Cloner cloner)
    5454      : base(original, cloner) {
    55       list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     55      list = new List<T>(original.Select(x => cloner.Clone(x)));
    5656      checkedState = new Dictionary<T, bool>();
    5757      foreach (var pair in original.checkedState)
    58         checkedState.Add(cloner.Clone<T>(pair.Key), pair.Value);
     58        checkedState.Add(cloner.Clone(pair.Key), pair.Value);
    5959    }
    6060    /// <summary>
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemList.cs

    r4668 r4671  
    6060      checkedState = new Dictionary<T, bool>();
    6161      foreach (var pair in original.checkedState)
    62         checkedState.Add(cloner.Clone<T>(pair.Key), pair.Value);
     62        checkedState.Add(cloner.Clone(pair.Key), pair.Value);
    6363    }
    6464    /// <summary>
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemArray.cs

    r4668 r4671  
    5050    protected ItemArray(ItemArray<T> original, Cloner cloner) {
    5151      cloner.RegisterClonedObject(original, this);
    52       array = original.Select(x => cloner.Clone<T>(x)).ToArray();
     52      array = original.Select(x => cloner.Clone(x)).ToArray();
    5353    }
    5454    public ItemArray() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemCollection.cs

    r4668 r4671  
    5050    protected ItemCollection(ItemCollection<T> original, Cloner cloner) {
    5151      cloner.RegisterClonedObject(original, this);
    52       list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     52      list = new List<T>(original.Select(x => cloner.Clone(x)));
    5353    }
    5454    public ItemCollection() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemDictionary.cs

    r4668 r4671  
    5353      cloner.RegisterClonedObject(original, this);
    5454      foreach (TKey key in dict.Keys)
    55         dict.Add(cloner.Clone<TKey>(key), cloner.Clone<TValue>(dict[key]));
     55        dict.Add(cloner.Clone(key), cloner.Clone(dict[key]));
    5656    }
    5757    public ItemDictionary() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemList.cs

    r4668 r4671  
    5050    protected ItemList(ItemList<T> original, Cloner cloner) {
    5151      cloner.RegisterClonedObject(original, this);
    52       list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     52      list = new List<T>(original.Select(x => cloner.Clone(x)));
    5353    }
    5454    public ItemList() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemSet.cs

    r4668 r4671  
    5050    protected ItemSet(ItemSet<T> original, Cloner cloner) {
    5151      cloner.RegisterClonedObject(original, this);
    52       set = new HashSet<T>(original.Select(x => cloner.Clone<T>(x)));
     52      set = new HashSet<T>(original.Select(x => cloner.Clone(x)));
    5353    }
    5454    public ItemSet() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/KeyedItemCollection.cs

    r4668 r4671  
    4949      cloner.RegisterClonedObject(original, this);
    5050      foreach (TItem item in original.dict.Values) {
    51         TItem clonedItem = cloner.Clone<TItem>(item);
     51        TItem clonedItem = cloner.Clone(item);
    5252        dict.Add(GetKeyForItem(clonedItem), clonedItem);
    5353      }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperationCollection.cs

    r4668 r4671  
    4242    private OperationCollection(OperationCollection original, Cloner cloner)
    4343      : base(original, cloner) {
    44       operations = new List<IOperation>(original.Select(x => cloner.Clone<IOperation>(x)));
     44      operations = new List<IOperation>(original.Select(x => cloner.Clone(x)));
    4545      parallel = original.parallel;
    4646    }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemArray.cs

    r4668 r4671  
    4848    protected ReadOnlyItemArray(ReadOnlyItemArray<T> original, Cloner cloner) {
    4949      cloner.RegisterClonedObject(original, this);
    50       array = cloner.Clone<IItemArray<T>>((IItemArray<T>)original.array);
     50      array = cloner.Clone((IItemArray<T>)original.array);
    5151      RegisterEvents();
    5252    }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemCollection.cs

    r4668 r4671  
    4848    protected ReadOnlyItemCollection(ReadOnlyItemCollection<T> original, Cloner cloner) {
    4949      cloner.RegisterClonedObject(original, this);
    50       collection = cloner.Clone<IItemCollection<T>>((IItemCollection<T>)original.collection);
     50      collection = cloner.Clone((IItemCollection<T>)original.collection);
    5151      RegisterEvents();
    5252    }
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/ConstrainedValueParameter.cs

    r4332 r4671  
    2323using System.Linq;
    2424using HeuristicLab.Collections;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4142    }
    4243
     44    [StorableConstructor]
     45    protected ConstrainedValueParameter(bool deserializing) : base(deserializing) { }
     46    protected ConstrainedValueParameter(ConstrainedValueParameter<T> original, Cloner cloner) : base(original, cloner) { }
    4347    public ConstrainedValueParameter() : base() { }
    4448    public ConstrainedValueParameter(string name) : base(name) { }
     
    5458    public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues, T value) : base(name, description, validValues, value) { }
    5559    public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues, T value, bool getsCollected) : base(name, description, validValues, value, getsCollected) { }
    56     [StorableConstructor]
    57     protected ConstrainedValueParameter(bool deserializing) : base(deserializing) { }
     60
     61    public override IDeepCloneable Clone(Cloner cloner) {
     62      return new ConstrainedValueParameter<T>(this, cloner);
     63    }
    5864
    5965    protected override void ValidValues_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r4332 r4671  
    6262    }
    6363
     64    [StorableConstructor]
     65    protected LookupParameter(bool deserializing) : base(deserializing) { }
     66    protected LookupParameter(LookupParameter<T> original, Cloner cloner)
     67      : base(original, cloner) {
     68      actualName = original.actualName;
     69    }
    6470    public LookupParameter()
    6571      : base("Anonymous", typeof(T)) {
     
    7884      this.actualName = actualName == null ? string.Empty : actualName;
    7985    }
    80     [StorableConstructor]
    81     protected LookupParameter(bool deserializing) : base(deserializing) { }
    8286
    8387    public override IDeepCloneable Clone(Cloner cloner) {
    84       LookupParameter<T> clone = (LookupParameter<T>)base.Clone(cloner);
    85       clone.actualName = actualName;
    86       return clone;
     88      return new LookupParameter<T>(this, cloner);
    8789    }
    8890
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/OperatorParameter.cs

    r4477 r4671  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3031  [StorableClass]
    3132  public class OperatorParameter : OptionalValueParameter<IOperator> {
     33    [StorableConstructor]
     34    protected OperatorParameter(bool deserializing) : base(deserializing) { }
     35    protected OperatorParameter(OperatorParameter original, Cloner cloner) : base(original, cloner) { }
    3236    public OperatorParameter() : base("Anonymous") { }
    3337    public OperatorParameter(string name) : base(name) { }
     
    3943    public OperatorParameter(string name, string description, IOperator value) : base(name, description, value) { }
    4044    public OperatorParameter(string name, string description, IOperator value, bool getsCollected) : base(name, description, value, getsCollected) { }
    41     [StorableConstructor]
    42     protected OperatorParameter(bool deserializing) : base(deserializing) { }
     45
     46    public override IDeepCloneable Clone(Cloner cloner) {
     47      return new OperatorParameter(this, cloner);
     48    }
    4349  }
    4450}
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/OptionalConstrainedValueParameter.cs

    r4332 r4671  
    8787
    8888    #region Constructors
     89    [StorableConstructor]
     90    protected OptionalConstrainedValueParameter(bool deserializing) : base(deserializing) { }
     91    protected OptionalConstrainedValueParameter(OptionalConstrainedValueParameter<T> original, Cloner cloner)
     92      : base(original, cloner) {
     93      validValues = cloner.Clone(original.validValues);
     94      value = cloner.Clone(original.value);
     95      getsCollected = original.getsCollected;
     96      Initialize();
     97    }
    8998    public OptionalConstrainedValueParameter()
    9099      : base("Anonymous", typeof(T)) {
     
    169178      Initialize();
    170179    }
    171     [StorableConstructor]
    172     protected OptionalConstrainedValueParameter(bool deserializing) : base(deserializing) { }
    173180    #endregion
    174181
    175182    [StorableHook(HookType.AfterDeserialization)]
     183    private void AfterDeserialization() {
     184      Initialize();
     185    }
     186
    176187    private void Initialize() {
    177188      RegisterValidValuesEvents();
     
    180191
    181192    public override IDeepCloneable Clone(Cloner cloner) {
    182       OptionalConstrainedValueParameter<T> clone = (OptionalConstrainedValueParameter<T>)base.Clone(cloner);
    183       clone.validValues = (ItemSet<T>)cloner.Clone(validValues);
    184       clone.value = (T)cloner.Clone(value);
    185       clone.getsCollected = getsCollected;
    186       clone.Initialize();
    187       return clone;
     193      return new OptionalConstrainedValueParameter<T>(this, cloner);
    188194    }
    189195
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/OptionalValueParameter.cs

    r4332 r4671  
    7979
    8080    #region Constructors
     81    [StorableConstructor]
     82    protected OptionalValueParameter(bool deserializing) : base(deserializing) { }
     83    protected OptionalValueParameter(OptionalValueParameter<T> original, Cloner cloner)
     84      : base(original, cloner) {
     85      value = cloner.Clone(original.value);
     86      getsCollected = original.getsCollected;
     87      RegisterValueEvents();
     88    }
    8189    public OptionalValueParameter()
    8290      : base("Anonymous", typeof(T)) {
     
    95103      this.value = value;
    96104      this.getsCollected = true;
    97       Initialize();
     105      RegisterValueEvents();
    98106    }
    99107    public OptionalValueParameter(string name, T value, bool getsCollected)
     
    101109      this.value = value;
    102110      this.getsCollected = getsCollected;
    103       Initialize();
     111      RegisterValueEvents();
    104112    }
    105113    public OptionalValueParameter(string name, string description)
     
    115123      this.value = value;
    116124      this.getsCollected = true;
    117       Initialize();
     125      RegisterValueEvents();
    118126    }
    119127    public OptionalValueParameter(string name, string description, T value, bool getsCollected)
     
    121129      this.value = value;
    122130      this.getsCollected = getsCollected;
    123       Initialize();
     131      RegisterValueEvents();
    124132    }
    125     [StorableConstructor]
    126     protected OptionalValueParameter(bool deserializing) : base(deserializing) { }
    127133    #endregion
    128134
    129135    [StorableHook(HookType.AfterDeserialization)]
    130     private void Initialize() {
     136    private void AfterDeserialization() {
    131137      RegisterValueEvents();
    132138    }
    133139
    134140    public override IDeepCloneable Clone(Cloner cloner) {
    135       OptionalValueParameter<T> clone = (OptionalValueParameter<T>)base.Clone(cloner);
    136       clone.value = (T)cloner.Clone(value);
    137       clone.getsCollected = getsCollected;
    138       clone.Initialize();
    139       return clone;
     141      return new OptionalValueParameter<T>(this, cloner);
    140142    }
    141143
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/Parameter.cs

    r4477 r4671  
    7777    }
    7878
     79    [StorableConstructor]
     80    protected Parameter(bool deserializing) : base(deserializing) { }
     81    protected Parameter(Parameter original, Cloner cloner)
     82      : base(original, cloner) {
     83      dataType = original.dataType;
     84      executionContext = cloner.Clone(original.executionContext);
     85    }
    7986    protected Parameter()
    8087      : base("Anonymous") {
     
    9198      this.dataType = dataType;
    9299    }
    93     [StorableConstructor]
    94     protected Parameter(bool deserializing) : base(deserializing) { }
    95 
    96     public override IDeepCloneable Clone(Cloner cloner) {
    97       Parameter clone = (Parameter)base.Clone(cloner);
    98       clone.dataType = dataType;
    99       clone.executionContext = (IExecutionContext)cloner.Clone(executionContext);
    100       return clone;
    101     }
    102100
    103101    public override string ToString() {
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/ScopeParameter.cs

    r4332 r4671  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3536    }
    3637
     38    [StorableConstructor]
     39    protected ScopeParameter(bool deserializing) : base(deserializing) { }
     40    protected ScopeParameter(ScopeParameter original, Cloner cloner) : base(original, cloner) { }
    3741    public ScopeParameter()
    3842      : base("Anonymous", typeof(IScope)) {
     
    4448      : base(name, description, typeof(IScope)) {
    4549    }
    46     [StorableConstructor]
    47     protected ScopeParameter(bool deserializing) : base(deserializing) { }
     50
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new ScopeParameter(this, cloner);
     53    }
    4854
    4955    public override string ToString() {
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/ScopeTreeLookupParameter.cs

    r3822 r4671  
    4747    }
    4848
     49    [StorableConstructor]
     50    protected ScopeTreeLookupParameter(bool deserializing) : base(deserializing) { }
     51    protected ScopeTreeLookupParameter(ScopeTreeLookupParameter<T> original, Cloner cloner)
     52      : base(original, cloner) {
     53      depth = original.depth;
     54    }
    4955    public ScopeTreeLookupParameter()
    5056      : base() {
     
    7581      this.depth = depth;
    7682    }
    77     [StorableConstructor]
    78     protected ScopeTreeLookupParameter(bool deserializing) : base(deserializing) { }
    7983
    8084    public override IDeepCloneable Clone(Cloner cloner) {
    81       ScopeTreeLookupParameter<T> clone = (ScopeTreeLookupParameter<T>)base.Clone(cloner);
    82       clone.depth = depth;
    83       return clone;
     85      return new ScopeTreeLookupParameter<T>(this, cloner);
    8486    }
    8587
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r4477 r4671  
    7979
    8080    #region Constructors
     81    [StorableConstructor]
     82    protected ValueLookupParameter(bool deserializing) : base(deserializing) { }
     83    protected ValueLookupParameter(ValueLookupParameter<T> original, Cloner cloner)
     84      : base(original, cloner) {
     85      value = cloner.Clone(original.value);
     86      getsCollected = original.getsCollected;
     87      RegisterValueEvents();
     88    }
    8189    public ValueLookupParameter()
    8290      : base() {
     
    95103      this.value = value;
    96104      this.getsCollected = true;
    97       Initialize();
     105      RegisterValueEvents();
    98106    }
    99107    public ValueLookupParameter(string name, T value, bool getsCollected)
     
    101109      this.value = value;
    102110      this.getsCollected = getsCollected;
    103       Initialize();
     111      RegisterValueEvents();
    104112    }
    105113    public ValueLookupParameter(string name, string description)
     
    115123      this.value = value;
    116124      this.getsCollected = true;
    117       Initialize();
     125      RegisterValueEvents();
    118126    }
    119127    public ValueLookupParameter(string name, string description, T value, bool getsCollected)
     
    121129      this.value = value;
    122130      this.getsCollected = getsCollected;
    123       Initialize();
     131      RegisterValueEvents();
    124132    }
    125133    public ValueLookupParameter(string name, string description, string actualName)
     
    131139      this.getsCollected = getsCollected;
    132140    }
    133     [StorableConstructor]
    134     protected ValueLookupParameter(bool deserializing) : base(deserializing) { }
    135141    #endregion
    136142
    137143    [StorableHook(HookType.AfterDeserialization)]
    138     private void Initialize() {
     144    private void AfterDeserialization() {
    139145      RegisterValueEvents();
    140146    }
    141147
    142148    public override IDeepCloneable Clone(Cloner cloner) {
    143       ValueLookupParameter<T> clone = (ValueLookupParameter<T>)base.Clone(cloner);
    144       clone.value = (T)cloner.Clone(value);
    145       clone.getsCollected = getsCollected;
    146       clone.Initialize();
    147       return clone;
     149      return new ValueLookupParameter<T>(this, cloner);
    148150    }
    149151
  • branches/CloningRefactoring/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r4332 r4671  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3940    }
    4041
     42    [StorableConstructor]
     43    protected ValueParameter(bool deserializing) : base(deserializing) { }
     44    protected ValueParameter(ValueParameter<T> original, Cloner cloner) : base(original, cloner) { }
    4145    public ValueParameter() : base() { }
    4246    public ValueParameter(string name) : base(name) { }
     
    4852    public ValueParameter(string name, string description, T value) : base(name, description, value) { }
    4953    public ValueParameter(string name, string description, T value, bool getsCollected) : base(name, description, value, getsCollected) { }
    50     [StorableConstructor]
    51     protected ValueParameter(bool deserializing) : base(deserializing) { }
     54
     55    public override IDeepCloneable Clone(Cloner cloner) {
     56      return new ValueParameter<T>(this, cloner);
     57    }
    5258  }
    5359}
Note: See TracChangeset for help on using the changeset viewer.