Changeset 2684 for trunk/sources/HeuristicLab.Operators/3.3/Counter.cs
- Timestamp:
- 01/26/10 05:14:51 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators/3.3/Counter.cs
r1530 r2684 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Operators { 29 30 /// <summary> 30 /// Class to increment an int variable by 1.31 /// Operator which increments an integer variable. 31 32 /// </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"]; } 38 42 } 39 43 40 /// <summary>41 /// Initializes a new instance of <see cref="Counter"/> with one variable info (<c>Value</c>).42 /// </summary>43 44 public Counter() 44 45 : 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))); 46 48 } 47 49 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); 57 55 } 58 56 }
Note: See TracChangeset
for help on using the changeset viewer.