- Timestamp:
- 03/13/08 23:20:02 (17 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/HeuristicLab.Core.csproj
r30 r61 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> -
trunk/sources/HeuristicLab.Core/Interfaces/IScope.cs
r2 r61 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; -
trunk/sources/HeuristicLab.Core/OperatorBase.cs
r47 r61 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(); -
trunk/sources/HeuristicLab.Core/Scope.cs
r2 r61 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 RemoveAlias(alias); 139 if (alias != name) { 140 myAliases.Add(alias, name); 141 OnAliasAdded(alias); 142 } 143 } 144 public void RemoveAlias(string alias) { 145 if (myAliases.ContainsKey(alias)) { 146 myAliases.Remove(alias); 147 OnAliasRemoved(alias); 148 } 149 } 150 124 151 public void AddSubScope(IScope scope) { 125 152 scope.SetParent(this); … … 172 199 RemoveVariable(variableNames[j]); 173 200 201 string[] aliases = new string[Aliases.Count]; 202 i = 0; 203 foreach (string alias in myAliases.Keys) { 204 aliases[i] = alias; 205 i++; 206 } 207 for (int j = 0; j < aliases.Length; j++) 208 RemoveAlias(aliases[j]); 209 174 210 while (SubScopes.Count > 0) 175 211 RemoveSubScope(SubScopes[0]); … … 182 218 foreach (IVariable variable in myVariables.Values) 183 219 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 220 foreach (KeyValuePair<string, string> alias in myAliases) 221 clone.AddAlias(alias.Key, alias.Value); 184 222 for (int i = 0; i < SubScopes.Count; i++) 185 223 clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects)); … … 197 235 if (VariableRemoved != null) 198 236 VariableRemoved(this, new VariableEventArgs(variable)); 237 } 238 public event EventHandler<AliasEventArgs> AliasAdded; 239 protected virtual void OnAliasAdded(string alias) { 240 if (AliasAdded != null) 241 AliasAdded(this, new AliasEventArgs(alias)); 242 } 243 public event EventHandler<AliasEventArgs> AliasRemoved; 244 protected virtual void OnAliasRemoved(string alias) { 245 if (AliasRemoved != null) 246 AliasRemoved(this, new AliasEventArgs(alias)); 199 247 } 200 248 public event EventHandler<ScopeIndexEventArgs> SubScopeAdded; … … 226 274 node.AppendChild(variables); 227 275 276 XmlNode aliases = document.CreateNode(XmlNodeType.Element, "Aliases", null); 277 foreach (KeyValuePair<string, string> alias in myAliases) { 278 XmlNode aliasNode = document.CreateNode(XmlNodeType.Element, "Alias", null); 279 XmlAttribute keyAttribute = document.CreateAttribute("Alias"); 280 keyAttribute.Value = alias.Key; 281 aliasNode.Attributes.Append(keyAttribute); 282 XmlAttribute valueAttribute = document.CreateAttribute("Name"); 283 valueAttribute.Value = alias.Value; 284 aliasNode.Attributes.Append(valueAttribute); 285 aliases.AppendChild(aliasNode); 286 } 287 node.AppendChild(aliases); 288 228 289 XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null); 229 290 for (int i = 0; i < SubScopes.Count; i++) … … 243 304 } 244 305 306 XmlNode aliases = node.SelectSingleNode("Aliases"); 307 if (aliases != null) { 308 foreach (XmlNode aliasNode in aliases.ChildNodes) 309 AddAlias(aliasNode.Attributes["Alias"].Value, aliasNode.Attributes["Name"].Value); 310 } 311 245 312 XmlNode subScopes = node.SelectSingleNode("SubScopes"); 246 313 for (int i = 0; i < subScopes.ChildNodes.Count; i++) { -
trunk/sources/HeuristicLab.Operators/CombinedOperator.cs
r52 r61 71 71 scope.AddVariable(new Variable(SubOperators[i].Name, SubOperators[i])); 72 72 } 73 74 foreach (IVariableInfo variableInfo in VariableInfos) {75 IItem value = GetVariableValue(variableInfo.FormalName, scope, true, true);76 if (scope.GetVariable(variableInfo.FormalName) != null)77 scope.RemoveVariable(variableInfo.FormalName);78 scope.AddVariable(new Variable(variableInfo.FormalName, value));79 }80 81 73 return new AtomicOperation(OperatorGraph.InitialOperator, scope); 82 74 } else {
Note: See TracChangeset
for help on using the changeset viewer.