Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators/DelegatingOperator.cs @ 89

Last change on this file since 89 was 89, checked in by gkronber, 16 years ago

Moved abstract operator DelegatingOperator from StructureIdentification to Operators. And removed code duplication.
See ticket #55.

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6
7namespace HeuristicLab.Operators {
8  public abstract class DelegatingOperator : OperatorBase {
9    public override IOperation Execute(IScope scope) {
10      myCanceled = false;
11
12      if(scope.GetVariable(Guid.ToString()) == null) { // contained operator not yet executed
13        // add marker
14        scope.AddVariable(new Variable(Guid.ToString(), new NullData()));
15
16        // add aliases
17        foreach(IVariableInfo variableInfo in VariableInfos)
18          scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);
19
20        CompositeOperation next = new CompositeOperation();
21        next.AddOperation(Apply(scope));
22        // execute combined operator again after contained operators have been executed
23        next.AddOperation(new AtomicOperation(this, scope));
24
25        OnExecuted();
26        return next;
27      } else {  // contained operator already executed
28        // remove marker
29        scope.RemoveVariable(Guid.ToString());
30
31        // remove aliases
32        foreach(IVariableInfo variableInfo in VariableInfos)
33          scope.RemoveAlias(variableInfo.FormalName);
34
35        OnExecuted();
36        return null;
37      }
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.