Changeset 4668
- Timestamp:
- 10/29/10 17:38:42 (14 years ago)
- Location:
- branches/CloningRefactoring
- Files:
-
- 46 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableArray.cs
r3560 r4668 62 62 [StorableConstructor] 63 63 protected ReadOnlyObservableArray(bool deserializing) { } 64 65 [StorableHook(HookType.AfterDeserialization)] 66 private void AfterDeserialization() { 67 RegisterEvents(); 68 } 64 69 #endregion 65 70 … … 111 116 112 117 #region Events 113 [StorableHook(HookType.AfterDeserialization)]114 118 protected void RegisterEvents() { 115 119 array.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsReplaced); -
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs
r3560 r4668 51 51 [StorableConstructor] 52 52 protected ReadOnlyObservableCollection(bool deserializing) { } 53 54 [StorableHook(HookType.AfterDeserialization)] 55 private void AfterDeserialization() { 56 RegisterEvents(); 57 } 53 58 #endregion 54 59 … … 89 94 90 95 #region Events 91 [StorableHook(HookType.AfterDeserialization)]92 96 protected void RegisterEvents() { 93 97 collection.ItemsAdded += new CollectionItemsChangedEventHandler<T>(collection_ItemsAdded); -
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs
r3560 r4668 65 65 [StorableConstructor] 66 66 protected ReadOnlyObservableDictionary(bool deserializing) { } 67 68 [StorableHook(HookType.AfterDeserialization)] 69 private void AfterDeserialization() { 70 RegisterEvents(); 71 } 67 72 #endregion 68 73 … … 116 121 117 122 #region Events 118 [StorableHook(HookType.AfterDeserialization)]119 123 protected void RegisterEvents() { 120 124 dict.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsAdded); -
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs
r3560 r4668 57 57 [StorableConstructor] 58 58 protected ReadOnlyObservableKeyedCollection(bool deserializing) { } 59 60 [StorableHook(HookType.AfterDeserialization)] 61 private void AfterDeserialization() { 62 RegisterEvents(); 63 } 59 64 #endregion 60 65 … … 105 110 106 111 #region Events 107 [StorableHook(HookType.AfterDeserialization)]108 112 protected void RegisterEvents() { 109 113 collection.ItemsAdded += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsAdded); -
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs
r3560 r4668 59 59 [StorableConstructor] 60 60 protected ReadOnlyObservableList(bool deserializing) { } 61 62 [StorableHook(HookType.AfterDeserialization)] 63 private void AfterDeserialization() { 64 RegisterEvents(); 65 } 61 66 #endregion 62 67 … … 108 113 109 114 #region Events 110 [StorableHook(HookType.AfterDeserialization)]111 115 protected void RegisterEvents() { 112 116 list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded); -
branches/CloningRefactoring/HeuristicLab.Collections/3.3/ReadOnlyObservableSet.cs
r3560 r4668 51 51 [StorableConstructor] 52 52 protected ReadOnlyObservableSet(bool deserializing) { } 53 54 [StorableHook(HookType.AfterDeserialization)] 55 private void AfterDeserialization() { 56 RegisterEvents(); 57 } 53 58 #endregion 54 59 … … 130 135 131 136 #region Events 132 [StorableHook(HookType.AfterDeserialization)]133 137 protected void RegisterEvents() { 134 138 set.ItemsAdded += new CollectionItemsChangedEventHandler<T>(set_ItemsAdded); -
branches/CloningRefactoring/HeuristicLab.Common/3.3/DeepCloneable.cs
r3387 r4668 20 20 #endregion 21 21 22 using System;23 22 24 23 namespace HeuristicLab.Common { … … 27 26 /// </summary> 28 27 public abstract class DeepCloneable : IDeepCloneable { 28 protected DeepCloneable(DeepCloneable original, Cloner cloner) { 29 cloner.RegisterClonedObject(original, this); 30 } 29 31 protected DeepCloneable() { } 30 32 … … 48 50 /// cloned objects.</param> 49 51 /// <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); 55 53 } 56 54 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemCollection.cs
r4068 r4668 46 46 47 47 /// <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> 48 61 /// Instantiates a new CheckedItemCollection. 49 62 /// </summary> … … 71 84 checkedState.Add(item, true); 72 85 } 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) { }79 86 80 87 /// <summary> … … 179 186 /// <returns>A clone of the CheckedItemCollection</returns> 180 187 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); 188 189 } 189 190 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/CheckedItemList.cs
r4068 r4668 48 48 } 49 49 } 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 } 50 64 /// <summary> 51 65 /// Instantiates an empty CheckedItemList. … … 75 89 } 76 90 } 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) { }83 91 84 92 /// <summary> … … 228 236 /// <returns>A deep clone of the CheckedItemList</returns> 229 237 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); 237 239 } 238 240 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ConstraintCollection.cs
r4068 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("ConstraintCollection", "Represents a collection of constraints.")] 28 29 public class ConstraintCollection : ItemCollection<IConstraint> { 30 [StorableConstructor] 31 protected ConstraintCollection(bool deserializing) : base(deserializing) { } 32 protected ConstraintCollection(ConstraintCollection original, Cloner cloner) : base(original, cloner) { } 29 33 public ConstraintCollection() : base() { } 30 34 public ConstraintCollection(int capacity) : base(capacity) { } 31 35 public ConstraintCollection(IEnumerable<IConstraint> collection) : base(collection) { } 32 [StorableConstructor]33 protected ConstraintCollection(bool deserializing) : base(deserializing) { }34 36 } 35 37 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemArray.cs
r4419 r4668 46 46 } 47 47 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 } 48 54 public ItemArray() : base() { } 49 55 public ItemArray(int length) : base(length) { } 50 56 public ItemArray(T[] array) : base(array) { } 51 57 public ItemArray(IEnumerable<T> collection) : base(collection) { } 52 [StorableConstructor]53 protected ItemArray(bool deserializing) : base(deserializing) { }54 58 55 59 public object Clone() { … … 57 61 } 58 62 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); 63 64 } 64 65 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemCollection.cs
r4419 r4668 46 46 } 47 47 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 } 48 54 public ItemCollection() : base() { } 49 55 public ItemCollection(int capacity) : base(capacity) { } 50 56 public ItemCollection(IEnumerable<T> collection) : base(collection) { } 51 [StorableConstructor]52 protected ItemCollection(bool deserializing) : base(deserializing) { }53 57 54 58 public object Clone() { … … 56 60 } 57 61 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); 62 63 } 63 64 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemDictionary.cs
r4419 r4668 48 48 } 49 49 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 } 50 57 public ItemDictionary() : base() { } 51 58 public ItemDictionary(int capacity) : base(capacity) { } 52 59 public ItemDictionary(IDictionary<TKey, TValue> dictionary) : base(dictionary) { } 53 [StorableConstructor]54 protected ItemDictionary(bool deserializing) : base(deserializing) { }55 60 56 61 public object Clone() { … … 58 63 } 59 64 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); 65 66 } 66 67 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemList.cs
r4419 r4668 46 46 } 47 47 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 } 48 54 public ItemList() : base() { } 49 55 public ItemList(int capacity) : base(capacity) { } 50 56 public ItemList(IEnumerable<T> collection) : base(collection) { } 51 [StorableConstructor]52 protected ItemList(bool deserializing) : base(deserializing) { }53 57 54 58 public object Clone() { … … 56 60 } 57 61 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); 62 63 } 63 64 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ItemSet.cs
r4419 r4668 46 46 } 47 47 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 } 48 54 public ItemSet() : base() { } 49 55 public ItemSet(IEnumerable<T> collection) : base(collection) { } 50 [StorableConstructor]51 protected ItemSet(bool deserializing) : base(deserializing) { }52 56 53 57 public object Clone() { … … 55 59 } 56 60 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); 61 62 } 62 63 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/KeyedItemCollection.cs
r4419 r4668 44 44 } 45 45 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 } 46 55 protected KeyedItemCollection() : base() { } 47 56 protected KeyedItemCollection(int capacity) : base(capacity) { } 48 57 protected KeyedItemCollection(IEnumerable<TItem> collection) : base(collection) { } 49 [StorableConstructor]50 protected KeyedItemCollection(bool deserializing) : base(deserializing) { }51 58 52 59 public object Clone() { 53 60 return Clone(new Cloner()); 54 61 } 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); 64 63 65 64 public new ReadOnlyKeyedItemCollection<TKey, TItem> AsReadOnly() { -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/NamedItemCollection.cs
r4068 r4668 29 29 [StorableClass] 30 30 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 } 31 37 public NamedItemCollection() : base() { } 32 38 public NamedItemCollection(int capacity) : base(capacity) { } 33 39 public NamedItemCollection(IEnumerable<T> collection) 34 40 : base(collection) { 35 Initialize();41 RegisterItemEvents(this); 36 42 } 37 [StorableConstructor]38 protected NamedItemCollection(bool deserializing) : base(deserializing) { }39 43 40 44 [StorableHook(HookType.AfterDeserialization)] 41 pr otected void Initialize() {45 private void AfterDeserialization() { 42 46 RegisterItemEvents(this); 43 47 } 44 48 45 49 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); 49 51 } 50 52 … … 73 75 } 74 76 75 pr ivatevoid RegisterItemEvents(IEnumerable<T> items) {77 protected void RegisterItemEvents(IEnumerable<T> items) { 76 78 foreach (T item in items) { 77 79 if (item != null) { -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperationCollection.cs
r3390 r4668 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 39 38 } 40 39 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 } 41 47 public OperationCollection() { 42 48 operations = new List<IOperation>(); … … 51 57 parallel = false; 52 58 } 53 [StorableConstructor]54 private OperationCollection(bool deserializing) { }55 59 56 60 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); 62 62 } 63 63 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorCollection.cs
r4419 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("Operator Collection", "Represents a collection of operators.")] 28 29 public class OperatorCollection : ItemCollection<IOperator> { 30 [StorableConstructor] 31 protected OperatorCollection(bool deserializing) : base(deserializing) { } 32 protected OperatorCollection(OperatorCollection original, Cloner cloner) : base(original, cloner) { } 29 33 public OperatorCollection() : base() { } 30 34 public OperatorCollection(IEnumerable<IOperator> collection) : base(collection) { } 31 [StorableConstructor]32 protected OperatorCollection(bool deserializing) : base(deserializing) { }33 35 } 34 36 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorList.cs
r4068 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("OperatorList", "Represents a list of operators.")] 28 29 public class OperatorList : ItemList<IOperator> { 30 [StorableConstructor] 31 protected OperatorList(bool deserializing) : base(deserializing) { } 32 protected OperatorList(OperatorList original, Cloner cloner) : base(original, cloner) { } 29 33 public OperatorList() : base() { } 30 34 public OperatorList(int capacity) : base(capacity) { } 31 35 public OperatorList(IEnumerable<IOperator> collection) : base(collection) { } 32 [StorableConstructor]33 protected OperatorList(bool deserializing) : base(deserializing) { }34 36 } 35 37 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/OperatorSet.cs
r4068 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("OperatorSet", "Represents a set of operators.")] 28 29 public class OperatorSet : ItemSet<IOperator> { 30 [StorableConstructor] 31 protected OperatorSet(bool deserializing) : base(deserializing) { } 32 protected OperatorSet(OperatorSet original, Cloner cloner) : base(original, cloner) { } 29 33 public OperatorSet() : base() { } 30 34 public OperatorSet(IEnumerable<IOperator> collection) : base(collection) { } 31 [StorableConstructor]32 protected OperatorSet(bool deserializing) : base(deserializing) { }33 35 } 34 36 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ParameterCollection.cs
r3390 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("ParameterCollection", "Represents a collection of parameters.")] 28 29 public class ParameterCollection : NamedItemCollection<IParameter> { 30 [StorableConstructor] 31 protected ParameterCollection(bool deserializing) : base(deserializing) { } 32 protected ParameterCollection(ParameterCollection original, Cloner cloner) : base(original, cloner) { } 29 33 public ParameterCollection() : base() { } 30 34 public ParameterCollection(int capacity) : base(capacity) { } 31 35 public ParameterCollection(IEnumerable<IParameter> collection) : base(collection) { } 32 [StorableConstructor]33 protected ParameterCollection(bool deserializing) : base(deserializing) { }34 36 } 35 37 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemCollection.cs
r4290 r4668 34 34 } 35 35 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 } 36 42 public ReadOnlyCheckedItemCollection() : base(new CheckedItemCollection<T>()) { } 37 43 public ReadOnlyCheckedItemCollection(ICheckedItemCollection<T> collection) … … 40 46 } 41 47 42 [StorableConstructor]43 protected ReadOnlyCheckedItemCollection(bool deserializing) : base(deserializing) { }44 48 [StorableHook(HookType.AfterDeserialization)] 45 private void AfterDeserialization Hook() {49 private void AfterDeserialization() { 46 50 CheckedItemCollection.CheckedItemsChanged += new CollectionItemsChangedEventHandler<T>(collection_CheckedItemsChanged); 47 51 } 48 52 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); 53 55 } 54 56 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemList.cs
r4290 r4668 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Collections; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 … … 33 34 } 34 35 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 } 35 42 public ReadOnlyCheckedItemList() : base(new CheckedItemList<T>()) { } 36 43 public ReadOnlyCheckedItemList(ICheckedItemList<T> list) … … 39 46 } 40 47 41 [StorableConstructor]42 protected ReadOnlyCheckedItemList(bool deserializing) : base(deserializing) { }43 48 [StorableHook(HookType.AfterDeserialization)] 44 private void AfterDeserialization Hook() {49 private void AfterDeserialization() { 45 50 CheckedItemList.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CheckedItemsChanged); 46 51 } 47 52 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); 52 55 } 53 56 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemArray.cs
r4419 r4668 44 44 } 45 45 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 } 46 53 public ReadOnlyItemArray() : base(new ItemArray<T>()) { } 47 54 public ReadOnlyItemArray(IItemArray<T> array) : base(array) { } 48 [StorableConstructor]49 protected ReadOnlyItemArray(bool deserializing) : base(deserializing) { }50 55 51 56 public object Clone() { … … 53 58 } 54 59 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); 60 61 } 61 62 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemCollection.cs
r4419 r4668 44 44 } 45 45 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 } 46 53 public ReadOnlyItemCollection() : base(new ItemCollection<T>()) { } 47 54 public ReadOnlyItemCollection(IItemCollection<T> collection) : base(collection) { } 48 [StorableConstructor]49 protected ReadOnlyItemCollection(bool deserializing) : base(deserializing) { }50 55 51 56 public object Clone() { … … 53 58 } 54 59 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); 60 61 } 61 62 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemDictionary.cs
r4419 r4668 47 47 } 48 48 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 } 49 56 public ReadOnlyItemDictionary() : base(new ItemDictionary<TKey, TValue>()) { } 50 57 public ReadOnlyItemDictionary(IItemDictionary<TKey, TValue> dictionary) : base(dictionary) { } 51 [StorableConstructor]52 protected ReadOnlyItemDictionary(bool deserializing) : base(deserializing) { }53 58 54 59 public object Clone() { … … 56 61 } 57 62 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); 63 64 } 64 65 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemList.cs
r4419 r4668 44 44 } 45 45 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 } 46 53 public ReadOnlyItemList() : base(new ItemList<T>()) { } 47 54 public ReadOnlyItemList(IItemList<T> list) : base(list) { } 48 [StorableConstructor]49 protected ReadOnlyItemList(bool deserializing) : base(deserializing) { }50 55 51 56 public object Clone() { … … 53 58 } 54 59 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); 60 61 } 61 62 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyItemSet.cs
r4419 r4668 44 44 } 45 45 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 } 46 53 public ReadOnlyItemSet() : base(new ItemSet<T>()) { } 47 54 public ReadOnlyItemSet(IItemSet<T> set) : base(set) { } 48 [StorableConstructor]49 protected ReadOnlyItemSet(bool deserializing) : base(deserializing) { }50 55 51 56 public object Clone() { … … 53 58 } 54 59 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); 60 61 } 61 62 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ReadOnlyKeyedItemCollection.cs
r4419 r4668 44 44 } 45 45 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 } 46 53 protected ReadOnlyKeyedItemCollection() : base() { } 47 54 public ReadOnlyKeyedItemCollection(IKeyedItemCollection<TKey, TItem> collection) : base(collection) { } 48 [StorableConstructor]49 protected ReadOnlyKeyedItemCollection(bool deserializing) : base(deserializing) { }50 55 51 56 public object Clone() { … … 53 58 } 54 59 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); 60 61 } 61 62 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ScopeList.cs
r3431 r4668 29 29 [Item("ScopeList", "Represents a list of scopes.")] 30 30 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 } 31 37 public ScopeList() : base() { } 32 38 public ScopeList(int capacity) : base(capacity) { } 33 39 public ScopeList(IEnumerable<IScope> collection) : base(collection) { } 34 [StorableConstructor]35 private ScopeList(bool deserializing) : base(deserializing) { }36 40 37 41 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); 42 43 } 43 44 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/ValueParameterCollection.cs
r3390 r4668 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("ValueParameterCollection", "Represents a collection of value parameters.")] 28 29 public class ValueParameterCollection : NamedItemCollection<IValueParameter> { 30 [StorableConstructor] 31 protected ValueParameterCollection(bool deserializing) : base(deserializing) { } 32 protected ValueParameterCollection(ValueParameterCollection original, Cloner cloner) : base(original, cloner) { } 29 33 public ValueParameterCollection() : base() { } 30 34 public ValueParameterCollection(int capacity) : base(capacity) { } 31 35 public ValueParameterCollection(IEnumerable<IValueParameter> collection) : base(collection) { } 32 [StorableConstructor]33 protected ValueParameterCollection(bool deserializing) : base(deserializing) { }34 36 } 35 37 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Collections/VariableCollection.cs
r4068 r4668 28 28 [Item("VariableCollection", "Represents a collection of variables.")] 29 29 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 } 30 38 public VariableCollection() : base() { } 31 39 public VariableCollection(int capacity) : base(capacity) { } 32 40 public VariableCollection(IEnumerable<IVariable> collection) : base(collection) { } 33 [StorableConstructor]34 private VariableCollection(bool deserializing) : base(deserializing) { }35 41 36 42 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); 43 44 } 44 45 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/ComparisonConstraint.cs
r4153 r4668 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 … … 30 31 [StorableConstructor] 31 32 protected ComparisonConstraint(bool deserializing) : base(deserializing) { } 32 33 protected ComparisonConstraint(ComparisonConstraint original, Cloner cloner) : base(original, cloner) { } 33 34 public ComparisonConstraint() : base() { } 34 35 public ComparisonConstraint(IItem constrainedValue, ConstraintOperation comparisonOperation, object comparisonValue) … … 41 42 public override IEnumerable<ConstraintOperation> AllowedConstraintOperations { 42 43 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); 43 48 } 44 49 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/Constraint.cs
r4345 r4668 31 31 [StorableConstructor] 32 32 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; 33 36 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 } 34 48 protected Constraint() { 35 49 this.Active = false; … … 138 152 protected virtual void OnActiveChanged() { 139 153 EventHandler handler = ActiveChanged; 140 if (handler != null) 141 handler(this, EventArgs.Empty); 154 if (handler != null) handler(this, EventArgs.Empty); 142 155 } 143 156 … … 145 158 protected virtual void OnConstrainedValueChanged() { 146 159 EventHandler handler = ConstrainedValueChanged; 147 if (handler != null) 148 handler(this, EventArgs.Empty); 160 if (handler != null) handler(this, EventArgs.Empty); 149 161 } 150 162 … … 152 164 protected virtual void OnConstraintDataChanged() { 153 165 EventHandler handler = ConstraintDataChanged; 154 if (handler != null) 155 handler(this, EventArgs.Empty); 166 if (handler != null) handler(this, EventArgs.Empty); 156 167 } 157 168 … … 159 170 protected virtual void OnConstraintOperationChanged() { 160 171 EventHandler handler = ConstraintOperationChanged; 161 if (handler != null) 162 handler(this, EventArgs.Empty); 172 if (handler != null) handler(this, EventArgs.Empty); 163 173 } 164 174 #endregion … … 182 192 return s; 183 193 } 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 else196 clone.constraintData = constraintData;197 198 clone.constraintOperation = this.constraintOperation;199 200 return clone;201 }202 194 #endregion 203 195 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/EqualityConstraint.cs
r4153 r4668 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 … … 30 31 [StorableConstructor] 31 32 protected EqualityConstraint(bool deserializing) : base(deserializing) { } 32 33 protected EqualityConstraint(EqualityConstraint original, Cloner cloner) : base(original, cloner) { } 33 34 public EqualityConstraint() : base() { } 34 35 public EqualityConstraint(IItem constrainedValue, ConstraintOperation constraintOperation, object constraintData) … … 41 42 public override IEnumerable<ConstraintOperation> AllowedConstraintOperations { 42 43 get { return new ConstraintOperation[2] { ConstraintOperation.Equal, ConstraintOperation.NotEqual }; } 44 } 45 46 public override IDeepCloneable Clone(Cloner cloner) { 47 return new EqualityConstraint(this, cloner); 43 48 } 44 49 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Constraints/TypeCompatibilityConstraint.cs
r4153 r4668 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 … … 28 29 [Item("TypeCompatibilityConstraint", "A constraint that checks for compatible types.")] 29 30 public class TypeCompatibilityConstraint : Constraint { 30 public TypeCompatibilityConstraint() {31 }32 31 [StorableConstructor] 33 32 protected TypeCompatibilityConstraint(bool deserializing) : base(deserializing) { } 33 protected TypeCompatibilityConstraint(TypeCompatibilityConstraint original, Cloner cloner) : base(original, cloner) { } 34 public TypeCompatibilityConstraint() : base() { } 34 35 public TypeCompatibilityConstraint(IItem constrainedValue, ConstraintOperation constraintOperation, Type constraintData) 35 36 : base(constrainedValue, constraintOperation, constraintData) { … … 46 47 public override IEnumerable<ConstraintOperation> AllowedConstraintOperations { 47 48 get { return new ConstraintOperation[2] { ConstraintOperation.IsTypeCompatible, ConstraintOperation.IsTypeNotCompatible }; } 49 } 50 51 public override IDeepCloneable Clone(Cloner cloner) { 52 return new TypeCompatibilityConstraint(this, cloner); 48 53 } 49 54 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Engine.cs
r4477 r4668 46 46 private System.Timers.Timer timer; 47 47 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 } 48 66 protected Engine() 49 67 : base() { … … 54 72 timer.AutoReset = true; 55 73 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;76 74 } 77 75 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Executable.cs
r3372 r4668 62 62 } 63 63 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 } 64 71 protected Executable() { 65 72 executionState = ExecutionState.Stopped; 66 73 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;76 74 } 77 75 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/ExecutionContext.cs
r4068 r4668 50 50 } 51 51 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 } 52 60 private ExecutionContext() { 53 61 parent = null; … … 63 71 64 72 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); 71 74 } 72 75 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Log.cs
r4419 r4668 43 43 } 44 44 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 } 45 51 public Log() 46 52 : base() { 47 53 messages = new List<string>(); 48 54 } 49 [StorableConstructor]50 protected Log(bool deserializing) : base(deserializing) { }51 55 52 56 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); 56 58 } 57 59 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/NamedItem.cs
r4477 r4668 66 66 } 67 67 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 } 68 75 /// <summary> 69 76 /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c> … … 91 98 else this.description = description; 92 99 } 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 }107 100 108 101 /// <summary> … … 121 114 /// <param name="e">The event arguments of the changing.</param> 122 115 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); 125 118 } 126 119 /// <inheritdoc/> … … 131 124 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 132 125 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); 135 128 OnToStringChanged(); 136 129 } … … 142 135 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 143 136 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); 146 139 } 147 140 } -
branches/CloningRefactoring/HeuristicLab.Core/3.3/OperatorGraph.cs
r4477 r4668 76 76 } 77 77 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 } 78 87 /// <summary> 79 88 /// Initializes a new instance of <see cref="OperatorGraph"/>. … … 85 94 Initialize(); 86 95 } 87 [StorableConstructor]88 protected OperatorGraph(bool deserializing) : base(deserializing) { }89 96 90 97 //mkommend: IMPORTANT DO NOT REMOVE THIS PRIVATE EVENT … … 93 100 private void OnOperatorGraphDeserializationFinished() { 94 101 EventHandler handler = DeserializationFinished; 95 if (handler != null) 96 handler(this, EventArgs.Empty);97 } 102 if (handler != null) handler(this, EventArgs.Empty); 103 } 104 98 105 [StorableHook(HookType.AfterDeserialization)] 106 private void AfterDeserialization() { 107 Initialize(); 108 } 99 109 private void Initialize() { 100 110 RegisterOperatorsEvents(); … … 110 120 /// <returns>The cloned object as <see cref="OperatorGraph"/>.</returns> 111 121 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); 118 123 } 119 124 … … 124 129 /// </summary> 125 130 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); 128 133 } 129 134 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs
r4332 r4668 45 45 } 46 46 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 } 47 54 protected ParameterizedNamedItem() 48 55 : base() { … … 74 81 readOnlyParameters = null; 75 82 } 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 }85 83 86 84 public virtual void CollectParameterValues(IDictionary<string, IItem> values) { -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Scope.cs
r4489 r4668 59 59 } 60 60 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 } 61 73 /// <summary> 62 74 /// Initializes a new instance of <see cref="Scope"/> having "Anonymous" as default name. … … 67 79 variables = new VariableCollection(); 68 80 subScopes = new ScopeList(); 69 Initialize();81 RegisterSubScopesEvents(); 70 82 } 71 83 /// <summary> … … 78 90 variables = new VariableCollection(); 79 91 subScopes = new ScopeList(); 80 Initialize();92 RegisterSubScopesEvents(); 81 93 } 82 94 public Scope(string name, string description) … … 85 97 variables = new VariableCollection(); 86 98 subScopes = new ScopeList(); 87 Initialize();99 RegisterSubScopesEvents(); 88 100 } 89 [StorableConstructor]90 private Scope(bool deserializing) : base(deserializing) { }91 101 92 102 [StorableHook(HookType.AfterDeserialization)] 93 private void Initialize() {103 private void AfterDeserialization() { 94 104 RegisterSubScopesEvents(); 95 105 } … … 103 113 /// <inheritdoc/> 104 114 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); 117 116 } 118 117 -
branches/CloningRefactoring/HeuristicLab.Core/3.3/Variable.cs
r4477 r4668 55 55 } 56 56 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 } 57 64 /// <summary> 58 65 /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c> … … 80 87 : base(name) { 81 88 this.value = value; 82 Initialize();89 RegisterValueEvents(); 83 90 } 84 91 public Variable(string name, string description, IItem value) 85 92 : base(name, description) { 86 93 this.value = value; 87 Initialize();94 RegisterValueEvents(); 88 95 } 89 [StorableConstructor]90 private Variable(bool deserializing) : base(deserializing) { }91 96 92 97 [StorableHook(HookType.AfterDeserialization)] 93 private void Initialize() {98 private void AfterDeserialization() { 94 99 RegisterValueEvents(); 95 100 } … … 101 106 /// <returns>The cloned object as <see cref="Variable"/>.</returns> 102 107 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); 108 109 } 109 110 … … 125 126 /// </summary> 126 127 private void OnValueChanged() { 127 if (ValueChanged != null)128 ValueChanged(this, EventArgs.Empty);128 var handler = ValueChanged; 129 if (handler != null) handler(this, EventArgs.Empty); 129 130 OnItemImageChanged(); 130 131 OnToStringChanged();
Note: See TracChangeset
for help on using the changeset viewer.