Free cookie consent management tool by TermsFeed Policy Generator

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

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

fixing SubScopeMessageDecomposer (#538)

File size: 1.3 KB
RevLine 
[704]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);
[1411]22      if (message.Give.Count > scope.SubScopes.Count) throw new InvalidOperationException("ERROR in SubScopeMessageDecomposer: There are not enough subscopes to put the contents of the message into");
[704]23      int i = 0;
[1207]24      foreach (IVariable var in message.Give) {
[704]25        scope.SubScopes[i].AddVariable(var);
[1411]26        i++;
[704]27      }
28      IVariableInfo info = GetVariableInfo("Message");
29      if (info.Local) {
30        RemoveVariable(info.ActualName);
31      } else {
32        scope.RemoveVariable(scope.TranslateName(info.FormalName));
33      }
34      return null;
35    }
36  }
37}
Note: See TracBrowser for help on using the repository browser.