Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Operators/SubScopeMessageDecomposer.cs @ 1027

Last change on this file since 1027 was 704, checked in by abeham, 16 years ago

[TICKET #297] communication restructuring

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using HeuristicLab.Core;
5using HeuristicLab.Communication.Data;
6
7namespace 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.