[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;
|
---|
[2834] | 23 | using HeuristicLab.Collections;
|
---|
[3376] | 24 | using HeuristicLab.Common;
|
---|
[2653] | 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Core {
|
---|
[3017] | 28 | [StorableClass]
|
---|
[3385] | 29 | public sealed class ExecutionContext : DeepCloneable, 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 |
|
---|
[3393] | 39 | public IKeyedItemCollection<string, IParameter> Parameters {
|
---|
[2834] | 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 |
|
---|
[3385] | 65 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[2653] | 66 | ExecutionContext clone = new ExecutionContext();
|
---|
| 67 | cloner.RegisterClonedObject(this, clone);
|
---|
[2834] | 68 | clone.parent = (IExecutionContext)cloner.Clone(parent);
|
---|
| 69 | clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem);
|
---|
[2687] | 70 | clone.scope = (IScope)cloner.Clone(scope);
|
---|
[2653] | 71 | return clone;
|
---|
| 72 | }
|
---|
[2796] | 73 |
|
---|
[2834] | 74 | public IAtomicOperation CreateOperation(IOperator op) {
|
---|
| 75 | return new ExecutionContext(parent, op, scope);
|
---|
[2796] | 76 | }
|
---|
[2834] | 77 | public IAtomicOperation CreateOperation(IOperator op, IScope scope) {
|
---|
| 78 | return new ExecutionContext(parent, op, scope);
|
---|
[2796] | 79 | }
|
---|
[2834] | 80 | public IAtomicOperation CreateChildOperation(IOperator op) {
|
---|
| 81 | return new ExecutionContext(this, op, scope);
|
---|
[2796] | 82 | }
|
---|
[2834] | 83 | public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) {
|
---|
| 84 | return new ExecutionContext(this, op, scope);
|
---|
[2796] | 85 | }
|
---|
[2653] | 86 | }
|
---|
| 87 | }
|
---|