Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Core/3.3/ExecutionContext.cs @ 17656

Last change on this file since 17656 was 17254, checked in by abeham, 5 years ago

#2521: Added context lookup parameter

  • Refactored tests
  • Fixed duplicate GUID
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HEAL.Attic;
24using HeuristicLab.Common;
25
26namespace HeuristicLab.Core {
27  [StorableType("83851945-1115-4C08-BD46-318A1FFC54E2")]
28  public sealed class ExecutionContext : DeepCloneable, IExecutionContext, IAtomicOperation {
29    [Storable]
30    private IParameterizedItem parameterizedItem;
31
32    [Storable]
33    private IExecutionContext parent;
34    public IExecutionContext Parent {
35      get { return parent; }
36    }
37
38    public IKeyedItemCollection<string, IParameter> Parameters {
39      get { return parameterizedItem.Parameters; }
40    }
41
42    public IParameterizedItem Item => parameterizedItem;
43
44    public IOperator Operator {
45      get { return parameterizedItem as IOperator; }
46    }
47
48    [Storable]
49    private IScope scope;
50    public IScope Scope {
51      get { return scope; }
52    }
53
54    [StorableConstructor]
55    private ExecutionContext(StorableConstructorFlag _) { }
56    private ExecutionContext(ExecutionContext original, Cloner cloner)
57      : base(original, cloner) {
58      parent = cloner.Clone(original.parent);
59      parameterizedItem = cloner.Clone(original.parameterizedItem);
60      scope = cloner.Clone(original.scope);
61    }
62    private ExecutionContext() {
63      parent = null;
64      parameterizedItem = null;
65      scope = null;
66    }
67    public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) {
68      if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException();
69      this.parent = parent;
70      this.parameterizedItem = parameterizedItem;
71      this.scope = scope;
72    }
73
74    public override IDeepCloneable Clone(Cloner cloner) {
75      return new ExecutionContext(this, cloner);
76    }
77
78    public IAtomicOperation CreateOperation(IOperator op) {
79      return new ExecutionContext(parent, op, scope);
80    }
81    public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
82      return new ExecutionContext(parent, op, scope);
83    }
84    public IAtomicOperation CreateChildOperation(IOperator op) {
85      return new ExecutionContext(this, op, scope);
86    }
87    public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
88      return new ExecutionContext(this, op, scope);
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.