Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3007 was 2994, checked in by epitzer, 15 years ago

Make StorableClass attribute compulsory for StorableSerializer to work, add named property StorableClassType to choose between Empty and MarkedOnly, later other options will be added. (#548)

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.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Core {
27  [StorableClass(StorableClassType.MarkedOnly)]
28  public 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 IObservableKeyedCollection<string, IParameter> Parameters {
39      get { return parameterizedItem.Parameters; }
40    }
41
42    public IOperator Operator {
43      get { return parameterizedItem as IOperator; }
44    }
45
46    [Storable]
47    private IScope scope;
48    public IScope Scope {
49      get { return scope; }
50    }
51
52    private ExecutionContext() {
53      parent = null;
54      parameterizedItem = null;
55      scope = null;
56    }
57    public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) {
58      if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException();
59      this.parent = parent;
60      this.parameterizedItem = parameterizedItem;
61      this.scope = scope;
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      ExecutionContext clone = new ExecutionContext();
66      cloner.RegisterClonedObject(this, clone);
67      clone.parent = (IExecutionContext)cloner.Clone(parent);
68      clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
69      clone.scope = (IScope)cloner.Clone(scope);
70      return clone;
71    }
72
73    public IAtomicOperation CreateOperation(IOperator op) {
74      return new ExecutionContext(parent, op, scope);
75    }
76    public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
77      return new ExecutionContext(parent, op, scope);
78    }
79    public IAtomicOperation CreateChildOperation(IOperator op) {
80      return new ExecutionContext(this, op, scope);
81    }
82    public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
83      return new ExecutionContext(this, op, scope);
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.