Free cookie consent management tool by TermsFeed Policy Generator

Changeset 61 for trunk


Ignore:
Timestamp:
03/13/08 23:20:02 (17 years ago)
Author:
swagner
Message:

Worked on ticket #48

  • merged changes from branch Modularization (r55:59) back into trunk again
Location:
trunk/sources
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/HeuristicLab.Core.csproj

    r30 r61  
    9191      <DependentUpon>ChooseTypeDialog.cs</DependentUpon>
    9292    </Compile>
     93    <Compile Include="AliasEventArgs.cs" />
    9394    <Compile Include="OperatorBaseDescriptionView.cs">
    9495      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Core/Interfaces/IScope.cs

    r2 r61  
    3030
    3131    ICollection<IVariable> Variables { get; }
     32    ICollection<string> Aliases { get; }
    3233    IList<IScope> SubScopes { get; }
    3334
     
    4243    IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError);
    4344
     45    string TranslateName(string name);
     46    void AddAlias(string alias, string name);
     47    void RemoveAlias(string alias);
     48
    4449    void AddSubScope(IScope scope);
    4550    void RemoveSubScope(IScope scope);
     
    5257    event EventHandler<VariableEventArgs> VariableAdded;
    5358    event EventHandler<VariableEventArgs> VariableRemoved;
     59    event EventHandler<AliasEventArgs> AliasAdded;
     60    event EventHandler<AliasEventArgs> AliasRemoved;
    5461    event EventHandler<ScopeIndexEventArgs> SubScopeAdded;
    5562    event EventHandler<ScopeIndexEventArgs> SubScopeRemoved;
  • trunk/sources/HeuristicLab.Core/OperatorBase.cs

    r47 r61  
    360360        }
    361361      } else {
    362         return scope.GetVariableValue(info.ActualName, recursiveLookup, throwOnError);
     362        return scope.GetVariableValue(formalName, recursiveLookup, throwOnError);
    363363      }
    364364    }
     
    367367    public virtual IOperation Execute(IScope scope) {
    368368      myCanceled = false;
     369
     370      foreach (IVariableInfo variableInfo in VariableInfos)
     371        scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);
     372
    369373      IOperation next = Apply(scope);
    370374      OnExecuted();
  • trunk/sources/HeuristicLab.Core/Scope.cs

    r2 r61  
    3838      get { return myVariables.Values; }
    3939    }
     40    private IDictionary<string, string> myAliases;
     41    public ICollection<string> Aliases {
     42      get { return myAliases.Values; }
     43    }
    4044    private List<IScope> mySubScopes;
    4145    public IList<IScope> SubScopes {
     
    4650      myName = "Anonymous";
    4751      myVariables = new Dictionary<string, IVariable>();
     52      myAliases = new Dictionary<string, string>();
    4853      mySubScopes = new List<IScope>();
    4954    }
     
    108113    public IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError) {
    109114      IVariable variable;
     115      name = TranslateName(name);
    110116      if (myVariables.TryGetValue(name, out variable)) {
    111117        return variable.Value;
     
    122128    }
    123129
     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
    124151    public void AddSubScope(IScope scope) {
    125152      scope.SetParent(this);
     
    172199        RemoveVariable(variableNames[j]);
    173200
     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
    174210      while (SubScopes.Count > 0)
    175211        RemoveSubScope(SubScopes[0]);
     
    182218      foreach (IVariable variable in myVariables.Values)
    183219        clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
     220      foreach (KeyValuePair<string, string> alias in myAliases)
     221        clone.AddAlias(alias.Key, alias.Value);
    184222      for (int i = 0; i < SubScopes.Count; i++)
    185223        clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects));
     
    197235      if (VariableRemoved != null)
    198236        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));
    199247    }
    200248    public event EventHandler<ScopeIndexEventArgs> SubScopeAdded;
     
    226274      node.AppendChild(variables);
    227275
     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
    228289      XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null);
    229290      for (int i = 0; i < SubScopes.Count; i++)
     
    243304      }
    244305
     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
    245312      XmlNode subScopes = node.SelectSingleNode("SubScopes");
    246313      for (int i = 0; i < subScopes.ChildNodes.Count; i++) {
  • trunk/sources/HeuristicLab.Operators/CombinedOperator.cs

    r52 r61  
    7171          scope.AddVariable(new Variable(SubOperators[i].Name, SubOperators[i]));
    7272        }
    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 
    8173        return new AtomicOperation(OperatorGraph.InitialOperator, scope);
    8274      } else {
Note: See TracChangeset for help on using the changeset viewer.