Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/ExecutionContext.cs @ 3623

Last change on this file since 3623 was 3393, checked in by swagner, 15 years ago

Changed items and views according to the refactoring of HeuristicLab.Collections (#977)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Collections;
24using HeuristicLab.Common;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Core {
28  [StorableClass]
29  public sealed class ExecutionContext : DeepCloneable, IExecutionContext, IAtomicOperation {
30    [Storable]
31    private IParameterizedItem parameterizedItem;
32
33    [Storable]
34    private IExecutionContext parent;
35    public IExecutionContext Parent {
36      get { return parent; }
37    }
38
39    public IKeyedItemCollection<string, IParameter> Parameters {
40      get { return parameterizedItem.Parameters; }
41    }
42
43    public IOperator Operator {
44      get { return parameterizedItem as IOperator; }
45    }
46
47    [Storable]
48    private IScope scope;
49    public IScope Scope {
50      get { return scope; }
51    }
52
53    private ExecutionContext() {
54      parent = null;
55      parameterizedItem = null;
56      scope = null;
57    }
58    public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) {
59      if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException();
60      this.parent = parent;
61      this.parameterizedItem = parameterizedItem;
62      this.scope = scope;
63    }
64
65    public override IDeepCloneable Clone(Cloner cloner) {
66      ExecutionContext clone = new ExecutionContext();
67      cloner.RegisterClonedObject(this, clone);
68      clone.parent = (IExecutionContext)cloner.Clone(parent);
69      clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
70      clone.scope = (IScope)cloner.Clone(scope);
71      return clone;
72    }
73
74    public IAtomicOperation CreateOperation(IOperator op) {
75      return new ExecutionContext(parent, op, scope);
76    }
77    public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
78      return new ExecutionContext(parent, op, scope);
79    }
80    public IAtomicOperation CreateChildOperation(IOperator op) {
81      return new ExecutionContext(this, op, scope);
82    }
83    public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
84      return new ExecutionContext(this, op, scope);
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.