Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4668


Ignore:
Timestamp:
10/29/10 17:38:42 (12 years ago)
Author:
swagner
Message:

Finished cloning refactoring of HeuristicLab.Common, HeuristicLab.Collections and HeuristicLab.Core (#922)

Location:
branches/CloningRefactoring
Files:
46 edited

Legend:

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

    r3560 r4668  
    6262    [StorableConstructor]
    6363    protected ReadOnlyObservableArray(bool deserializing) { }
     64
     65    [StorableHook(HookType.AfterDeserialization)]
     66    private void AfterDeserialization() {
     67      RegisterEvents();
     68    }
    6469    #endregion
    6570
     
    111116
    112117    #region Events
    113     [StorableHook(HookType.AfterDeserialization)]
    114118    protected void RegisterEvents() {
    115119      array.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsReplaced);
  • branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs

    r3560 r4668  
    5151    [StorableConstructor]
    5252    protected ReadOnlyObservableCollection(bool deserializing) { }
     53
     54    [StorableHook(HookType.AfterDeserialization)]
     55    private void AfterDeserialization() {
     56      RegisterEvents();
     57    }
    5358    #endregion
    5459
     
    8994
    9095    #region Events
    91     [StorableHook(HookType.AfterDeserialization)]
    9296    protected void RegisterEvents() {
    9397      collection.ItemsAdded += new CollectionItemsChangedEventHandler<T>(collection_ItemsAdded);
  • branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs

    r3560 r4668  
    6565    [StorableConstructor]
    6666    protected ReadOnlyObservableDictionary(bool deserializing) { }
     67
     68    [StorableHook(HookType.AfterDeserialization)]
     69    private void AfterDeserialization() {
     70      RegisterEvents();
     71    }
    6772    #endregion
    6873
     
    116121
    117122    #region Events
    118     [StorableHook(HookType.AfterDeserialization)]
    119123    protected void RegisterEvents() {
    120124      dict.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsAdded);
  • branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs

    r3560 r4668  
    5757    [StorableConstructor]
    5858    protected ReadOnlyObservableKeyedCollection(bool deserializing) { }
     59
     60    [StorableHook(HookType.AfterDeserialization)]
     61    private void AfterDeserialization() {
     62      RegisterEvents();
     63    }
    5964    #endregion
    6065
     
    105110
    106111    #region Events
    107     [StorableHook(HookType.AfterDeserialization)]
    108112    protected void RegisterEvents() {
    109113      collection.ItemsAdded += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsAdded);
  • branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs

    r3560 r4668  
    5959    [StorableConstructor]
    6060    protected ReadOnlyObservableList(bool deserializing) { }
     61
     62    [StorableHook(HookType.AfterDeserialization)]
     63    private void AfterDeserialization() {
     64      RegisterEvents();
     65    }
    6166    #endregion
    6267
     
    108113
    109114    #region Events
    110     [StorableHook(HookType.AfterDeserialization)]
    111115    protected void RegisterEvents() {
    112116      list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded);
  • branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableSet.cs

    r3560 r4668  
    5151    [StorableConstructor]
    5252    protected ReadOnlyObservableSet(bool deserializing) { }
     53
     54    [StorableHook(HookType.AfterDeserialization)]
     55    private void AfterDeserialization() {
     56      RegisterEvents();
     57    }
    5358    #endregion
    5459
     
    130135
    131136    #region Events
    132     [StorableHook(HookType.AfterDeserialization)]
    133137    protected void RegisterEvents() {
    134138      set.ItemsAdded += new CollectionItemsChangedEventHandler<T>(set_ItemsAdded);
  • branches/CloningRefactoring/HeuristicLab.Common/3.3/DeepCloneable.cs

    r3387 r4668  
    2020#endregion
    2121
    22 using System;
    2322
    2423namespace HeuristicLab.Common {
     
    2726  /// </summary>
    2827  public abstract class DeepCloneable : IDeepCloneable {
     28    protected DeepCloneable(DeepCloneable original, Cloner cloner) {
     29      cloner.RegisterClonedObject(original, this);
     30    }
    2931    protected DeepCloneable() { }
    3032
     
    4850    /// cloned objects.</param>
    4951    /// <returns>A clone of this instance.</returns>
    50     public virtual IDeepCloneable Clone(Cloner cloner) {
    51       DeepCloneable clone = (DeepCloneable)Activator.CreateInstance(this.GetType(),true);
    52       cloner.RegisterClonedObject(this, clone);
    53       return clone;
    54     }
     52    public abstract IDeepCloneable Clone(Cloner cloner);
    5553  }
    5654}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemCollection.cs

    r4068 r4668  
    4646
    4747    /// <summary>
     48    /// Instantiates an empty CheckedItemCollection for deserialization.
     49    /// </summary>
     50    /// <param name="deserializing"></param>
     51    [StorableConstructor]
     52    protected CheckedItemCollection(bool deserializing) : base(deserializing) { }
     53    protected CheckedItemCollection(CheckedItemCollection<T> original, Cloner cloner)
     54      : base(original, cloner) {
     55      list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     56      checkedState = new Dictionary<T, bool>();
     57      foreach (var pair in original.checkedState)
     58        checkedState.Add(cloner.Clone<T>(pair.Key), pair.Value);
     59    }
     60    /// <summary>
    4861    /// Instantiates a new CheckedItemCollection.
    4962    /// </summary>
     
    7184          checkedState.Add(item, true);
    7285    }
    73     /// <summary>
    74     /// Instantiates an empty CheckedItemCollection for deserialization.
    75     /// </summary>
    76     /// <param name="deserializing"></param>
    77     [StorableConstructor]
    78     protected CheckedItemCollection(bool deserializing) : base(deserializing) { }
    7986
    8087    /// <summary>
     
    179186    /// <returns>A clone of the CheckedItemCollection</returns>
    180187    public override IDeepCloneable Clone(Cloner cloner) {
    181       CheckedItemCollection<T> clone = (CheckedItemCollection<T>)Activator.CreateInstance(this.GetType());
    182       cloner.RegisterClonedObject(this, clone);
    183       clone.list = new List<T>(this.Select(x => (T)cloner.Clone(x)));
    184       clone.checkedState = new Dictionary<T, bool>();
    185       foreach (var pair in checkedState)
    186         clone.checkedState.Add((T)cloner.Clone(pair.Key), pair.Value);
    187       return clone;
     188      return new CheckedItemCollection<T>(this, cloner);
    188189    }
    189190  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemList.cs

    r4068 r4668  
    4848      }
    4949    }
     50
     51    /// <summary>
     52    /// Instantiates a new CheckedItemList for deserialization.
     53    /// </summary>
     54    /// <param name="deserializing"></param>
     55    [StorableConstructor]
     56    protected CheckedItemList(bool deserializing) : base(deserializing) { }
     57    protected CheckedItemList(CheckedItemList<T> original, Cloner cloner)
     58      : base(original, cloner) {
     59      list = new List<T>(original.Select(x => (T)cloner.Clone(x)));
     60      checkedState = new Dictionary<T, bool>();
     61      foreach (var pair in original.checkedState)
     62        checkedState.Add(cloner.Clone<T>(pair.Key), pair.Value);
     63    }
    5064    /// <summary>
    5165    /// Instantiates an empty CheckedItemList.
     
    7589      }
    7690    }
    77     /// <summary>
    78     /// Instantiates a new CheckedItemList for deserialization.
    79     /// </summary>
    80     /// <param name="deserializing"></param>
    81     [StorableConstructor]
    82     protected CheckedItemList(bool deserializing) : base(deserializing) { }
    8391
    8492    /// <summary>
     
    228236    /// <returns>A deep clone of the CheckedItemList</returns>
    229237    public override IDeepCloneable Clone(Cloner cloner) {
    230       CheckedItemList<T> clone = (CheckedItemList<T>)Activator.CreateInstance(this.GetType());
    231       cloner.RegisterClonedObject(this, clone);
    232       clone.list = new List<T>(this.Select(x => (T)cloner.Clone(x)));
    233       clone.checkedState = new Dictionary<T, bool>();
    234       foreach (var pair in checkedState)
    235         clone.checkedState.Add((T)cloner.Clone(pair.Key), pair.Value);
    236       return clone;
     238      return new CheckedItemList<T>(this, cloner);
    237239    }
    238240  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ConstraintCollection.cs

    r4068 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("ConstraintCollection", "Represents a collection of constraints.")]
    2829  public class ConstraintCollection : ItemCollection<IConstraint> {
     30    [StorableConstructor]
     31    protected ConstraintCollection(bool deserializing) : base(deserializing) { }
     32    protected ConstraintCollection(ConstraintCollection original, Cloner cloner) : base(original, cloner) { }
    2933    public ConstraintCollection() : base() { }
    3034    public ConstraintCollection(int capacity) : base(capacity) { }
    3135    public ConstraintCollection(IEnumerable<IConstraint> collection) : base(collection) { }
    32     [StorableConstructor]
    33     protected ConstraintCollection(bool deserializing) : base(deserializing) { }
    3436  }
    3537}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemArray.cs

    r4419 r4668  
    4646    }
    4747
     48    [StorableConstructor]
     49    protected ItemArray(bool deserializing) : base(deserializing) { }
     50    protected ItemArray(ItemArray<T> original, Cloner cloner) {
     51      cloner.RegisterClonedObject(original, this);
     52      array = original.Select(x => cloner.Clone<T>(x)).ToArray();
     53    }
    4854    public ItemArray() : base() { }
    4955    public ItemArray(int length) : base(length) { }
    5056    public ItemArray(T[] array) : base(array) { }
    5157    public ItemArray(IEnumerable<T> collection) : base(collection) { }
    52     [StorableConstructor]
    53     protected ItemArray(bool deserializing) : base(deserializing) { }
    5458
    5559    public object Clone() {
     
    5761    }
    5862    public virtual IDeepCloneable Clone(Cloner cloner) {
    59       ItemArray<T> clone = (ItemArray<T>)Activator.CreateInstance(this.GetType());
    60       cloner.RegisterClonedObject(this, clone);
    61       clone.array = this.Select(x => (T)cloner.Clone(x)).ToArray();
    62       return clone;
     63      return new ItemArray<T>(this, cloner);
    6364    }
    6465
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemCollection.cs

    r4419 r4668  
    4646    }
    4747
     48    [StorableConstructor]
     49    protected ItemCollection(bool deserializing) : base(deserializing) { }
     50    protected ItemCollection(ItemCollection<T> original, Cloner cloner) {
     51      cloner.RegisterClonedObject(original, this);
     52      list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     53    }
    4854    public ItemCollection() : base() { }
    4955    public ItemCollection(int capacity) : base(capacity) { }
    5056    public ItemCollection(IEnumerable<T> collection) : base(collection) { }
    51     [StorableConstructor]
    52     protected ItemCollection(bool deserializing) : base(deserializing) { }
    5357
    5458    public object Clone() {
     
    5660    }
    5761    public virtual IDeepCloneable Clone(Cloner cloner) {
    58       ItemCollection<T> clone = (ItemCollection<T>)Activator.CreateInstance(this.GetType());
    59       cloner.RegisterClonedObject(this, clone);
    60       clone.list = new List<T>(this.Select(x => (T)cloner.Clone(x)));
    61       return clone;
     62      return new ItemCollection<T>(this, cloner);
    6263    }
    6364
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemDictionary.cs

    r4419 r4668  
    4848    }
    4949
     50    [StorableConstructor]
     51    protected ItemDictionary(bool deserializing) : base(deserializing) { }
     52    protected ItemDictionary(ItemDictionary<TKey, TValue> original, Cloner cloner) {
     53      cloner.RegisterClonedObject(original, this);
     54      foreach (TKey key in dict.Keys)
     55        dict.Add(cloner.Clone<TKey>(key), cloner.Clone<TValue>(dict[key]));
     56    }
    5057    public ItemDictionary() : base() { }
    5158    public ItemDictionary(int capacity) : base(capacity) { }
    5259    public ItemDictionary(IDictionary<TKey, TValue> dictionary) : base(dictionary) { }
    53     [StorableConstructor]
    54     protected ItemDictionary(bool deserializing) : base(deserializing) { }
    5560
    5661    public object Clone() {
     
    5863    }
    5964    public virtual IDeepCloneable Clone(Cloner cloner) {
    60       ItemDictionary<TKey, TValue> clone = (ItemDictionary<TKey, TValue>)Activator.CreateInstance(this.GetType());
    61       cloner.RegisterClonedObject(this, clone);
    62       foreach (TKey key in dict.Keys)
    63         clone.dict.Add((TKey)cloner.Clone(key), (TValue)cloner.Clone(dict[key]));
    64       return clone;
     65      return new ItemDictionary<TKey, TValue>(this, cloner);
    6566    }
    6667
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemList.cs

    r4419 r4668  
    4646    }
    4747
     48    [StorableConstructor]
     49    protected ItemList(bool deserializing) : base(deserializing) { }
     50    protected ItemList(ItemList<T> original, Cloner cloner) {
     51      cloner.RegisterClonedObject(original, this);
     52      list = new List<T>(original.Select(x => cloner.Clone<T>(x)));
     53    }
    4854    public ItemList() : base() { }
    4955    public ItemList(int capacity) : base(capacity) { }
    5056    public ItemList(IEnumerable<T> collection) : base(collection) { }
    51     [StorableConstructor]
    52     protected ItemList(bool deserializing) : base(deserializing) { }
    5357
    5458    public object Clone() {
     
    5660    }
    5761    public virtual IDeepCloneable Clone(Cloner cloner) {
    58       ItemList<T> clone = (ItemList<T>)Activator.CreateInstance(this.GetType());
    59       cloner.RegisterClonedObject(this, clone);
    60       clone.list = new List<T>(this.Select(x => (T)cloner.Clone(x)));
    61       return clone;
     62      return new ItemList<T>(this, cloner);
    6263    }
    6364
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemSet.cs

    r4419 r4668  
    4646    }
    4747
     48    [StorableConstructor]
     49    protected ItemSet(bool deserializing) : base(deserializing) { }
     50    protected ItemSet(ItemSet<T> original, Cloner cloner) {
     51      cloner.RegisterClonedObject(original, this);
     52      set = new HashSet<T>(original.Select(x => cloner.Clone<T>(x)));
     53    }
    4854    public ItemSet() : base() { }
    4955    public ItemSet(IEnumerable<T> collection) : base(collection) { }
    50     [StorableConstructor]
    51     protected ItemSet(bool deserializing) : base(deserializing) { }
    5256
    5357    public object Clone() {
     
    5559    }
    5660    public virtual IDeepCloneable Clone(Cloner cloner) {
    57       ItemSet<T> clone = (ItemSet<T>)Activator.CreateInstance(this.GetType());
    58       cloner.RegisterClonedObject(this, clone);
    59       clone.set = new HashSet<T>(this.Select(x => (T)cloner.Clone(x)));
    60       return clone;
     61      return new ItemSet<T>(this, cloner);
    6162    }
    6263
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/KeyedItemCollection.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected KeyedItemCollection(bool deserializing) : base(deserializing) { }
     48    protected KeyedItemCollection(KeyedItemCollection<TKey, TItem> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      foreach (TItem item in original.dict.Values) {
     51        TItem clonedItem = cloner.Clone<TItem>(item);
     52        dict.Add(GetKeyForItem(clonedItem), clonedItem);
     53      }
     54    }
    4655    protected KeyedItemCollection() : base() { }
    4756    protected KeyedItemCollection(int capacity) : base(capacity) { }
    4857    protected KeyedItemCollection(IEnumerable<TItem> collection) : base(collection) { }
    49     [StorableConstructor]
    50     protected KeyedItemCollection(bool deserializing) : base(deserializing) { }
    5158
    5259    public object Clone() {
    5360      return Clone(new Cloner());
    5461    }
    55     public virtual IDeepCloneable Clone(Cloner cloner) {
    56       KeyedItemCollection<TKey, TItem> clone = (KeyedItemCollection<TKey, TItem>)Activator.CreateInstance(this.GetType());
    57       cloner.RegisterClonedObject(this, clone);
    58       foreach (TItem item in dict.Values) {
    59         TItem clonedItem = (TItem)cloner.Clone(item);
    60         clone.dict.Add(GetKeyForItem(clonedItem), clonedItem);
    61       }
    62       return clone;
    63     }
     62    public abstract IDeepCloneable Clone(Cloner cloner);
    6463
    6564    public new ReadOnlyKeyedItemCollection<TKey, TItem> AsReadOnly() {
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/NamedItemCollection.cs

    r4068 r4668  
    2929  [StorableClass]
    3030  public class NamedItemCollection<T> : KeyedItemCollection<string, T> where T : class, INamedItem {
     31    [StorableConstructor]
     32    protected NamedItemCollection(bool deserializing) : base(deserializing) { }
     33    protected NamedItemCollection(NamedItemCollection<T> original, Cloner cloner)
     34      : base(original, cloner) {
     35      RegisterItemEvents(this);
     36    }
    3137    public NamedItemCollection() : base() { }
    3238    public NamedItemCollection(int capacity) : base(capacity) { }
    3339    public NamedItemCollection(IEnumerable<T> collection)
    3440      : base(collection) {
    35       Initialize();
     41      RegisterItemEvents(this);
    3642    }
    37     [StorableConstructor]
    38     protected NamedItemCollection(bool deserializing) : base(deserializing) { }
    3943
    4044    [StorableHook(HookType.AfterDeserialization)]
    41     protected void Initialize() {
     45    private void AfterDeserialization() {
    4246      RegisterItemEvents(this);
    4347    }
    4448
    4549    public override IDeepCloneable Clone(Cloner cloner) {
    46       NamedItemCollection<T> clone = (NamedItemCollection<T>)base.Clone(cloner);
    47       clone.Initialize();
    48       return clone;
     50      return new NamedItemCollection<T>(this, cloner);
    4951    }
    5052
     
    7375    }
    7476
    75     private void RegisterItemEvents(IEnumerable<T> items) {
     77    protected void RegisterItemEvents(IEnumerable<T> items) {
    7678      foreach (T item in items) {
    7779        if (item != null) {
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperationCollection.cs

    r3390 r4668  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    3938    }
    4039
     40    [StorableConstructor]
     41    private OperationCollection(bool deserializing) { }
     42    private OperationCollection(OperationCollection original, Cloner cloner)
     43      : base(original, cloner) {
     44      operations = new List<IOperation>(original.Select(x => cloner.Clone<IOperation>(x)));
     45      parallel = original.parallel;
     46    }
    4147    public OperationCollection() {
    4248      operations = new List<IOperation>();
     
    5157      parallel = false;
    5258    }
    53     [StorableConstructor]
    54     private OperationCollection(bool deserializing) { }
    5559
    5660    public override IDeepCloneable Clone(Cloner cloner) {
    57       OperationCollection clone = (OperationCollection)Activator.CreateInstance(this.GetType());
    58       cloner.RegisterClonedObject(this, clone);
    59       clone.operations = new List<IOperation>(this.Select(x => (IOperation)cloner.Clone(x)));
    60       clone.parallel = parallel;
    61       return clone;
     61      return new OperationCollection(this, cloner);
    6262    }
    6363
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorCollection.cs

    r4419 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("Operator Collection", "Represents a collection of operators.")]
    2829  public class OperatorCollection : ItemCollection<IOperator> {
     30    [StorableConstructor]
     31    protected OperatorCollection(bool deserializing) : base(deserializing) { }
     32    protected OperatorCollection(OperatorCollection original, Cloner cloner) : base(original, cloner) { }
    2933    public OperatorCollection() : base() { }
    3034    public OperatorCollection(IEnumerable<IOperator> collection) : base(collection) { }
    31     [StorableConstructor]
    32     protected OperatorCollection(bool deserializing) : base(deserializing) { }
    3335  }
    3436}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorList.cs

    r4068 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("OperatorList", "Represents a list of operators.")]
    2829  public class OperatorList : ItemList<IOperator> {
     30    [StorableConstructor]
     31    protected OperatorList(bool deserializing) : base(deserializing) { }
     32    protected OperatorList(OperatorList original, Cloner cloner) : base(original, cloner) { }
    2933    public OperatorList() : base() { }
    3034    public OperatorList(int capacity) : base(capacity) { }
    3135    public OperatorList(IEnumerable<IOperator> collection) : base(collection) { }
    32     [StorableConstructor]
    33     protected OperatorList(bool deserializing) : base(deserializing) { }
    3436  }
    3537}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorSet.cs

    r4068 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("OperatorSet", "Represents a set of operators.")]
    2829  public class OperatorSet : ItemSet<IOperator> {
     30    [StorableConstructor]
     31    protected OperatorSet(bool deserializing) : base(deserializing) { }
     32    protected OperatorSet(OperatorSet original, Cloner cloner) : base(original, cloner) { }
    2933    public OperatorSet() : base() { }
    3034    public OperatorSet(IEnumerable<IOperator> collection) : base(collection) { }
    31     [StorableConstructor]
    32     protected OperatorSet(bool deserializing) : base(deserializing) { }
    3335  }
    3436}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ParameterCollection.cs

    r3390 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("ParameterCollection", "Represents a collection of parameters.")]
    2829  public class ParameterCollection : NamedItemCollection<IParameter> {
     30    [StorableConstructor]
     31    protected ParameterCollection(bool deserializing) : base(deserializing) { }
     32    protected ParameterCollection(ParameterCollection original, Cloner cloner) : base(original, cloner) { }
    2933    public ParameterCollection() : base() { }
    3034    public ParameterCollection(int capacity) : base(capacity) { }
    3135    public ParameterCollection(IEnumerable<IParameter> collection) : base(collection) { }
    32     [StorableConstructor]
    33     protected ParameterCollection(bool deserializing) : base(deserializing) { }
    3436  }
    3537}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemCollection.cs

    r4290 r4668  
    3434    }
    3535
     36    [StorableConstructor]
     37    protected ReadOnlyCheckedItemCollection(bool deserializing) : base(deserializing) { }
     38    protected ReadOnlyCheckedItemCollection(ReadOnlyCheckedItemCollection<T> original, Cloner cloner)
     39      : base(original, cloner) {
     40      CheckedItemCollection.CheckedItemsChanged += new CollectionItemsChangedEventHandler<T>(collection_CheckedItemsChanged);
     41    }
    3642    public ReadOnlyCheckedItemCollection() : base(new CheckedItemCollection<T>()) { }
    3743    public ReadOnlyCheckedItemCollection(ICheckedItemCollection<T> collection)
     
    4046    }
    4147
    42     [StorableConstructor]
    43     protected ReadOnlyCheckedItemCollection(bool deserializing) : base(deserializing) { }
    4448    [StorableHook(HookType.AfterDeserialization)]
    45     private void AfterDeserializationHook() {
     49    private void AfterDeserialization() {
    4650      CheckedItemCollection.CheckedItemsChanged += new CollectionItemsChangedEventHandler<T>(collection_CheckedItemsChanged);
    4751    }
    4852
    49     public override IDeepCloneable Clone(Common.Cloner cloner) {
    50       ReadOnlyCheckedItemCollection<T> clone = (ReadOnlyCheckedItemCollection<T>)base.Clone(cloner);
    51       clone.CheckedItemCollection.CheckedItemsChanged += new CollectionItemsChangedEventHandler<T>(clone.collection_CheckedItemsChanged);
    52       return clone;
     53    public override IDeepCloneable Clone(Cloner cloner) {
     54      return new ReadOnlyCheckedItemCollection<T>(this, cloner);
    5355    }
    5456
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemList.cs

    r4290 r4668  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Collections;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
     
    3334    }
    3435
     36    [StorableConstructor]
     37    protected ReadOnlyCheckedItemList(bool deserializing) : base(deserializing) { }
     38    protected ReadOnlyCheckedItemList(ReadOnlyCheckedItemList<T> original, Cloner cloner)
     39      : base(original, cloner) {
     40      CheckedItemList.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CheckedItemsChanged);
     41    }
    3542    public ReadOnlyCheckedItemList() : base(new CheckedItemList<T>()) { }
    3643    public ReadOnlyCheckedItemList(ICheckedItemList<T> list)
     
    3946    }
    4047
    41     [StorableConstructor]
    42     protected ReadOnlyCheckedItemList(bool deserializing) : base(deserializing) { }
    4348    [StorableHook(HookType.AfterDeserialization)]
    44     private void AfterDeserializationHook() {
     49    private void AfterDeserialization() {
    4550      CheckedItemList.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CheckedItemsChanged);
    4651    }
    4752
    48     public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
    49       ReadOnlyCheckedItemList<T> clone = (ReadOnlyCheckedItemList<T>)base.Clone(cloner);
    50       clone.CheckedItemList.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<T>>(clone.list_CheckedItemsChanged);
    51       return clone;
     53    public override IDeepCloneable Clone(Cloner cloner) {
     54      return new ReadOnlyCheckedItemList<T>(this, cloner);
    5255    }
    5356
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemArray.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected ReadOnlyItemArray(bool deserializing) : base(deserializing) { }
     48    protected ReadOnlyItemArray(ReadOnlyItemArray<T> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      array = cloner.Clone<IItemArray<T>>((IItemArray<T>)original.array);
     51      RegisterEvents();
     52    }
    4653    public ReadOnlyItemArray() : base(new ItemArray<T>()) { }
    4754    public ReadOnlyItemArray(IItemArray<T> array) : base(array) { }
    48     [StorableConstructor]
    49     protected ReadOnlyItemArray(bool deserializing) : base(deserializing) { }
    5055
    5156    public object Clone() {
     
    5358    }
    5459    public virtual IDeepCloneable Clone(Cloner cloner) {
    55       ReadOnlyItemArray<T> clone = (ReadOnlyItemArray<T>)Activator.CreateInstance(this.GetType());
    56       cloner.RegisterClonedObject(this, clone);
    57       clone.array = (IItemArray<T>)((IItemArray<T>)array).Clone(cloner);
    58       clone.RegisterEvents();
    59       return clone;
     60      return new ReadOnlyItemArray<T>(this, cloner);
    6061    }
    6162
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemCollection.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected ReadOnlyItemCollection(bool deserializing) : base(deserializing) { }
     48    protected ReadOnlyItemCollection(ReadOnlyItemCollection<T> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      collection = cloner.Clone<IItemCollection<T>>((IItemCollection<T>)original.collection);
     51      RegisterEvents();
     52    }
    4653    public ReadOnlyItemCollection() : base(new ItemCollection<T>()) { }
    4754    public ReadOnlyItemCollection(IItemCollection<T> collection) : base(collection) { }
    48     [StorableConstructor]
    49     protected ReadOnlyItemCollection(bool deserializing) : base(deserializing) { }
    5055
    5156    public object Clone() {
     
    5358    }
    5459    public virtual IDeepCloneable Clone(Cloner cloner) {
    55       ReadOnlyItemCollection<T> clone = (ReadOnlyItemCollection<T>)Activator.CreateInstance(this.GetType());
    56       cloner.RegisterClonedObject(this, clone);
    57       clone.collection = (IItemCollection<T>)((IItemCollection<T>)collection).Clone(cloner);
    58       clone.RegisterEvents();
    59       return clone;
     60      return new ReadOnlyItemCollection<T>(this, cloner);
    6061    }
    6162
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemDictionary.cs

    r4419 r4668  
    4747    }
    4848
     49    [StorableConstructor]
     50    protected ReadOnlyItemDictionary(bool deserializing) : base(deserializing) { }
     51    protected ReadOnlyItemDictionary(ReadOnlyItemDictionary<TKey, TValue> original, Cloner cloner) {
     52      cloner.RegisterClonedObject(original, this);
     53      dict = cloner.Clone((IItemDictionary<TKey, TValue>)original.dict);
     54      RegisterEvents();
     55    }
    4956    public ReadOnlyItemDictionary() : base(new ItemDictionary<TKey, TValue>()) { }
    5057    public ReadOnlyItemDictionary(IItemDictionary<TKey, TValue> dictionary) : base(dictionary) { }
    51     [StorableConstructor]
    52     protected ReadOnlyItemDictionary(bool deserializing) : base(deserializing) { }
    5358
    5459    public object Clone() {
     
    5661    }
    5762    public virtual IDeepCloneable Clone(Cloner cloner) {
    58       ReadOnlyItemDictionary<TKey, TValue> clone = (ReadOnlyItemDictionary<TKey, TValue>)Activator.CreateInstance(this.GetType());
    59       cloner.RegisterClonedObject(this, clone);
    60       clone.dict = (IItemDictionary<TKey, TValue>)((IItemDictionary<TKey, TValue>)dict).Clone(cloner);
    61       clone.RegisterEvents();
    62       return clone;
     63      return new ReadOnlyItemDictionary<TKey, TValue>(this, cloner);
    6364    }
    6465
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemList.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected ReadOnlyItemList(bool deserializing) : base(deserializing) { }
     48    protected ReadOnlyItemList(ReadOnlyItemList<T> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      list = cloner.Clone((IItemList<T>)original.list);
     51      RegisterEvents();
     52    }
    4653    public ReadOnlyItemList() : base(new ItemList<T>()) { }
    4754    public ReadOnlyItemList(IItemList<T> list) : base(list) { }
    48     [StorableConstructor]
    49     protected ReadOnlyItemList(bool deserializing) : base(deserializing) { }
    5055
    5156    public object Clone() {
     
    5358    }
    5459    public virtual IDeepCloneable Clone(Cloner cloner) {
    55       ReadOnlyItemList<T> clone = (ReadOnlyItemList<T>)Activator.CreateInstance(this.GetType());
    56       cloner.RegisterClonedObject(this, clone);
    57       clone.list = (IItemList<T>)((IItemList<T>)list).Clone(cloner);
    58       clone.RegisterEvents();
    59       return clone;
     60      return new ReadOnlyItemList<T>(this, cloner);
    6061    }
    6162
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemSet.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected ReadOnlyItemSet(bool deserializing) : base(deserializing) { }
     48    protected ReadOnlyItemSet(ReadOnlyItemSet<T> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      set = cloner.Clone((IItemSet<T>)original.set);
     51      RegisterEvents();
     52    }
    4653    public ReadOnlyItemSet() : base(new ItemSet<T>()) { }
    4754    public ReadOnlyItemSet(IItemSet<T> set) : base(set) { }
    48     [StorableConstructor]
    49     protected ReadOnlyItemSet(bool deserializing) : base(deserializing) { }
    5055
    5156    public object Clone() {
     
    5358    }
    5459    public virtual IDeepCloneable Clone(Cloner cloner) {
    55       ReadOnlyItemSet<T> clone = (ReadOnlyItemSet<T>)Activator.CreateInstance(this.GetType());
    56       cloner.RegisterClonedObject(this, clone);
    57       clone.set = (IItemSet<T>)((IItemSet<T>)set).Clone(cloner);
    58       clone.RegisterEvents();
    59       return clone;
     60      return new ReadOnlyItemSet<T>(this, cloner);
    6061    }
    6162
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyKeyedItemCollection.cs

    r4419 r4668  
    4444    }
    4545
     46    [StorableConstructor]
     47    protected ReadOnlyKeyedItemCollection(bool deserializing) : base(deserializing) { }
     48    protected ReadOnlyKeyedItemCollection(ReadOnlyKeyedItemCollection<TKey, TItem> original, Cloner cloner) {
     49      cloner.RegisterClonedObject(original, this);
     50      collection = cloner.Clone((IKeyedItemCollection<TKey, TItem>)original.collection);
     51      RegisterEvents();
     52    }
    4653    protected ReadOnlyKeyedItemCollection() : base() { }
    4754    public ReadOnlyKeyedItemCollection(IKeyedItemCollection<TKey, TItem> collection) : base(collection) { }
    48     [StorableConstructor]
    49     protected ReadOnlyKeyedItemCollection(bool deserializing) : base(deserializing) { }
    5055
    5156    public object Clone() {
     
    5358    }
    5459    public virtual IDeepCloneable Clone(Cloner cloner) {
    55       ReadOnlyKeyedItemCollection<TKey, TItem> clone = (ReadOnlyKeyedItemCollection<TKey, TItem>)Activator.CreateInstance(this.GetType());
    56       cloner.RegisterClonedObject(this, clone);
    57       clone.collection = (IKeyedItemCollection<TKey, TItem>)((IKeyedItemCollection<TKey, TItem>)collection).Clone(cloner);
    58       clone.RegisterEvents();
    59       return clone;
     60      return new ReadOnlyKeyedItemCollection<TKey, TItem>(this, cloner);
    6061    }
    6162
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ScopeList.cs

    r3431 r4668  
    2929  [Item("ScopeList", "Represents a list of scopes.")]
    3030  public sealed class ScopeList : ItemList<IScope> {
     31    [StorableConstructor]
     32    private ScopeList(bool deserializing) : base(deserializing) { }
     33    private ScopeList(ScopeList original, Cloner cloner)
     34      : base(original, cloner) {
     35      list = new List<IScope>(original.Select(x => cloner.Clone(x)));
     36    }
    3137    public ScopeList() : base() { }
    3238    public ScopeList(int capacity) : base(capacity) { }
    3339    public ScopeList(IEnumerable<IScope> collection) : base(collection) { }
    34     [StorableConstructor]
    35     private ScopeList(bool deserializing) : base(deserializing) { }
    3640
    3741    public override IDeepCloneable Clone(Cloner cloner) {
    38       ScopeList clone = new ScopeList();
    39       cloner.RegisterClonedObject(this, clone);
    40       clone.list = new List<IScope>(this.Select(x => (IScope)cloner.Clone(x)));
    41       return clone;
     42      return new ScopeList(this, cloner);
    4243    }
    4344  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ValueParameterCollection.cs

    r3390 r4668  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
     
    2728  [Item("ValueParameterCollection", "Represents a collection of value parameters.")]
    2829  public class ValueParameterCollection : NamedItemCollection<IValueParameter> {
     30    [StorableConstructor]
     31    protected ValueParameterCollection(bool deserializing) : base(deserializing) { }
     32    protected ValueParameterCollection(ValueParameterCollection original, Cloner cloner) : base(original, cloner) { }
    2933    public ValueParameterCollection() : base() { }
    3034    public ValueParameterCollection(int capacity) : base(capacity) { }
    3135    public ValueParameterCollection(IEnumerable<IValueParameter> collection) : base(collection) { }
    32     [StorableConstructor]
    33     protected ValueParameterCollection(bool deserializing) : base(deserializing) { }
    3436  }
    3537}
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/VariableCollection.cs

    r4068 r4668  
    2828  [Item("VariableCollection", "Represents a collection of variables.")]
    2929  public sealed class VariableCollection : NamedItemCollection<IVariable> {
     30    [StorableConstructor]
     31    private VariableCollection(bool deserializing) : base(deserializing) { }
     32    private VariableCollection(VariableCollection original, Cloner cloner)
     33      : base(original, cloner) {
     34      foreach (string key in original.dict.Keys)
     35        dict.Add(key, cloner.Clone(original.dict[key]));
     36      RegisterItemEvents(this);
     37    }
    3038    public VariableCollection() : base() { }
    3139    public VariableCollection(int capacity) : base(capacity) { }
    3240    public VariableCollection(IEnumerable<IVariable> collection) : base(collection) { }
    33     [StorableConstructor]
    34     private VariableCollection(bool deserializing) : base(deserializing) { }
    3541
    3642    public override IDeepCloneable Clone(Cloner cloner) {
    37       VariableCollection clone = new VariableCollection();
    38       cloner.RegisterClonedObject(this, clone);
    39       foreach (string key in dict.Keys)
    40         clone.dict.Add(key, (IVariable)cloner.Clone(dict[key]));
    41       clone.Initialize();
    42       return clone;
     43      return new VariableCollection(this, cloner);
    4344    }
    4445  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/ComparisonConstraint.cs

    r4153 r4668  
    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
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/Constraint.cs

    r4345 r4668  
    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      IItem constraintDataItem = original.constraintData as IItem;
     38      ICloneable constraintDataCloneable = original.constraintData as ICloneable;
     39      if (constraintDataItem != null)
     40        constraintData = cloner.Clone(constraintDataItem);
     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  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/EqualityConstraint.cs

    r4153 r4668  
    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
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/TypeCompatibilityConstraint.cs

    r4153 r4668  
    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
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Engine.cs

    r4477 r4668  
    4646    private System.Timers.Timer timer;
    4747
     48    [StorableConstructor]
     49    protected Engine(bool deserializing)
     50      : base(deserializing) {
     51      pausePending = stopPending = false;
     52      timer = new System.Timers.Timer(100);
     53      timer.AutoReset = true;
     54      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     55    }
     56    protected Engine(Engine original, Cloner cloner)
     57      : base(original, cloner) {
     58      if (original.ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
     59      log = cloner.Clone(original.log);
     60      IOperation[] contexts = original.executionStack.ToArray();
     61      for (int i = contexts.Length - 1; i >= 0; i--)
     62        executionStack.Push(cloner.Clone(contexts[i]));
     63      pausePending = original.pausePending;
     64      stopPending = original.stopPending;
     65    }
    4866    protected Engine()
    4967      : base() {
     
    5472      timer.AutoReset = true;
    5573      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    56     }
    57     [StorableConstructor]
    58     protected Engine(bool deserializing)
    59       : base(deserializing) {
    60       pausePending = stopPending = false;
    61       timer = new System.Timers.Timer(100);
    62       timer.AutoReset = true;
    63       timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    64     }
    65 
    66     public override IDeepCloneable Clone(Cloner cloner) {
    67       if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    68       Engine clone = (Engine)base.Clone(cloner);
    69       clone.log = (ILog)cloner.Clone(log);
    70       IOperation[] contexts = executionStack.ToArray();
    71       for (int i = contexts.Length - 1; i >= 0; i--)
    72         clone.executionStack.Push((IOperation)cloner.Clone(contexts[i]));
    73       clone.pausePending = pausePending;
    74       clone.stopPending = stopPending;
    75       return clone;
    7674    }
    7775
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Executable.cs

    r3372 r4668  
    6262    }
    6363
     64    [StorableConstructor]
     65    protected Executable(bool deserializing) : base(deserializing) { }
     66    protected Executable(Executable original, Cloner cloner)
     67      : base(original, cloner) {
     68      executionState = original.executionState;
     69      executionTime = original.executionTime;
     70    }
    6471    protected Executable() {
    6572      executionState = ExecutionState.Stopped;
    6673      executionTime = TimeSpan.Zero;
    67     }
    68     [StorableConstructor]
    69     protected Executable(bool deserializing) : base(deserializing) { }
    70 
    71     public override IDeepCloneable Clone(Cloner cloner) {
    72       Executable clone = (Executable)base.Clone(cloner);
    73       clone.executionState = executionState;
    74       clone.executionTime = executionTime;
    75       return clone;
    7674    }
    7775
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/ExecutionContext.cs

    r4068 r4668  
    5050    }
    5151
     52    [StorableConstructor]
     53    private ExecutionContext(bool deserializing) { }
     54    private ExecutionContext(ExecutionContext original, Cloner cloner)
     55      : base(original, cloner) {
     56      parent = cloner.Clone(original.parent);
     57      parameterizedItem = cloner.Clone(original.parameterizedItem);
     58      scope = cloner.Clone(original.scope);
     59    }
    5260    private ExecutionContext() {
    5361      parent = null;
     
    6371
    6472    public override IDeepCloneable Clone(Cloner cloner) {
    65       ExecutionContext clone = new ExecutionContext();
    66       cloner.RegisterClonedObject(this, clone);
    67       clone.parent = (IExecutionContext)cloner.Clone(parent);
    68       clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
    69       clone.scope = (IScope)cloner.Clone(scope);
    70       return clone;
     73      return new ExecutionContext(this, cloner);
    7174    }
    7275
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Log.cs

    r4419 r4668  
    4343    }
    4444
     45    [StorableConstructor]
     46    protected Log(bool deserializing) : base(deserializing) { }
     47    protected Log(Log original, Cloner cloner)
     48      : base(original, cloner) {
     49      messages = new List<string>(original.messages);
     50    }
    4551    public Log()
    4652      : base() {
    4753      messages = new List<string>();
    4854    }
    49     [StorableConstructor]
    50     protected Log(bool deserializing) : base(deserializing) { }
    5155
    5256    public override IDeepCloneable Clone(Cloner cloner) {
    53       Log clone = (Log)base.Clone(cloner);
    54       clone.messages = new List<string>(messages);
    55       return clone;
     57      return new Log(this, cloner);
    5658    }
    5759
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/NamedItem.cs

    r4477 r4668  
    6666    }
    6767
     68    [StorableConstructor]
     69    protected NamedItem(bool deserializing) : base(deserializing) { }
     70    protected NamedItem(NamedItem original, Cloner cloner)
     71      : base(original, cloner) {
     72      name = original.name;
     73      description = original.description;
     74    }
    6875    /// <summary>
    6976    /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c>
     
    9198      else this.description = description;
    9299    }
    93     [StorableConstructor]
    94     protected NamedItem(bool deserializing) : base(deserializing) { }
    95 
    96     /// <summary>
    97     /// Clones the current instance (deep clone).
    98     /// </summary>
    99     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    100     /// <returns>The cloned object as <see cref="Variable"/>.</returns>
    101     public override IDeepCloneable Clone(Cloner cloner) {
    102       NamedItem clone = (NamedItem)base.Clone(cloner);
    103       clone.name = name;
    104       clone.description = description;
    105       return clone;
    106     }
    107100
    108101    /// <summary>
     
    121114    /// <param name="e">The event arguments of the changing.</param>
    122115    protected virtual void OnNameChanging(CancelEventArgs<string> e) {
    123       if (NameChanging != null)
    124         NameChanging(this, e);
     116      var handler = NameChanging;
     117      if (handler != null) handler(this, e);
    125118    }
    126119    /// <inheritdoc/>
     
    131124    /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks>
    132125    protected virtual void OnNameChanged() {
    133       if (NameChanged != null)
    134         NameChanged(this, EventArgs.Empty);
     126      var handler = NameChanged;
     127      if (handler != null) handler(this, EventArgs.Empty);
    135128      OnToStringChanged();
    136129    }
     
    142135    /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks>
    143136    protected virtual void OnDescriptionChanged() {
    144       if (DescriptionChanged != null)
    145         DescriptionChanged(this, EventArgs.Empty);
     137      var handler = DescriptionChanged;
     138      if (handler != null) handler(this, EventArgs.Empty);
    146139    }
    147140  }
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/OperatorGraph.cs

    r4477 r4668  
    7676    }
    7777
     78    [StorableConstructor]
     79    protected OperatorGraph(bool deserializing) : base(deserializing) { }
     80    protected OperatorGraph(OperatorGraph original, Cloner cloner)
     81      : base(original, cloner) {
     82      operators = cloner.Clone(original.operators);
     83      initialOperator = cloner.Clone(original.initialOperator);
     84      visualizationInfo = cloner.Clone(original.visualizationInfo);
     85      Initialize();
     86    }
    7887    /// <summary>
    7988    /// Initializes a new instance of <see cref="OperatorGraph"/>.
     
    8594      Initialize();
    8695    }
    87     [StorableConstructor]
    88     protected OperatorGraph(bool deserializing) : base(deserializing) { }
    8996
    9097    //mkommend: IMPORTANT DO NOT REMOVE THIS PRIVATE EVENT
     
    93100    private void OnOperatorGraphDeserializationFinished() {
    94101      EventHandler handler = DeserializationFinished;
    95       if (handler != null)
    96         handler(this, EventArgs.Empty);
    97     }
     102      if (handler != null) handler(this, EventArgs.Empty);
     103    }
     104
    98105    [StorableHook(HookType.AfterDeserialization)]
     106    private void AfterDeserialization() {
     107      Initialize();
     108    }
    99109    private void Initialize() {
    100110      RegisterOperatorsEvents();
     
    110120    /// <returns>The cloned object as <see cref="OperatorGraph"/>.</returns>
    111121    public override IDeepCloneable Clone(Cloner cloner) {
    112       OperatorGraph clone = (OperatorGraph)base.Clone(cloner);
    113       clone.operators = (OperatorSet)cloner.Clone(operators);
    114       clone.initialOperator = (IOperator)cloner.Clone(initialOperator);
    115       clone.visualizationInfo = cloner.Clone(visualizationInfo);
    116       clone.Initialize();
    117       return clone;
     122      return new OperatorGraph(this, cloner);
    118123    }
    119124
     
    124129    /// </summary>
    125130    protected virtual void OnInitialOperatorChanged() {
    126       if (InitialOperatorChanged != null)
    127         InitialOperatorChanged(this, EventArgs.Empty);
     131      var handler = InitialOperatorChanged;
     132      if (handler != null) handler(this, EventArgs.Empty);
    128133    }
    129134
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs

    r4332 r4668  
    4545    }
    4646
     47    [StorableConstructor]
     48    protected ParameterizedNamedItem(bool deserializing) : base(deserializing) { }
     49    protected ParameterizedNamedItem(ParameterizedNamedItem original, Cloner cloner)
     50      : base(original, cloner) {
     51      parameters = cloner.Clone(original.parameters);
     52      readOnlyParameters = null;
     53    }
    4754    protected ParameterizedNamedItem()
    4855      : base() {
     
    7481      readOnlyParameters = null;
    7582    }
    76     [StorableConstructor]
    77     protected ParameterizedNamedItem(bool deserializing) : base(deserializing) { }
    78 
    79     public override IDeepCloneable Clone(Cloner cloner) {
    80       ParameterizedNamedItem clone = (ParameterizedNamedItem)base.Clone(cloner);
    81       clone.parameters = (ParameterCollection)cloner.Clone(parameters);
    82       clone.readOnlyParameters = null;
    83       return clone;
    84     }
    8583
    8684    public virtual void CollectParameterValues(IDictionary<string, IItem> values) {
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Scope.cs

    r4489 r4668  
    5959    }
    6060
     61    [StorableConstructor]
     62    private Scope(bool deserializing) : base(deserializing) { }
     63    private Scope(Scope original, Cloner cloner)
     64      : base(original, cloner) {
     65      if (original.variables.Count > 0) variables = cloner.Clone(original.variables);
     66      if (original.subScopes.Count > 0) {
     67        subScopes = cloner.Clone(original.subScopes);
     68        foreach (IScope child in SubScopes)
     69          child.Parent = this;
     70        RegisterSubScopesEvents();
     71      }
     72    }
    6173    /// <summary>
    6274    /// Initializes a new instance of <see cref="Scope"/> having "Anonymous" as default name.
     
    6779      variables = new VariableCollection();
    6880      subScopes = new ScopeList();
    69       Initialize();
     81      RegisterSubScopesEvents();
    7082    }
    7183    /// <summary>
     
    7890      variables = new VariableCollection();
    7991      subScopes = new ScopeList();
    80       Initialize();
     92      RegisterSubScopesEvents();
    8193    }
    8294    public Scope(string name, string description)
     
    8597      variables = new VariableCollection();
    8698      subScopes = new ScopeList();
    87       Initialize();
     99      RegisterSubScopesEvents();
    88100    }
    89     [StorableConstructor]
    90     private Scope(bool deserializing) : base(deserializing) { }
    91101
    92102    [StorableHook(HookType.AfterDeserialization)]
    93     private void Initialize() {
     103    private void AfterDeserialization() {
    94104      RegisterSubScopesEvents();
    95105    }
     
    103113    /// <inheritdoc/>
    104114    public override IDeepCloneable Clone(Cloner cloner) {
    105       Scope clone = new Scope();
    106       cloner.RegisterClonedObject(this, clone);
    107       clone.name = name;
    108       clone.description = description;
    109       if (variables.Count > 0) clone.variables = (VariableCollection)cloner.Clone(variables);
    110       if (subScopes.Count > 0) {
    111         clone.subScopes = (ScopeList)cloner.Clone(subScopes);
    112         foreach (IScope child in clone.SubScopes)
    113           child.Parent = clone;
    114         clone.Initialize();
    115       }
    116       return clone;
     115      return new Scope(this, cloner);
    117116    }
    118117
  • branches/CloningRefactoring/HeuristicLab.Core/3.3/Variable.cs

    r4477 r4668  
    5555    }
    5656
     57    [StorableConstructor]
     58    private Variable(bool deserializing) : base(deserializing) { }
     59    private Variable(Variable original, Cloner cloner)
     60      : base(original, cloner) {
     61      value = cloner.Clone(original.value);
     62      RegisterValueEvents();
     63    }
    5764    /// <summary>
    5865    /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c>
     
    8087      : base(name) {
    8188      this.value = value;
    82       Initialize();
     89      RegisterValueEvents();
    8390    }
    8491    public Variable(string name, string description, IItem value)
    8592      : base(name, description) {
    8693      this.value = value;
    87       Initialize();
     94      RegisterValueEvents();
    8895    }
    89     [StorableConstructor]
    90     private Variable(bool deserializing) : base(deserializing) { }
    9196
    9297    [StorableHook(HookType.AfterDeserialization)]
    93     private void Initialize() {
     98    private void AfterDeserialization() {
    9499      RegisterValueEvents();
    95100    }
     
    101106    /// <returns>The cloned object as <see cref="Variable"/>.</returns>
    102107    public override IDeepCloneable Clone(Cloner cloner) {
    103       Variable clone = new Variable(Name, Description);
    104       cloner.RegisterClonedObject(this, clone);
    105       clone.value = (IItem)cloner.Clone(value);
    106       clone.Initialize();
    107       return clone;
     108      return new Variable(this, cloner);
    108109    }
    109110
     
    125126    /// </summary>
    126127    private void OnValueChanged() {
    127       if (ValueChanged != null)
    128         ValueChanged(this, EventArgs.Empty);
     128      var handler = ValueChanged;
     129      if (handler != null) handler(this, EventArgs.Empty);
    129130      OnItemImageChanged();
    130131      OnToStringChanged();
Note: See TracChangeset for help on using the changeset viewer.