#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 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.Collections.Generic;
using System.Text;
using System.Xml;
namespace HeuristicLab.Core {
///
/// Class for storing meta-information about variables/parameters of an operator.
///
public class VariableInfo : ItemBase, IVariableInfo {
private string myActualName;
///
/// Gets or sets the actual name of the current instance.
///
/// Calls in the setter.
public string ActualName {
get { return myActualName; }
set {
if (myActualName != value) {
myActualName = value;
OnActualNameChanged();
}
}
}
private string myFormalName;
///
/// Gets the formal name of the current instance.
///
public string FormalName {
get { return myFormalName; }
}
private string myDescription;
///
/// Gets the description of the current instance.
///
public string Description {
get { return myDescription; }
}
private Type myDataType;
///
/// Gets the data type of the parameter.
///
public Type DataType {
get { return myDataType; }
}
private VariableKind myKind;
///
/// Gets the kind of the parameter (input parameter, output parameter,...).
///
public VariableKind Kind {
get { return myKind; }
}
private bool myLocal;
///
/// Gets or sets a boolean value, whether the variable is a local one.
///
/// Calls in the setter.
public bool Local {
get { return myLocal; }
set {
if (myLocal != value) {
myLocal = value;
OnLocalChanged();
}
}
}
///
/// Initializes a new instance of with actual and formal name "Anonymous",
/// no description, a null data type and the local flag set to false. The type of
/// the variable is an input parameter.
///
public VariableInfo() {
myActualName = "Anonymous";
myFormalName = "Anonymous";
myDescription = "";
myDataType = null;
myKind = VariableKind.In;
myLocal = false;
}
///
/// Initializes a new instance of with the given parameters.
///
/// Calls .
/// The formal name is assigned to the actual name, too.
/// The formal name of the current instance.
/// The description of the current instance.
/// The data type of the parameter.
/// The type of the parameter.
public VariableInfo(string formalName, string description, Type dataType, VariableKind kind)
: this() {
myActualName = formalName;
myFormalName = formalName;
myDescription = description;
myDataType = dataType;
myKind = kind;
}
///
/// Creates a new instance of to represent the current instance
/// visually.
///
/// The created view as .
public override IView CreateView() {
return new VariableInfoView(this);
}
///
/// Clones the current instance (deep clone).
///
/// Dictionary of all already cloned objects. (Needed to avoid cycles.)
/// The cloned object as .
public override object Clone(IDictionary clonedObjects) {
VariableInfo clone = new VariableInfo();
clonedObjects.Add(Guid, clone);
clone.myActualName = ActualName;
clone.myFormalName = FormalName;
clone.myDescription = Description;
clone.myDataType = DataType;
clone.myKind = Kind;
clone.myLocal = Local;
return clone;
}
///
public event EventHandler ActualNameChanged;
///
/// Fires a new ActualNameChanged event.
///
protected virtual void OnActualNameChanged() {
if (ActualNameChanged != null)
ActualNameChanged(this, new EventArgs());
}
///
public event EventHandler LocalChanged;
///
/// Fires a new LocalChanged event.
///
protected virtual void OnLocalChanged() {
if (LocalChanged != null)
LocalChanged(this, new EventArgs());
}
#region Persistence Methods
///
/// Saves the current instance as in the specified .
///
/// Calls of base class .
/// A quick overview how the single elements of the current instance are saved:
///
/// -
/// Actual name:
/// Saved as with tag name ActualName.
///
/// -
/// Formal name:
/// Saves as with tag name FormalName.
///
/// -
/// Description:
/// Saved as with tag name Description.
///
/// - Data type:
/// Saved as with tag name DataType.
///
/// -
/// Kind:
/// Saved as with tag name Kind.
///
/// -
/// Local:
/// Saved as with tag name Local.
///
///
/// The (tag)name of the .
/// The where to save the data.
/// The dictionary of all already persisted objects. (Needed to avoid cycles.)
/// The saved .
public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary persistedObjects) {
XmlNode node = base.GetXmlNode(name, document, persistedObjects);
XmlAttribute actualNameAttribute = document.CreateAttribute("ActualName");
actualNameAttribute.Value = ActualName;
node.Attributes.Append(actualNameAttribute);
XmlAttribute formalNameAttribute = document.CreateAttribute("FormalName");
formalNameAttribute.Value = FormalName;
node.Attributes.Append(formalNameAttribute);
XmlAttribute descriptionAttribute = document.CreateAttribute("Description");
descriptionAttribute.Value = Description;
node.Attributes.Append(descriptionAttribute);
XmlAttribute dataTypeAttribute = document.CreateAttribute("DataType");
dataTypeAttribute.Value = PersistenceManager.BuildTypeString(DataType);
node.Attributes.Append(dataTypeAttribute);
XmlAttribute kindAttribute = document.CreateAttribute("Kind");
kindAttribute.Value = Kind.ToString();
node.Attributes.Append(kindAttribute);
XmlAttribute localAttribute = document.CreateAttribute("Local");
localAttribute.Value = Local.ToString();
node.Attributes.Append(localAttribute);
return node;
}
///
/// Loads the persisted variable info from the specified .
///
/// See for further information on how the variable info must be
/// saved.
/// Calls of base class .
/// The where the variable info is saved.
/// The dictionary of all already restored objects.
/// (Needed to avoid cycles.)
public override void Populate(XmlNode node, IDictionary restoredObjects) {
base.Populate(node, restoredObjects);
myActualName = node.Attributes["ActualName"].Value;
myFormalName = node.Attributes["FormalName"].Value;
myDescription = node.Attributes["Description"].Value;
myDataType = Type.GetType(node.Attributes["DataType"].Value, true);
myKind = (VariableKind)Enum.Parse(typeof(VariableKind), node.Attributes["Kind"].Value);
myLocal = bool.Parse(node.Attributes["Local"].Value);
}
#endregion
}
}