Changeset 56
- Timestamp:
- 03/07/08 23:52:38 (17 years ago)
- Location:
- branches/Modularization/HeuristicLab.Core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Modularization/HeuristicLab.Core/HeuristicLab.Core.csproj
r30 r56 91 91 <DependentUpon>ChooseTypeDialog.cs</DependentUpon> 92 92 </Compile> 93 <Compile Include="AliasEventArgs.cs" /> 93 94 <Compile Include="OperatorBaseDescriptionView.cs"> 94 95 <SubType>UserControl</SubType> -
branches/Modularization/HeuristicLab.Core/Interfaces/IScope.cs
r2 r56 30 30 31 31 ICollection<IVariable> Variables { get; } 32 ICollection<string> Aliases { get; } 32 33 IList<IScope> SubScopes { get; } 33 34 … … 42 43 IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError); 43 44 45 string TranslateName(string name); 46 void AddAlias(string alias, string name); 47 void RemoveAlias(string alias); 48 44 49 void AddSubScope(IScope scope); 45 50 void RemoveSubScope(IScope scope); … … 52 57 event EventHandler<VariableEventArgs> VariableAdded; 53 58 event EventHandler<VariableEventArgs> VariableRemoved; 59 event EventHandler<AliasEventArgs> AliasAdded; 60 event EventHandler<AliasEventArgs> AliasRemoved; 54 61 event EventHandler<ScopeIndexEventArgs> SubScopeAdded; 55 62 event EventHandler<ScopeIndexEventArgs> SubScopeRemoved; -
branches/Modularization/HeuristicLab.Core/OperatorBase.cs
r47 r56 360 360 } 361 361 } else { 362 return scope.GetVariableValue( info.ActualName, recursiveLookup, throwOnError);362 return scope.GetVariableValue(formalName, recursiveLookup, throwOnError); 363 363 } 364 364 } … … 367 367 public virtual IOperation Execute(IScope scope) { 368 368 myCanceled = false; 369 370 foreach (IVariableInfo variableInfo in VariableInfos) 371 scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName); 372 369 373 IOperation next = Apply(scope); 370 374 OnExecuted(); -
branches/Modularization/HeuristicLab.Core/Scope.cs
r2 r56 38 38 get { return myVariables.Values; } 39 39 } 40 private IDictionary<string, string> myAliases; 41 public ICollection<string> Aliases { 42 get { return myAliases.Values; } 43 } 40 44 private List<IScope> mySubScopes; 41 45 public IList<IScope> SubScopes { … … 46 50 myName = "Anonymous"; 47 51 myVariables = new Dictionary<string, IVariable>(); 52 myAliases = new Dictionary<string, string>(); 48 53 mySubScopes = new List<IScope>(); 49 54 } … … 108 113 public IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError) { 109 114 IVariable variable; 115 name = TranslateName(name); 110 116 if (myVariables.TryGetValue(name, out variable)) { 111 117 return variable.Value; … … 122 128 } 123 129 130 public string TranslateName(string name) { 131 while (myAliases.ContainsKey(name)) 132 name = myAliases[name]; 133 if (parent != null) 134 name = parent.TranslateName(name); 135 return name; 136 } 137 public void AddAlias(string alias, string name) { 138 if (alias != name) { 139 if (myAliases.ContainsKey(alias)) 140 myAliases.Remove(alias); 141 myAliases.Add(alias, name); 142 OnAliasAdded(alias); 143 } 144 } 145 public void RemoveAlias(string alias) { 146 if (myAliases.ContainsKey(alias)) { 147 myAliases.Remove(alias); 148 OnAliasRemoved(alias); 149 } 150 } 151 124 152 public void AddSubScope(IScope scope) { 125 153 scope.SetParent(this); … … 172 200 RemoveVariable(variableNames[j]); 173 201 202 string[] aliases = new string[Aliases.Count]; 203 i = 0; 204 foreach (string alias in myAliases.Keys) { 205 aliases[i] = alias; 206 i++; 207 } 208 for (int j = 0; j < aliases.Length; j++) 209 RemoveAlias(aliases[j]); 210 174 211 while (SubScopes.Count > 0) 175 212 RemoveSubScope(SubScopes[0]); … … 182 219 foreach (IVariable variable in myVariables.Values) 183 220 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 221 foreach (KeyValuePair<string, string> alias in myAliases) 222 clone.AddAlias(alias.Key, alias.Value); 184 223 for (int i = 0; i < SubScopes.Count; i++) 185 224 clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects)); … … 197 236 if (VariableRemoved != null) 198 237 VariableRemoved(this, new VariableEventArgs(variable)); 238 } 239 public event EventHandler<AliasEventArgs> AliasAdded; 240 protected virtual void OnAliasAdded(string alias) { 241 if (AliasAdded != null) 242 AliasAdded(this, new AliasEventArgs(alias)); 243 } 244 public event EventHandler<AliasEventArgs> AliasRemoved; 245 protected virtual void OnAliasRemoved(string alias) { 246 if (AliasRemoved != null) 247 AliasRemoved(this, new AliasEventArgs(alias)); 199 248 } 200 249 public event EventHandler<ScopeIndexEventArgs> SubScopeAdded; … … 226 275 node.AppendChild(variables); 227 276 277 XmlNode aliases = document.CreateNode(XmlNodeType.Element, "Aliases", null); 278 foreach (KeyValuePair<string, string> alias in myAliases) { 279 XmlNode child = document.CreateNode(XmlNodeType.Element, alias.Key, null); 280 child.InnerText = alias.Value; 281 aliases.AppendChild(child); 282 } 283 node.AppendChild(aliases); 284 228 285 XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null); 229 286 for (int i = 0; i < SubScopes.Count; i++) … … 243 300 } 244 301 302 XmlNode aliases = node.SelectSingleNode("Aliases"); 303 if (aliases != null) { 304 foreach (XmlNode aliasNode in aliases.ChildNodes) 305 AddAlias(aliasNode.Name, aliasNode.InnerText); 306 } 307 245 308 XmlNode subScopes = node.SelectSingleNode("SubScopes"); 246 309 for (int i = 0; i < subScopes.ChildNodes.Count; i++) {
Note: See TracChangeset
for help on using the changeset viewer.