#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Drawing;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Parameters {
///
/// A base class for parameters.
///
[Item("Parameter", "A base class for parameters.")]
[StorableClass]
public abstract class Parameter : NamedItem, IParameter {
public override Image ItemImage {
get {
if ((dataType != null) && (typeof(IOperator).IsAssignableFrom(dataType)))
return HeuristicLab.Common.Resources.VS2008ImageLibrary.Method;
else
return base.ItemImage;
}
}
public override bool CanChangeName {
get { return false; }
}
public override bool CanChangeDescription {
get { return false; }
}
[Storable]
private Type dataType;
public Type DataType {
get { return dataType; }
}
protected IItem cachedActualValue;
public IItem ActualValue {
get {
if (cachedActualValue == null) cachedActualValue = GetActualValue();
return cachedActualValue;
}
set {
cachedActualValue = value;
SetActualValue(value);
}
}
[Storable]
private IExecutionContext executionContext;
public IExecutionContext ExecutionContext {
get { return executionContext; }
set {
if (value != executionContext) {
executionContext = value;
cachedActualValue = null;
OnExecutionContextChanged();
}
}
}
[StorableConstructor]
protected Parameter(bool deserializing) : base(deserializing) { }
protected Parameter(Parameter original, Cloner cloner)
: base(original, cloner) {
dataType = original.dataType;
executionContext = cloner.Clone(original.executionContext);
}
protected Parameter()
: base("Anonymous") {
dataType = typeof(IItem);
}
protected Parameter(string name, Type dataType)
: base(name) {
if (dataType == null) throw new ArgumentNullException();
this.dataType = dataType;
}
protected Parameter(string name, string description, Type dataType)
: base(name, description) {
if (dataType == null) throw new ArgumentNullException();
this.dataType = dataType;
}
public override string ToString() {
return Name;
}
protected abstract IItem GetActualValue();
protected abstract void SetActualValue(IItem value);
protected virtual void OnExecutionContextChanged() { }
}
}