1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Communication.Data;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Communication.Operators {
|
---|
9 | public class CurrentStateInitializer : OperatorBase {
|
---|
10 | public override string Description {
|
---|
11 | get { return @"TODO\r\nOperator description still missing ..."; }
|
---|
12 | }
|
---|
13 |
|
---|
14 | public CurrentStateInitializer()
|
---|
15 | : base() {
|
---|
16 | AddVariableInfo(new VariableInfo("Protocol", "", typeof(Protocol), VariableKind.In));
|
---|
17 | AddVariableInfo(new VariableInfo("CurrentState", "", typeof(ProtocolState), VariableKind.New | VariableKind.Out));
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override IOperation Apply(IScope scope) {
|
---|
21 | Protocol p = GetVariableValue<Protocol>("Protocol", scope, true);
|
---|
22 | ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true, false);
|
---|
23 | IVariableInfo info = GetVariableInfo("CurrentState");
|
---|
24 | string actualName = "";
|
---|
25 | if (!info.Local)
|
---|
26 | actualName = scope.TranslateName(info.FormalName);
|
---|
27 | if (currentState == null) {
|
---|
28 | currentState = p.InitialState;
|
---|
29 | if (info.Local)
|
---|
30 | AddVariable(new Variable(info.ActualName, currentState));
|
---|
31 | else
|
---|
32 | scope.AddVariable(new Variable(actualName, currentState));
|
---|
33 | } else {
|
---|
34 | currentState = p.InitialState;
|
---|
35 | if (info.Local) {
|
---|
36 | if (GetVariable(info.ActualName) == null) AddVariable(new Variable(info.ActualName, currentState));
|
---|
37 | else GetVariable(info.ActualName).Value = currentState;
|
---|
38 | } else {
|
---|
39 | if (scope.GetVariable(actualName) == null) scope.AddVariable(new Variable(actualName, currentState));
|
---|
40 | else scope.GetVariable(actualName).Value = currentState;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | return null;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|