[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;
|
---|
[3136] | 23 | using System.Drawing;
|
---|
[2818] | 24 | using HeuristicLab.Common;
|
---|
[2714] | 25 | using HeuristicLab.Core;
|
---|
[2653] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
[2714] | 28 | namespace HeuristicLab.Parameters {
|
---|
[2653] | 29 | /// <summary>
|
---|
[2740] | 30 | /// A base class for parameters.
|
---|
[2653] | 31 | /// </summary>
|
---|
[2664] | 32 | [Item("Parameter", "A base class for parameters.")]
|
---|
[3017] | 33 | [StorableClass]
|
---|
[2664] | 34 | public abstract class Parameter : NamedItem, IParameter {
|
---|
[3136] | 35 | public override Image ItemImage {
|
---|
| 36 | get {
|
---|
| 37 | if ((dataType != null) && (typeof(IOperator).IsAssignableFrom(dataType)))
|
---|
| 38 | return HeuristicLab.Common.Resources.VS2008ImageLibrary.Method;
|
---|
| 39 | else
|
---|
| 40 | return base.ItemImage;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
[2653] | 43 | public override bool CanChangeName {
|
---|
| 44 | get { return false; }
|
---|
| 45 | }
|
---|
| 46 | public override bool CanChangeDescription {
|
---|
| 47 | get { return false; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | [Storable]
|
---|
| 51 | private Type dataType;
|
---|
| 52 | public Type DataType {
|
---|
| 53 | get { return dataType; }
|
---|
| 54 | }
|
---|
[2987] | 55 | protected IItem cachedActualValue;
|
---|
[2757] | 56 | public IItem ActualValue {
|
---|
[2987] | 57 | get {
|
---|
| 58 | if (cachedActualValue == null) cachedActualValue = GetActualValue();
|
---|
| 59 | return cachedActualValue;
|
---|
| 60 | }
|
---|
| 61 | set {
|
---|
| 62 | cachedActualValue = value;
|
---|
| 63 | SetActualValue(value);
|
---|
| 64 | }
|
---|
[2757] | 65 | }
|
---|
[2740] | 66 | [Storable]
|
---|
[2834] | 67 | private IExecutionContext executionContext;
|
---|
| 68 | public IExecutionContext ExecutionContext {
|
---|
[2740] | 69 | get { return executionContext; }
|
---|
[2757] | 70 | set {
|
---|
| 71 | if (value != executionContext) {
|
---|
| 72 | executionContext = value;
|
---|
[2987] | 73 | cachedActualValue = null;
|
---|
[2757] | 74 | OnExecutionContextChanged();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
[2740] | 77 | }
|
---|
[2653] | 78 |
|
---|
[2664] | 79 | protected Parameter()
|
---|
[2653] | 80 | : base("Anonymous") {
|
---|
| 81 | dataType = typeof(IItem);
|
---|
| 82 | }
|
---|
[2756] | 83 | protected Parameter(string name, Type dataType)
|
---|
| 84 | : base(name) {
|
---|
| 85 | if (dataType == null) throw new ArgumentNullException();
|
---|
| 86 | this.dataType = dataType;
|
---|
| 87 | }
|
---|
[2664] | 88 | protected Parameter(string name, string description, Type dataType)
|
---|
[2653] | 89 | : base(name, description) {
|
---|
| 90 | if (dataType == null) throw new ArgumentNullException();
|
---|
| 91 | this.dataType = dataType;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[2664] | 95 | Parameter clone = (Parameter)base.Clone(cloner);
|
---|
[2653] | 96 | clone.dataType = dataType;
|
---|
[2834] | 97 | clone.executionContext = (IExecutionContext)cloner.Clone(executionContext);
|
---|
[2653] | 98 | return clone;
|
---|
| 99 | }
|
---|
[2669] | 100 |
|
---|
| 101 | public override string ToString() {
|
---|
[2818] | 102 | return string.Format("{0} ({1})", Name, DataType.GetPrettyName());
|
---|
[2669] | 103 | }
|
---|
[2757] | 104 |
|
---|
| 105 | protected abstract IItem GetActualValue();
|
---|
| 106 | protected abstract void SetActualValue(IItem value);
|
---|
| 107 |
|
---|
| 108 | protected virtual void OnExecutionContextChanged() { }
|
---|
[2653] | 109 | }
|
---|
| 110 | }
|
---|