[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 |
|
---|
| 22 | using System;
|
---|
[3376] | 23 | using HeuristicLab.Common;
|
---|
[2653] | 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Core {
|
---|
[3017] | 27 | [StorableClass]
|
---|
[3385] | 28 | public sealed class ExecutionContext : DeepCloneable, IExecutionContext, IAtomicOperation {
|
---|
[2653] | 29 | [Storable]
|
---|
[2834] | 30 | private IParameterizedItem parameterizedItem;
|
---|
| 31 |
|
---|
| 32 | [Storable]
|
---|
| 33 | private IExecutionContext parent;
|
---|
| 34 | public IExecutionContext Parent {
|
---|
[2653] | 35 | get { return parent; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[3393] | 38 | public IKeyedItemCollection<string, IParameter> Parameters {
|
---|
[2834] | 39 | get { return parameterizedItem.Parameters; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[2653] | 42 | public IOperator Operator {
|
---|
[2834] | 43 | get { return parameterizedItem as IOperator; }
|
---|
[2653] | 44 | }
|
---|
| 45 |
|
---|
| 46 | [Storable]
|
---|
[2687] | 47 | private IScope scope;
|
---|
| 48 | public IScope Scope {
|
---|
[2653] | 49 | get { return scope; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private ExecutionContext() {
|
---|
| 53 | parent = null;
|
---|
[2834] | 54 | parameterizedItem = null;
|
---|
[2653] | 55 | scope = null;
|
---|
| 56 | }
|
---|
[2834] | 57 | public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) {
|
---|
| 58 | if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException();
|
---|
[2653] | 59 | this.parent = parent;
|
---|
[2834] | 60 | this.parameterizedItem = parameterizedItem;
|
---|
[2653] | 61 | this.scope = scope;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[3385] | 64 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[2653] | 65 | ExecutionContext clone = new ExecutionContext();
|
---|
| 66 | cloner.RegisterClonedObject(this, clone);
|
---|
[2834] | 67 | clone.parent = (IExecutionContext)cloner.Clone(parent);
|
---|
| 68 | clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
|
---|
[2687] | 69 | clone.scope = (IScope)cloner.Clone(scope);
|
---|
[2653] | 70 | return clone;
|
---|
| 71 | }
|
---|
[2796] | 72 |
|
---|
[2834] | 73 | public IAtomicOperation CreateOperation(IOperator op) {
|
---|
| 74 | return new ExecutionContext(parent, op, scope);
|
---|
[2796] | 75 | }
|
---|
[2834] | 76 | public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
|
---|
| 77 | return new ExecutionContext(parent, op, scope);
|
---|
[2796] | 78 | }
|
---|
[2834] | 79 | public IAtomicOperation CreateChildOperation(IOperator op) {
|
---|
| 80 | return new ExecutionContext(this, op, scope);
|
---|
[2796] | 81 | }
|
---|
[2834] | 82 | public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
|
---|
| 83 | return new ExecutionContext(this, op, scope);
|
---|
[2796] | 84 | }
|
---|
[2653] | 85 | }
|
---|
| 86 | }
|
---|