Changeset 2042 for branches/Operator Architecture Refactoring
- Timestamp:
- 06/15/09 02:18:42 (15 years ago)
- Location:
- branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3
- Files:
-
- 3 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/AtomicOperation.cs
r2033 r2042 72 72 /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param> 73 73 /// <returns>The cloned object as <see cref="AtomicOperation"/>.</returns> 74 public override object Clone(IDictionary<long, object> clonedObjects) {74 public override ICloneable Clone(ICloner cloner) { 75 75 AtomicOperation clone = new AtomicOperation(); 76 clone dObjects.Add(clone.Id, clone);77 clone.myOperator = (IOperator) Auxiliary.Clone(Operator, clonedObjects);78 clone.myScope = (IScope) Auxiliary.Clone(Scope, clonedObjects);76 cloner.AddClonedObject(this, clone); 77 clone.myOperator = (IOperator)cloner.Clone(Operator); 78 clone.myScope = (IScope)cloner.Clone(Scope); 79 79 return clone; 80 80 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Auxiliary.cs
r2033 r2042 30 30 /// </summary> 31 31 public static class Auxiliary { 32 #region Cloning33 /// <summary>34 /// Clones the given <paramref name="obj"/> (deep clone).35 /// </summary>36 /// <remarks>Checks before clone if object has not already been cloned.</remarks>37 /// <param name="obj">The object to clone.</param>38 /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>39 /// <returns>The cloned object.</returns>40 public static object Clone(ICloneable obj, IDictionary<long, object> clonedObjects) {41 object clone;42 if (clonedObjects.TryGetValue(obj.Id, out clone))43 return clone;44 else45 return obj.Clone(clonedObjects);46 }47 #endregion48 49 32 #region Error Messages 50 33 /// <summary> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/CloneableBase.cs
r2033 r2042 31 31 /// </summary> 32 32 public abstract class CloneableBase : ICloneable { 33 /// <summary>34 /// Gets a unique id (memory address) of the current instance. The id is used to35 /// detect, if an object has already been cloned or not.36 /// </summary>37 public long Id {38 get {39 GCHandle handle = new GCHandle();40 handle.Target = this;41 return GCHandle.ToIntPtr(handle).ToInt64();42 }43 }44 45 /// <summary>46 /// Clones the current instance (deep clone).47 /// </summary>48 /// <remarks>Uses the <see cref="Auxiliary.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>49 /// <returns>The clone.</returns>50 33 public object Clone() { 51 return Auxiliary.Clone(this, new Dictionary<long, object>());34 return Clone(new Cloner()); 52 35 } 53 36 /// <summary> … … 57 40 /// <param name="clonedObjects">All already cloned objects.</param> 58 41 /// <returns>The clone.</returns> 59 public virtual object Clone(IDictionary<long, object> clonedObjects) {42 public virtual ICloneable Clone(ICloner cloner) { 60 43 CloneableBase clone = (CloneableBase)Activator.CreateInstance(this.GetType()); 61 clone dObjects.Add(clone.Id, clone);44 cloner.AddClonedObject(this, clone); 62 45 return clone; 63 46 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/CompositeOperation.cs
r2033 r2042 84 84 /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 85 85 /// <returns>The cloned operation as <see cref="CompositeOperation"/>.</returns> 86 public override object Clone(IDictionary<long, object> clonedObjects) {86 public override ICloneable Clone(ICloner cloner) { 87 87 CompositeOperation clone = new CompositeOperation(); 88 clone dObjects.Add(clone.Id, clone);88 cloner.AddClonedObject(this, clone); 89 89 clone.myExecuteInParallel = ExecuteInParallel; 90 90 for (int i = 0; i < Operations.Count; i++) 91 clone.AddOperation((IOperation) Auxiliary.Clone(Operations[i], clonedObjects));91 clone.AddOperation((IOperation)cloner.Clone(Operations[i])); 92 92 return clone; 93 93 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/EngineBase.cs
r2033 r2042 130 130 /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param> 131 131 /// <returns>The cloned object as <see cref="EngineBase"/>.</returns> 132 public override object Clone(IDictionary<long, object> clonedObjects) {133 EngineBase clone = (EngineBase)base.Clone(clone dObjects);134 clone.myOperatorGraph = (IOperatorGraph) Auxiliary.Clone(OperatorGraph, clonedObjects);135 clone.myGlobalScope = (IScope) Auxiliary.Clone(GlobalScope, clonedObjects);132 public override ICloneable Clone(ICloner cloner) { 133 EngineBase clone = (EngineBase)base.Clone(cloner); 134 clone.myOperatorGraph = (IOperatorGraph)cloner.Clone(OperatorGraph); 135 clone.myGlobalScope = (IScope)cloner.Clone(GlobalScope); 136 136 clone.myExecutionTime = ExecutionTime; 137 137 IOperation[] operations = new IOperation[ExecutionStack.Count]; 138 138 ExecutionStack.CopyTo(operations, 0); 139 139 for (int i = operations.Length - 1; i >= 0; i--) 140 clone.myExecutionStack.Push((IOperation) Auxiliary.Clone(operations[i], clonedObjects));140 clone.myExecutionStack.Push((IOperation)cloner.Clone(operations[i])); 141 141 clone.myRunning = Running; 142 142 clone.myCanceled = Canceled; -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r2033 r2042 125 125 <Compile Include="CallGraph.cs" /> 126 126 <Compile Include="CallNode.cs" /> 127 <Compile Include="Cloner.cs" /> 128 <Compile Include="ParameterEventArgs.cs" /> 129 <Compile Include="Interfaces\ICloner.cs" /> 130 <Compile Include="Interfaces\ICloneable.cs" /> 127 131 <Compile Include="ParameterView.cs"> 128 132 <SubType>UserControl</SubType> … … 136 140 <Compile Include="Interfaces\ICallNode.cs" /> 137 141 <Compile Include="Interfaces\ICallGraph.cs" /> 138 <Compile Include="Interfaces\ICloneable.cs" />139 142 <Compile Include="KeyValueEventArgs.cs" /> 140 143 <Compile Include="OperatorBaseDescriptionView.cs"> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/ICloneable.cs
r2033 r2042 30 30 /// </summary> 31 31 public interface ICloneable : System.ICloneable { 32 /// <summary> 33 /// Gets a unique id representing the current object. This id is used to check, if an object has 34 /// already been cloned (to avoid cycles). 35 /// </summary> 36 long Id { get; } 37 /// <summary> 38 /// Clones the current instance, considering already cloned objects. 39 /// </summary> 40 /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param> 41 /// <returns>The cloned object.</returns> 42 object Clone(IDictionary<long, object> clonedObjects); 32 ICloneable Clone(ICloner cloner); 43 33 } 44 34 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IOperator.cs
r2033 r2042 49 49 50 50 /// <summary> 51 /// Gets a list of all sub operators.52 /// </summary>53 IList<IOperator> SubOperators { get; }54 /// <summary>55 51 /// Gets a collection of all variable (parameter) infos. 56 52 /// </summary> 57 ICollection<IVariableInfo> VariableInfos { get; } 58 /// <summary> 59 /// Gets a collection of all variables of the current operator. 60 /// </summary> 61 ICollection<IVariable> Variables { get; } 62 63 /// <summary> 64 /// Adds the given sub operator to the current instance. 65 /// </summary> 66 /// <param name="op">The operator to add.</param> 67 void AddSubOperator(IOperator op); 68 /// <summary> 69 /// Adds the given sub operator at a the specified <paramref name="index"/>. 70 /// </summary> 71 /// <param name="op">The operator to add.</param> 72 /// <param name="index">The position where to add the operator.</param> 73 void AddSubOperator(IOperator op, int index); 74 /// <summary> 75 /// Removes a sub operator at the specified <paramref name="index"/>. 76 /// </summary> 77 /// <param name="index">The position where to delete the operator.</param> 78 void RemoveSubOperator(int index); 53 ICollection<IParameter> Parameters { get; } 79 54 80 55 /// <summary> … … 83 58 /// <param name="formalName">The formal name of the variable info.</param> 84 59 /// <returns>The variable info with the specified formal name.</returns> 85 I VariableInfo GetVariableInfo(string formalName);60 IParameter GetParameter(string name); 86 61 /// <summary> 87 62 /// Adds the specified variable info to the current instance. 88 63 /// </summary> 89 64 /// <param name="variableInfo">The variable info to add.</param> 90 void Add VariableInfo(IVariableInfo variableInfo);65 void AddParameter(IParameter parameter); 91 66 /// <summary> 92 67 /// Removes the variable info with the given formal name. 93 68 /// </summary> 94 69 /// <param name="formalName">The formal name of the variable info to remove.</param> 95 void RemoveVariableInfo(string formalName); 96 97 /// <summary> 98 /// Gets a variable with the given <paramref name="name"/>. 99 /// </summary> 100 /// <param name="name">The name of the variable.</param> 101 /// <returns>The variable with the specified name.</returns> 102 IVariable GetVariable(string name); 103 /// <summary> 104 /// Adds the specified <paramref name="variable"/> to the current instance. 105 /// </summary> 106 /// <param name="variable">The variable to add.</param> 107 void AddVariable(IVariable variable); 108 /// <summary> 109 /// Deletes the variable with the specified <paramref name="name"/>. 110 /// </summary> 111 /// <param name="name">The name of the variable to delete.</param> 112 void RemoveVariable(string name); 113 114 /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/> 115 /// <typeparam name="T">The type of the value that is searched.</typeparam> 116 T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem; 117 /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 118 /// <typeparam name="T">The type of the value that is searched.</typeparam> 119 T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem; 120 /// <inheritdoc cref="GetVariableValue(System.String, IScope, bool, bool)" 121 /// select="summary"/> 122 /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param> 123 /// <param name="scope">The scope where to look for the variable.</param> 124 /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if 125 /// the variable is not found in the specified <paramref name="scope"/>.</param> 126 /// <returns>The value of the searched variable or null if it is not found.</returns> 127 IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup); 128 /// <summary> 129 /// Gets the value of the variable in the specified <paramref name="scope"/> 130 /// whose variable(parameter) info has the specified <paramref name="formalName"/>. 131 /// </summary> 132 /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param> 133 /// <param name="scope">The scope where to look for the variable.</param> 134 /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if 135 /// the variable is not found in the specified <paramref name="scope"/>.</param> 136 /// <param name="throwOnError">Boolean value, whether an exception shall be thrown, if the variable 137 /// cannot be found or just <c>null</c> shall be returned.</param> 138 /// <returns>The value of the searched variable (or null if the variable is not 139 /// found and <paramref name="throwOnError"/> is set to false).</returns> 140 IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError); 70 void RemoveParameter(string name); 141 71 142 72 /// <summary> … … 160 90 event EventHandler BreakpointChanged; 161 91 /// <summary> 162 /// Occurs when a sub operator has been added.163 /// </summary>164 event EventHandler<OperatorIndexEventArgs> SubOperatorAdded;165 /// <summary>166 /// Occurs when a sub operator has been deleted.167 /// </summary>168 event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved;169 /// <summary>170 92 /// Occurs when a variable info has been added. 171 93 /// </summary> 172 event EventHandler< VariableInfoEventArgs> VariableInfoAdded;94 event EventHandler<ParameterEventArgs> ParameterAdded; 173 95 /// <summary> 174 96 /// Occurs when a variable info has been deleted. 175 97 /// </summary> 176 event EventHandler<VariableInfoEventArgs> VariableInfoRemoved; 177 /// <summary> 178 /// Occurs when a variable has been added. 179 /// </summary> 180 event EventHandler<VariableEventArgs> VariableAdded; 181 /// <summary> 182 /// Occurs when a variable has been deleted. 183 /// </summary> 184 event EventHandler<VariableEventArgs> VariableRemoved; 98 event EventHandler<ParameterEventArgs> ParameterRemoved; 185 99 /// <summary> 186 100 /// Occurs when the current instance is executed. -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IScope.cs
r2033 r2042 39 39 /// </summary> 40 40 ICollection<IVariable> Variables { get; } 41 /// <summary>42 /// Gets all aliases of the current scope.43 /// </summary>44 IEnumerable<KeyValuePair<string, string>> Aliases { get; }45 41 /// <summary> 46 42 /// Gets all subscopes in the current scope. … … 96 92 97 93 /// <summary> 98 /// Gets the actual name of the given alias.99 /// </summary>100 /// <param name="name">The alias whose actual name is searched.</param>101 /// <returns>The actual name.</returns>102 string TranslateName(string name);103 /// <summary>104 /// Adds an alias to the current instance.105 /// </summary>106 /// <param name="alias">The alias to add.</param>107 /// <param name="name">The actual name of the alias.</param>108 void AddAlias(string alias, string name);109 /// <summary>110 /// Deletes the specified <paramref name="alias"/> from the current instance.111 /// </summary>112 /// <param name="alias">The alias to delete.</param>113 void RemoveAlias(string alias);114 115 /// <summary>116 94 /// Adds the specified sub scope to the current instance. 117 95 /// </summary> … … 149 127 event EventHandler<VariableEventArgs> VariableRemoved; 150 128 /// <summary> 151 /// Occurs when an alias has been added to the current instance.152 /// </summary>153 event EventHandler<AliasEventArgs> AliasAdded;154 /// <summary>155 /// Occurs when an alias has been removed from the current instance.156 /// </summary>157 event EventHandler<AliasEventArgs> AliasRemoved;158 /// <summary>159 129 /// Occurs when a sub scope has been added to the current instance. 160 130 /// </summary> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorBase.cs
r2033 r2042 78 78 79 79 [Storable] 80 private List<IOperator> mySubOperators; 81 /// <summary> 82 /// Gets a list of all suboperators. 83 /// <note type="caution"> Returns the suboperators read-only!</note> 84 /// </summary> 85 public virtual IList<IOperator> SubOperators { 86 get { return mySubOperators.AsReadOnly(); } 87 } 88 89 [Storable] 90 private Dictionary<string, IVariableInfo> myVariableInfos; 91 /// <inheritdoc/> 92 public virtual ICollection<IVariableInfo> VariableInfos { 93 get { return myVariableInfos.Values; } 94 } 95 96 private Dictionary<string, IVariable> myVariables; 97 /// <inheritdoc/> 98 public virtual ICollection<IVariable> Variables { 99 get { return myVariables.Values; } 100 } 101 102 [Storable(Name="Variables")] 103 private List<IVariable> VariablePersistence { 104 get { return new List<IVariable>(myVariables.Values); } 105 set { 106 myVariables.Clear(); 107 foreach (IVariable var in value) { 108 AddVariable(var); 109 } 110 } 80 private Dictionary<string, IParameter> myParameters; 81 /// <inheritdoc/> 82 public virtual ICollection<IParameter> Parameters { 83 get { return myParameters.Values; } 111 84 } 112 85 … … 119 92 myCanceled = false; 120 93 myBreakpoint = false; 121 mySubOperators = new List<IOperator>(); 122 myVariableInfos = new Dictionary<string, IVariableInfo>(); 123 myVariables = new Dictionary<string, IVariable>(); 94 myParameters = new Dictionary<string, IParameter>(); 124 95 } 125 96 … … 130 101 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 131 102 /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns> 132 public override object Clone(IDictionary<long, object> clonedObjects) {133 OperatorBase clone = (OperatorBase)base.Clone(clone dObjects);103 public override ICloneable Clone(ICloner cloner) { 104 OperatorBase clone = (OperatorBase)base.Clone(cloner); 134 105 clone.myName = Name; 135 clone.mySubOperators.Clear(); 136 for (int i = 0; i < SubOperators.Count; i++) 137 clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects)); 138 clone.myVariableInfos.Clear(); 139 foreach (IVariableInfo variableInfo in myVariableInfos.Values) 140 clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects)); 141 clone.myVariables.Clear(); 142 foreach (IVariable variable in myVariables.Values) 143 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 106 clone.myParameters.Clear(); 107 foreach (IParameter parameter in myParameters.Values) 108 clone.AddParameter((IParameter)cloner.Clone(parameter)); 144 109 return clone; 145 110 } … … 154 119 } 155 120 156 #region SubOperator Methods 157 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator)"/> 158 /// <param name="subOperator">The sub operator to add.</param> 159 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 160 public virtual void AddSubOperator(IOperator subOperator) { 161 mySubOperators.Add(subOperator); 162 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1); 163 } 164 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/> 165 /// <param name="subOperator">The sub operator to add.</param> 166 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 167 public virtual void AddSubOperator(IOperator subOperator, int index) { 168 mySubOperators.Insert(index, subOperator); 169 OnSubOperatorAdded(subOperator, index); 170 } 171 /// <inheritdoc/> 172 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> 173 public virtual void RemoveSubOperator(int index) { 174 IOperator op = mySubOperators[index]; 175 mySubOperators.RemoveAt(index); 176 OnSubOperatorRemoved(op, index); 177 } 178 #endregion 179 180 #region VariableInfo Methods 181 /// <inheritdoc/> 182 public virtual IVariableInfo GetVariableInfo(string formalName) { 183 IVariableInfo info; 184 if (myVariableInfos.TryGetValue(formalName, out info)) 185 return info; 121 #region Parameter Methods 122 /// <inheritdoc/> 123 public virtual IParameter GetParameter(string name) { 124 IParameter parameter; 125 if (myParameters.TryGetValue(name, out parameter)) 126 return parameter; 186 127 else 187 128 return null; … … 189 130 /// <inheritdoc/> 190 131 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 191 public virtual void Add VariableInfo(IVariableInfo variableInfo) {192 my VariableInfos.Add(variableInfo.FormalName, variableInfo);193 On VariableInfoAdded(variableInfo);132 public virtual void AddParameter(IParameter parameter) { 133 myParameters.Add(parameter.Name, parameter); 134 OnParameterAdded(parameter); 194 135 } 195 136 /// <inheritdoc/> 196 137 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 197 public virtual void RemoveVariableInfo(string formalName) { 198 IVariableInfo variableInfo; 199 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) { 200 myVariableInfos.Remove(formalName); 201 OnVariableInfoRemoved(variableInfo); 202 } 203 } 204 #endregion 205 206 #region Variable Methods 207 /// <inheritdoc/> 208 public virtual IVariable GetVariable(string name) { 209 IVariable variable; 210 if (myVariables.TryGetValue(name, out variable)) 211 return variable; 212 else 213 return null; 214 } 215 /// <inheritdoc/> 216 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 217 /// event handlers.</remarks> 218 public virtual void AddVariable(IVariable variable) { 219 myVariables.Add(variable.Name, variable); 220 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 221 variable.NameChanged += new EventHandler(Variable_NameChanged); 222 OnVariableAdded(variable); 223 } 224 /// <inheritdoc/> 225 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 226 /// event handlers.</remarks> 227 public virtual void RemoveVariable(string name) { 228 IVariable variable; 229 if (myVariables.TryGetValue(name, out variable)) { 230 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 231 variable.NameChanged -= new EventHandler(Variable_NameChanged); 232 myVariables.Remove(name); 233 OnVariableRemoved(variable); 234 } 235 } 236 private void Variable_NameChanging(object sender, NameChangingEventArgs e) { 237 e.Cancel = myVariables.ContainsKey(e.Name); 238 } 239 private void Variable_NameChanged(object sender, EventArgs e) { 240 IVariable variable = (IVariable)sender; 241 string oldName = null; 242 foreach (KeyValuePair<string, IVariable> element in myVariables) { 243 if (element.Value == variable) 244 oldName = element.Key; 245 } 246 myVariables.Remove(oldName); 247 myVariables.Add(variable.Name, variable); 248 } 249 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool)"/> 250 /// <remarks>Calls <see cref="GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 251 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 252 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem { 253 return GetVariableValue<T>(formalName, scope, recursiveLookup, true); 254 } 255 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 256 /// <remarks>Calls 257 /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks> 258 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem { 259 return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError); 260 } 261 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/> 262 /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 263 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 264 public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) { 265 return GetVariableValue(formalName, scope, recursiveLookup, true); 266 } 267 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 268 public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) { 269 IVariableInfo info = GetVariableInfo(formalName); 270 if (info.Local) { 271 IVariable variable; 272 if (myVariables.TryGetValue(info.ActualName, out variable)) 273 return variable.Value; 274 else { 275 if (throwOnError) 276 throw new ArgumentException("Variable " + info.ActualName + " not found"); 277 else 278 return null; 279 } 280 } else { 281 return scope.GetVariableValue(formalName, recursiveLookup, throwOnError); 138 public virtual void RemoveParameter(string name) { 139 IParameter parameter; 140 if (myParameters.TryGetValue(name, out parameter)) { 141 myParameters.Remove(name); 142 OnParameterRemoved(parameter); 282 143 } 283 144 } … … 287 148 public virtual IOperation Execute(IScope scope) { 288 149 myCanceled = false; 289 290 foreach (IVariableInfo variableInfo in VariableInfos)291 scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);292 293 150 IOperation next = Apply(scope); 294 295 foreach (IVariableInfo variableInfo in VariableInfos)296 scope.RemoveAlias(variableInfo.FormalName);297 298 151 OnExecuted(); 299 152 return next; … … 333 186 } 334 187 /// <inheritdoc/> 335 public event EventHandler<OperatorIndexEventArgs> SubOperatorAdded; 336 /// <summary> 337 /// Fires a new <c>SubOperatorAdded</c> event. 338 /// </summary> 339 /// <param name="subOperator">The sub operator that has been added.</param> 340 /// <param name="index">The position where the operator has been added.</param> 341 protected virtual void OnSubOperatorAdded(IOperator subOperator, int index) { 342 if (SubOperatorAdded != null) 343 SubOperatorAdded(this, new OperatorIndexEventArgs(subOperator, index)); 344 } 345 /// <inheritdoc/> 346 public event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved; 347 /// <summary> 348 /// Fires a new <c>SubOperatorRemoved</c> event. 349 /// </summary> 350 /// <param name="subOperator">The sub operator that has been removed.</param> 351 /// <param name="index">The position where the operator has been removed.</param> 352 protected virtual void OnSubOperatorRemoved(IOperator subOperator, int index) { 353 if (SubOperatorRemoved != null) 354 SubOperatorRemoved(this, new OperatorIndexEventArgs(subOperator, index)); 355 } 356 /// <inheritdoc/> 357 public event EventHandler<VariableInfoEventArgs> VariableInfoAdded; 188 public event EventHandler<ParameterEventArgs> ParameterAdded; 358 189 /// <summary> 359 190 /// Fires a new <c>VariableInfoAdded</c> event. 360 191 /// </summary> 361 192 /// <param name="variableInfo">The variable info that has been added.</param> 362 protected virtual void On VariableInfoAdded(IVariableInfo variableInfo) {363 if ( VariableInfoAdded != null)364 VariableInfoAdded(this, new VariableInfoEventArgs(variableInfo));365 } 366 /// <inheritdoc/> 367 public event EventHandler< VariableInfoEventArgs> VariableInfoRemoved;193 protected virtual void OnParameterAdded(IParameter parameter) { 194 if (ParameterAdded != null) 195 ParameterAdded(this, new ParameterEventArgs(parameter)); 196 } 197 /// <inheritdoc/> 198 public event EventHandler<ParameterEventArgs> ParameterRemoved; 368 199 /// <summary> 369 200 /// Fires a new <c>VariableInfoRemoved</c> event. 370 201 /// </summary> 371 202 /// <param name="variableInfo">The variable info that has been removed.</param> 372 protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) { 373 if (VariableInfoRemoved != null) 374 VariableInfoRemoved(this, new VariableInfoEventArgs(variableInfo)); 375 } 376 /// <inheritdoc/> 377 public event EventHandler<VariableEventArgs> VariableAdded; 378 /// <summary> 379 /// Fires a new <c>VariableAdded</c> event. 380 /// </summary> 381 /// <param name="variable">The variable that has been added.</param> 382 protected virtual void OnVariableAdded(IVariable variable) { 383 if (VariableAdded != null) 384 VariableAdded(this, new VariableEventArgs(variable)); 385 } 386 /// <inheritdoc/> 387 public event EventHandler<VariableEventArgs> VariableRemoved; 388 /// <summary> 389 /// Fires a new <c>VariableRemoved</c> event. 390 /// </summary> 391 /// <param name="variable">The variable that has been removed</param> 392 protected virtual void OnVariableRemoved(IVariable variable) { 393 if (VariableRemoved != null) 394 VariableRemoved(this, new VariableEventArgs(variable)); 203 protected virtual void OnParameterRemoved(IParameter parameter) { 204 if (ParameterRemoved != null) 205 ParameterRemoved(this, new ParameterEventArgs(parameter)); 395 206 } 396 207 /// <inheritdoc/> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorGraph.cs
r2033 r2042 80 80 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 81 81 /// <returns>The cloned object as <see cref="OperatorGraph"/>.</returns> 82 public override object Clone(IDictionary<long, object> clonedObjects) {82 public override ICloneable Clone(ICloner cloner) { 83 83 OperatorGraph clone = new OperatorGraph(); 84 clone dObjects.Add(clone.Id, clone);84 cloner.AddClonedObject(this, clone); 85 85 foreach (IOperator op in Operators) 86 clone.AddOperator((IOperator) Auxiliary.Clone(op, clonedObjects));86 clone.AddOperator((IOperator)cloner.Clone(op)); 87 87 if (InitialOperator != null) 88 clone.myInitialOperator = (IOperator) Auxiliary.Clone(InitialOperator, clonedObjects);88 clone.myInitialOperator = (IOperator)cloner.Clone(InitialOperator); 89 89 return clone; 90 90 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorGroup.cs
r2033 r2042 84 84 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 85 85 /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns> 86 public override object Clone(IDictionary<long, object> clonedObjects) {87 OperatorGroup clone = (OperatorGroup)base.Clone(clone dObjects);86 public override ICloneable Clone(ICloner cloner) { 87 OperatorGroup clone = (OperatorGroup)base.Clone(cloner); 88 88 clone.myName = Name; 89 89 foreach (IOperatorGroup group in SubGroups) 90 clone.AddSubGroup((IOperatorGroup) Auxiliary.Clone(group, clonedObjects));90 clone.AddSubGroup((IOperatorGroup)cloner.Clone(group)); 91 91 foreach (IOperator op in Operators) 92 clone.AddOperator((IOperator) Auxiliary.Clone(op, clonedObjects));92 clone.AddOperator((IOperator)cloner.Clone(op)); 93 93 return clone; 94 94 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorLibrary.cs
r2033 r2042 70 70 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 71 71 /// <returns>The cloned object as <see cref="OperatorLibrary"/>.</returns> 72 public override object Clone(IDictionary<long, object> clonedObjects) {72 public override ICloneable Clone(ICloner cloner) { 73 73 OperatorLibrary clone = new OperatorLibrary(); 74 clone dObjects.Add(clone.Id, clone);75 clone.myGroup = (IOperatorGroup) Auxiliary.Clone(Group, clonedObjects);74 cloner.AddClonedObject(this, clone); 75 clone.myGroup = (IOperatorGroup)cloner.Clone(Group); 76 76 return clone; 77 77 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Parameter.cs
r2033 r2042 69 69 } 70 70 71 public override object Clone(IDictionary<long, object> clonedObjects) {71 public override ICloneable Clone(ICloner cloner) { 72 72 Parameter clone = new Parameter(); 73 clone dObjects.Add(clone.Id, clone);73 cloner.AddClonedObject(this, clone); 74 74 clone.myName = Name; 75 75 clone.myDescription = Description; -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Scope.cs
r2033 r2042 60 60 } 61 61 } 62 63 [Storable]64 private IDictionary<string, string> myAliases;65 /// <inheritdoc/>66 public IEnumerable<KeyValuePair<string, string>> Aliases {67 get { return myAliases; }68 }69 62 70 63 [Storable] … … 84 77 myName = "Anonymous"; 85 78 myVariables = new Dictionary<string, IVariable>(); 86 myAliases = new Dictionary<string, string>();87 79 mySubScopes = new List<IScope>(); 88 80 } … … 177 169 } 178 170 } 179 /// <inheritdoc/>180 public string TranslateName(string name) {181 while (myAliases.ContainsKey(name))182 name = myAliases[name];183 if (parent != null)184 name = parent.TranslateName(name);185 return name;186 }187 /// <inheritdoc/>188 public void AddAlias(string alias, string name) {189 RemoveAlias(alias);190 if (alias != name) {191 myAliases.Add(alias, name);192 OnAliasAdded(alias);193 }194 }195 /// <inheritdoc/>196 public void RemoveAlias(string alias) {197 if (myAliases.ContainsKey(alias)) {198 myAliases.Remove(alias);199 OnAliasRemoved(alias);200 }201 }202 171 203 172 /// <inheritdoc/> … … 256 225 257 226 /// <inheritdoc/> 258 public override object Clone(IDictionary<long, object> clonedObjects) {259 Scope clone = (Scope)base.Clone(clone dObjects);227 public override ICloneable Clone(ICloner cloner) { 228 Scope clone = (Scope)base.Clone(cloner); 260 229 clone.myName = Name; 261 230 262 231 foreach (IVariable variable in myVariables.Values) 263 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 264 foreach (KeyValuePair<string, string> alias in myAliases) 265 clone.AddAlias(alias.Key, alias.Value); 232 clone.AddVariable((IVariable)cloner.Clone(variable)); 266 233 for (int i = 0; i < SubScopes.Count; i++) 267 clone.AddSubScope((IScope) Auxiliary.Clone(SubScopes[i], clonedObjects));234 clone.AddSubScope((IScope)cloner.Clone(SubScopes[i])); 268 235 269 236 return clone; … … 289 256 if (VariableRemoved != null) 290 257 VariableRemoved(this, new VariableEventArgs(variable)); 291 }292 /// <inheritdoc />293 public event EventHandler<AliasEventArgs> AliasAdded;294 /// <summary>295 /// Fires a new <c>AliasAdded</c> event.296 /// </summary>297 /// <param name="alias">The alias that has been added.</param>298 protected virtual void OnAliasAdded(string alias) {299 if (AliasAdded != null)300 AliasAdded(this, new AliasEventArgs(alias));301 }302 /// <inheritdoc/>303 public event EventHandler<AliasEventArgs> AliasRemoved;304 /// <summary>305 /// Fires a new <c>AliasRemoved</c> event.306 /// </summary>307 /// <param name="alias">The alias that has been deleted.</param>308 protected virtual void OnAliasRemoved(string alias) {309 if (AliasRemoved != null)310 AliasRemoved(this, new AliasEventArgs(alias));311 258 } 312 259 /// <inheritdoc/> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Variable.cs
r2033 r2042 102 102 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 103 103 /// <returns>The cloned object as <see cref="Variable"/>.</returns> 104 public override object Clone(IDictionary<long, object> clonedObjects) {104 public override ICloneable Clone(ICloner cloner) { 105 105 Variable clone = new Variable(); 106 clone dObjects.Add(clone.Id, clone);106 cloner.AddClonedObject(this, clone); 107 107 clone.myName = Name; 108 108 if (Value != null) 109 clone.myValue = (IItem) Auxiliary.Clone(Value, clonedObjects);109 clone.myValue = (IItem)cloner.Clone(Value); 110 110 return clone; 111 111 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/VariableInfo.cs
r2033 r2042 145 145 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 146 146 /// <returns>The cloned object as <see cref="VariableInfo"/>.</returns> 147 public override object Clone(IDictionary<long, object> clonedObjects) {147 public override ICloneable Clone(ICloner cloner) { 148 148 VariableInfo clone = new VariableInfo(); 149 clone dObjects.Add(clone.Id, clone);149 cloner.AddClonedObject(this, clone); 150 150 clone.myActualName = ActualName; 151 151 clone.myFormalName = FormalName;
Note: See TracChangeset
for help on using the changeset viewer.