Free cookie consent management tool by TermsFeed Policy Generator

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

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

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

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.Give.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.Give) {
25        scope.SubScopes[i].AddVariable(var);
26        i++;
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.