Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Communication.Data;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Communication.Operators {
|
---|
8 | public class SubScopeMessageDecomposer : OperatorBase {
|
---|
9 | public override string Description {
|
---|
10 | get {
|
---|
11 | return @"Takes a message and extracts the contents into subscopes";
|
---|
12 | }
|
---|
13 | }
|
---|
14 |
|
---|
15 | public SubScopeMessageDecomposer()
|
---|
16 | : base() {
|
---|
17 | AddVariableInfo(new VariableInfo("Message", "The message to decompose", typeof(Message), VariableKind.In | VariableKind.Deleted));
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override IOperation Apply(IScope scope) {
|
---|
21 | Message message = GetVariableValue<Message>("Message", scope, false);
|
---|
22 | if (message.Expect.Count > scope.SubScopes.Count) throw new InvalidOperationException("ERROR in SubScopeMessageDecomposer: There are not enough subscopes to put the contents of the message into");
|
---|
23 | int i = 0;
|
---|
24 | foreach (IVariable var in message.Expect) {
|
---|
25 | scope.SubScopes[i].AddVariable(var);
|
---|
26 | }
|
---|
27 | IVariableInfo info = GetVariableInfo("Message");
|
---|
28 | if (info.Local) {
|
---|
29 | RemoveVariable(info.ActualName);
|
---|
30 | } else {
|
---|
31 | scope.RemoveVariable(scope.TranslateName(info.FormalName));
|
---|
32 | }
|
---|
33 | return null;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.