Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Parameters/3.3/Parameter.cs @ 9793

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

Merged cloning refactoring branch back into trunk (#922)

File size: 3.4 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 System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Parameters {
29  /// <summary>
30  /// A base class for parameters.
31  /// </summary>
32  [Item("Parameter", "A base class for parameters.")]
33  [StorableClass]
34  public abstract class Parameter : NamedItem, IParameter {
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    }
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    }
55    protected IItem cachedActualValue;
56    public IItem ActualValue {
57      get {
58        if (cachedActualValue == null) cachedActualValue = GetActualValue();
59        return cachedActualValue;
60      }
61      set {
62        cachedActualValue = value;
63        SetActualValue(value);
64      }
65    }
66    [Storable]
67    private IExecutionContext executionContext;
68    public IExecutionContext ExecutionContext {
69      get { return executionContext; }
70      set {
71        if (value != executionContext) {
72          executionContext = value;
73          cachedActualValue = null;
74          OnExecutionContextChanged();
75        }
76      }
77    }
78
79    [StorableConstructor]
80    protected Parameter(bool deserializing) : base(deserializing) { }
81    protected Parameter(Parameter original, Cloner cloner)
82      : base(original, cloner) {
83      dataType = original.dataType;
84      executionContext = cloner.Clone(original.executionContext);
85    }
86    protected Parameter()
87      : base("Anonymous") {
88      dataType = typeof(IItem);
89    }
90    protected Parameter(string name, Type dataType)
91      : base(name) {
92      if (dataType == null) throw new ArgumentNullException();
93      this.dataType = dataType;
94    }
95    protected Parameter(string name, string description, Type dataType)
96      : base(name, description) {
97      if (dataType == null) throw new ArgumentNullException();
98      this.dataType = dataType;
99    }
100
101    public override string ToString() {
102      return Name;
103    }
104
105    protected abstract IItem GetActualValue();
106    protected abstract void SetActualValue(IItem value);
107
108    protected virtual void OnExecutionContextChanged() { }
109  }
110}
Note: See TracBrowser for help on using the repository browser.