Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/10 05:14:51 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • continued work on adapting and refactoring HeuristicLab.Data according to the changes in HeuristicLab.Core
  • started work on adapting and refactoring HeuristicLab.Operators according to changes in HeuristicLab.Core
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r1530 r2684  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Operators {
    2930  /// <summary>
    30   /// Class to increment an int variable by 1.
     31  /// Operator which increments an integer variable.
    3132  /// </summary>
    32   public class Counter : OperatorBase {
    33     /// <summary>
    34     /// Gets the description of the current instance.
    35     /// </summary>
    36     public override string Description {
    37       get { return @"TODO\r\nOperator description still missing ..."; }
     33  [Item("Counter", "An operator which increments an integer variable.")]
     34  [EmptyStorableClass]
     35  [Creatable("Test")]
     36  public sealed class Counter : StandardOperator {
     37    public ItemParameter<IntData> Value {
     38      get { return (ItemParameter<IntData>)Parameters["Value"]; }
     39    }
     40    public ItemParameter<IntData> Increment {
     41      get { return (ItemParameter<IntData>)Parameters["Increment"]; }
    3842    }
    3943
    40     /// <summary>
    41     /// Initializes a new instance of <see cref="Counter"/> with one variable info (<c>Value</c>).
    42     /// </summary>
    4344    public Counter()
    4445      : base() {
    45       AddVariableInfo(new VariableInfo("Value", "Counter value", typeof(IntData), VariableKind.In | VariableKind.Out));
     46      Parameters.Add(new ItemParameter<IntData>("Value", "The value which should be incremented."));
     47      Parameters.Add(new ItemParameter<IntData>("Increment", "The increment which is added to the value.", new IntData(1)));
    4648    }
    4749
    48     /// <summary>
    49     /// Increments an int value of the specified <paramref name="scope"/> by one.
    50     /// </summary>
    51     /// <param name="scope">The scope whose variable should be incremented.</param>
    52     /// <returns><c>null</c>.</returns>
    53     public override IOperation Apply(IScope scope) {
    54       IntData value = GetVariableValue<IntData>("Value", scope, true);
    55       value.Data++;
    56       return null;
     50    public override ExecutionContextCollection Apply(ExecutionContext context) {
     51      IntData value = Value.GetValue(context);
     52      IntData increment = Increment.GetValue(context);
     53      value.Value += increment.Value;
     54      return base.Apply(context);
    5755    }
    5856  }
Note: See TracChangeset for help on using the changeset viewer.