Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/10 05:23:56 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs

    r2754 r2756  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3132  /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.
    3233  /// </summary>
    33   [Item("SubScopesItemParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]
    34   public class SubScopesItemParameter<T> : Parameter where T : class, IItem {
     34  [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]
     35  public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
    3536    [Storable]
    3637    private string actualName;
     
    4647    }
    4748
    48     public T[] Values {
    49       get { return GetValues(); }
    50       set { SetValues(value); }
     49    public T[] ActualValues {
     50      get { return GetActualValues(); }
     51      set { SetActualValues(value); }
    5152    }
    5253
    53     public SubScopesItemParameter()
    54       : base("Anonymous", null, typeof(T)) {
     54    public SubScopesLookupParameter()
     55      : base("Anonymous", typeof(T)) {
    5556      actualName = Name;
    5657    }
    57     public SubScopesItemParameter(string name, string description)
     58    public SubScopesLookupParameter(string name)
     59      : base(name, typeof(T)) {
     60      actualName = Name;
     61    }
     62    public SubScopesLookupParameter(string name, string description)
    5863      : base(name, description, typeof(T)) {
    5964      actualName = Name;
     
    6166
    6267    public override IDeepCloneable Clone(Cloner cloner) {
    63       SubScopesItemParameter<T> clone = (SubScopesItemParameter<T>)base.Clone(cloner);
     68      SubScopesLookupParameter<T> clone = (SubScopesLookupParameter<T>)base.Clone(cloner);
    6469      clone.actualName = actualName;
    6570      return clone;
     
    7075    }
    7176
    72     protected string GetActualName() {
    73       string name = Name;
    74       ExecutionContext current = ExecutionContext;
    75       while (current != null) {
    76         if (current.Operator.Parameters.ContainsKey(name))
    77           name = ((SubScopesItemParameter<T>)current.Operator.Parameters[name]).ActualName;
    78         current = current.Parent;
     77    protected virtual T[] GetActualValues() {
     78      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
     79      IScope scope = ExecutionContext.Scope;
     80      T[] values = new T[scope.SubScopes.Count];
     81      IVariable var;
     82      T value;
     83
     84      for (int i = 0; i < values.Length; i++) {
     85        scope.SubScopes[i].Variables.TryGetValue(name, out var);
     86        if (var != null) {
     87          value = var.Value as T;
     88          if (value == null)
     89            throw new InvalidOperationException(
     90              string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     91                            name,
     92                            typeof(T).GetPrettyName())
     93            );
     94          values[i] = value;
     95        }
    7996      }
    80       return name;
     97      return values;
    8198    }
    82     protected virtual T[] GetValues() {
    83       string name = GetActualName();
    84       IScope scope = ExecutionContext.Scope;
    85       T[] value = new T[scope.SubScopes.Count];
    86       IVariable var;
    87 
    88       for (int i = 0; i < value.Length; i++) {
    89         scope.SubScopes[i].Variables.TryGetValue(name, out var);
    90         if (var != null) value[i] = (T)var.Value;
    91       }
    92       return value;
    93     }
    94     protected virtual void SetValues(T[] values) {
    95       string name = GetActualName();
     99    protected virtual void SetActualValues(T[] values) {
     100      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
    96101      IScope scope = ExecutionContext.Scope;
    97102      IVariable var;
Note: See TracChangeset for help on using the changeset viewer.