Changeset 2027 for branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ComparatorBase.cs
- Timestamp:
- 06/06/09 02:09:35 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ComparatorBase.cs
r1530 r2027 36 36 /// </summary> 37 37 protected ComparatorBase() { 38 Add VariableInfo(new VariableInfo("LeftSide", "Variable on the left side of the comparison", typeof(IItem), VariableKind.In));39 Add VariableInfo(new VariableInfo("RightSide", "Variable on the right side of the comparison", typeof(IItem), VariableKind.In));40 Add VariableInfo(new VariableInfo("Result", "Result of the comparison", typeof(BoolData), VariableKind.Out | VariableKind.New));38 AddParameter(new Parameter("LeftSide", "Variable on the left side of the comparison", typeof(IItem), ParameterType.In)); 39 AddParameter(new Parameter("RightSide", "Variable on the right side of the comparison", typeof(IItem), ParameterType.In)); 40 AddParameter(new Parameter("Result", "Result of the comparison", typeof(BoolData), ParameterType.Out)); 41 41 } 42 42 … … 50 50 /// <param name="scope">The scope where to apply the compare operation.</param> 51 51 /// <returns><c>null</c>.</returns> 52 public override IOperation Apply(IScope scope) { 53 BoolData result = GetVariableValue<BoolData>("Result", scope, false, false); 52 public override IOperation Apply(IEnvironment env, IScope scope) { 53 string resultName = env.TranslateName("Result"); 54 BoolData result = scope.GetVariableValue<BoolData>(resultName, false, false); 54 55 if (result == null) { 55 56 result = new BoolData(true); 56 IVariableInfo info = GetVariableInfo("Result"); 57 if (info.Local) 58 AddVariable(new Variable(info.ActualName, result)); 59 else 60 scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), result)); 57 scope.AddVariable(new Variable(resultName, result)); 61 58 } 62 IItem leftSide = GetVariableValue<IItem>("LeftSide", scope, true);59 IItem leftSide = scope.GetVariableValue<IItem>(env.TranslateName("LeftSide"), true); 63 60 if (!(leftSide is IComparable)) throw new InvalidOperationException("Comparator: Left side needs to be of type IComparable"); 64 61 IComparable left = (IComparable)leftSide; 65 IItem rightSide = GetVariableValue<IItem>("RightSide", scope, true);62 IItem rightSide = scope.GetVariableValue<IItem>(env.TranslateName("RightSide"), true); 66 63 result.Data = Compare(left, rightSide); 67 64 return null;
Note: See TracChangeset
for help on using the changeset viewer.