Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2931 was 2834, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • worked on operators, engines, and optimization
File size: 2.9 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  public class ExecutionContext : DeepCloneable, IExecutionContext, IAtomicOperation {
28    [Storable]
29    private IParameterizedItem parameterizedItem;
30
31    [Storable]
32    private IExecutionContext parent;
33    public IExecutionContext Parent {
34      get { return parent; }
35    }
36
37    public IObservableKeyedCollection<string, IParameter> Parameters {
38      get { return parameterizedItem.Parameters; }
39    }
40
41    public IOperator Operator {
42      get { return parameterizedItem as IOperator; }
43    }
44
45    [Storable]
46    private IScope scope;
47    public IScope Scope {
48      get { return scope; }
49    }
50
51    private ExecutionContext() {
52      parent = null;
53      parameterizedItem = null;
54      scope = null;
55    }
56    public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) {
57      if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException();
58      this.parent = parent;
59      this.parameterizedItem = parameterizedItem;
60      this.scope = scope;
61    }
62
63    public override IDeepCloneable Clone(Cloner cloner) {
64      ExecutionContext clone = new ExecutionContext();
65      cloner.RegisterClonedObject(this, clone);
66      clone.parent = (IExecutionContext)cloner.Clone(parent);
67      clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
68      clone.scope = (IScope)cloner.Clone(scope);
69      return clone;
70    }
71
72    public IAtomicOperation CreateOperation(IOperator op) {
73      return new ExecutionContext(parent, op, scope);
74    }
75    public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
76      return new ExecutionContext(parent, op, scope);
77    }
78    public IAtomicOperation CreateChildOperation(IOperator op) {
79      return new ExecutionContext(this, op, scope);
80    }
81    public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
82      return new ExecutionContext(this, op, scope);
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.