Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2715 for trunk


Ignore:
Timestamp:
01/29/10 04:15:45 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • adapted parameters to be able to use generic content types of views
Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperatorParameter.cs

    r2653 r2715  
    3030    IOperator Value { get; set; }
    3131
    32     new IOperator GetValue(ExecutionContext context);
    33 
    3432    event EventHandler ActualNameChanged;
    3533    event EventHandler ValueChanged;
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2714 r2715  
    5050
    5151    public override ExecutionContextCollection Apply(ExecutionContext context) {
    52       IntData value = Value.GetValue(context);
    53       IntData increment = Increment.GetValue(context);
     52      IntData value = (IntData)Value.GetValue(context);
     53      IntData increment = (IntData)Increment.GetValue(context);
    5454      value.Value += increment.Value;
    5555      return base.Apply(context);
  • trunk/sources/HeuristicLab.Operators/3.3/StandardOperator.cs

    r2714 r2715  
    4646
    4747    public override ExecutionContextCollection Apply(ExecutionContext context) {
    48       IOperator successor = Successor.GetValue(context);
     48      IOperator successor = (IOperator)Successor.GetValue(context);
    4949      if (successor != null)
    5050        return new ExecutionContextCollection(new ExecutionContext(context.Parent, successor, context.Scope));
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.Designer.cs

    r2714 r2715  
    2121
    2222namespace HeuristicLab.Parameters.Views {
    23   partial class ItemParameterView {
     23  partial class ItemParameterView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.cs

    r2714 r2715  
    3535  /// The visual representation of a <see cref="Parameter"/>.
    3636  /// </summary>
    37   [Content(typeof(ItemParameter), true)]
    38   public partial class ItemParameterView : ParameterView {
     37  [Content(typeof(ItemParameter<>), true)]
     38  public partial class ItemParameterView<T> : ParameterView where T : class, IItem {
    3939    protected TypeSelectorDialog typeSelectorDialog;
    4040
     
    4444    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    4545    /// No own data storage present.</remarks>
    46     public new ItemParameter Content {
    47       get { return (ItemParameter)base.Content; }
     46    public new ItemParameter<T> Content {
     47      get { return (ItemParameter<T>)base.Content; }
    4848      set { base.Content = value; }
    4949    }
     
    6161    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    6262    /// <param name="variable">The variable to represent visually.</param>
    63     public ItemParameterView(ItemParameter parameter)
     63    public ItemParameterView(ItemParameter<T> parameter)
    6464      : this() {
    6565      Content = parameter;
     
    134134      typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
    135135      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
    136         Content.Value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     136        Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    137137    }
    138138    protected virtual void clearValueButton_Click(object sender, EventArgs e) {
     
    152152    protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
    153153      if (e.Effect != DragDropEffects.None) {
    154         IItem item = e.Data.GetData("Value") as IItem;
    155         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
     154        T item = e.Data.GetData("Value") as T;
     155        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    156156        Content.Value = item;
    157157      }
  • trunk/sources/HeuristicLab.Parameters/3.3/ItemParameter.cs

    r2714 r2715  
    3131  /// Represents a parameter.
    3232  /// </summary>
    33   [Item("ItemParameter", "A parameter which represents an IItem.")]
    34   [Creatable("Test")]
    35   public class ItemParameter : Parameter {
     33  [Item("ItemParameter<T>", "A generic parameter which represents an instance of type T.")]
     34  public class ItemParameter<T> : Parameter where T : class, IItem {
    3635    [Storable]
    3736    private string actualName;
     
    4746    }
    4847
    49     private IItem value;
     48    private T value;
    5049    [Storable]
    51     public IItem Value {
     50    public T Value {
    5251      get { return this.value; }
    5352      set {
     
    6362
    6463    public ItemParameter()
    65       : base("Anonymous", null, typeof(IItem)) {
     64      : base("Anonymous", null, typeof(T)) {
    6665      actualName = Name;
    6766      Value = null;
    6867    }
    69     protected ItemParameter(string name, string description, Type dataType)
    70       : base(name, description, dataType) {
     68    public ItemParameter(string name, string description)
     69      : base(name, description, typeof(T)) {
    7170      this.actualName = Name;
    7271      this.Value = null;
    7372    }
    74     public ItemParameter(string name, string description)
    75       : base(name, description, typeof(IItem)) {
    76       this.actualName = Name;
    77       this.Value = null;
    78     }
    79     public ItemParameter(string name, string description, IItem value)
    80       : base(name, description, typeof(IItem)) {
     73    public ItemParameter(string name, string description, T value)
     74      : base(name, description, typeof(T)) {
    8175      this.actualName = Name;
    8276      this.Value = value;
     
    8478
    8579    public override IItem GetValue(ExecutionContext context) {
    86       ItemParameter param = this;
     80      ItemParameter<T> param = this;
    8781      ExecutionContext current = context;
    8882      string actualName = null;
     
    9488          current = current.Parent;
    9589        if (current != null)
    96           param = (ItemParameter)current.Operator.Parameters[actualName];
     90          param = (ItemParameter<T>)current.Operator.Parameters[actualName];
    9791        else
    9892          param = null;
     
    106100
    107101    public override IDeepCloneable Clone(Cloner cloner) {
    108       ItemParameter clone = (ItemParameter)base.Clone(cloner);
     102      ItemParameter<T> clone = (ItemParameter<T>)base.Clone(cloner);
    109103      clone.actualName = actualName;
    110       clone.Value = (IItem)cloner.Clone(value);
     104      clone.Value = (T)cloner.Clone(value);
    111105      return clone;
    112106    }
     
    133127    }
    134128  }
    135 
    136   [Item("ItemParameter<T>", "A generic parameter which represents an instance of type T.")]
    137   [EmptyStorableClass]
    138   public class ItemParameter<T> : ItemParameter where T : class, IItem {
    139     public new T Value {
    140       get { return (T)base.Value; }
    141       set { base.Value = value; }
    142     }
    143 
    144     public ItemParameter()
    145       : base("Anonymous", null, typeof(T)) {
    146       Value = null;
    147     }
    148     public ItemParameter(string name, string description)
    149       : base(name, description, typeof(T)) {
    150       this.Value = null;
    151     }
    152     public ItemParameter(string name, string description, T value)
    153       : base(name, description, typeof(T)) {
    154       this.Value = value;
    155     }
    156 
    157     public new T GetValue(ExecutionContext context) {
    158       return (T)base.GetValue(context);
    159     }
    160   }
    161129}
Note: See TracChangeset for help on using the changeset viewer.