Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3376 was 3376, checked in by swagner, 14 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

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