Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2030


Ignore:
Timestamp:
06/08/09 02:02:21 (15 years ago)
Author:
swagner
Message:

Refactoring of the Operator Architecture (#95)

Location:
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IParameter.cs

    r1994 r2030  
    2727namespace HeuristicLab.Core {
    2828  /// <summary>
    29   /// Interface to store meta-information about parameters of operators.
     29  /// Interface to represent parameters of operators.
    3030  /// </summary>
    3131  public interface IParameter : IItem {
    3232    /// <summary>
    33     /// Gets or sets the name of the current instance.
     33    /// Gets or sets the actual name of the parameter.
    3434    /// </summary>
    35     string Name { get; }
     35    string ActualName { get; set; }
    3636    /// <summary>
    37     /// Gets the description of the current instance.
     37    /// Gets or sets the formal name of the parameter.
    3838    /// </summary>
    39     string Description { get; }
     39    string FormalName { get; }
     40    /// <summary>
     41    /// Gets or sets the description of the current instance.
     42    /// </summary>
     43    string Description { get; set; }
    4044    /// <summary>
    4145    /// Gets the data type of the current instance.
     
    4650    /// </summary>
    4751    ParameterType Type { get; }
     52    /// <summary>
     53    /// Gets or sets, if the parameter is constant (only valid for input parameters).
     54    /// </summary>
     55    bool Constant { get; set; }
     56    /// <summary>
     57    /// Gets or sets, if the parameter should be cached by operators.
     58    /// </summary>
     59    bool Cached { get; set; }
     60    /// <summary>
     61    /// Gets or sets the value of the parameter.
     62    /// </summary>
     63    IItem Value { get; set; }
     64
     65    /// <summary>
     66    /// Occurs when the actual name of the current instance has been changed.
     67    /// </summary>
     68    event EventHandler ActualNameChanged;
     69    /// <summary>
     70    /// Occurs when the description of the current instance has been changed.
     71    /// </summary>
     72    event EventHandler DescriptionChanged;
     73    /// <summary>
     74    /// Occurs when the constant flag of the current instance has been changed.
     75    /// </summary>
     76    event EventHandler ConstantChanged;
     77    /// <summary>
     78    /// Occurs when the cached flag of the current instance has been changed.
     79    /// </summary>
     80    event EventHandler CachedChanged;
     81    /// <summary>
     82    /// Occurs when the value of the current instance has been changed.
     83    /// </summary>
     84    event EventHandler ValueChanged;
     85
     86  }
     87
     88  /// <summary>
     89  /// Generic interface to represent parameters of operators.
     90  /// </summary>
     91  /// <typeparam name="T">The data type of the parameter, which has to be an <see cref="IItem"/>.</typeparam>
     92  public interface IParamter<T> : IParameter where T : class, IItem {
     93    /// <summary>
     94    /// Gets or sets the value of the parameter.
     95    /// </summary>
     96    T Value { get; set; }
    4897  }
    4998}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Parameter.cs

    r2027 r2030  
    2727namespace HeuristicLab.Core {
    2828  /// <summary>
    29   /// Class for storing meta-information about parameters of an operator.
     29  /// Represents a parameter of an operator.
    3030  /// </summary>
    31   public class Parameter : ItemBase, IParameter {
    32     private string myName;
    33     /// <summary>
    34     /// Gets or sets the name of the current instance.
     31  /// <typeparam name="T">The data type of the parameter, which has to be an <see cref="IItem"/>.</typeparam>
     32  public class Parameter<T> : ItemBase, IParameter, IParamter<T> where T : class, IItem {
     33    private string myActualName;
     34    /// <summary>
     35    /// Gets or sets the actual name of the current instance.
    3536    /// </summary>
    3637    /// <remarks>Calls <see cref="OnActualNameChanged"/> in the setter.</remarks>
    37     public string Name {
    38       get { return myName; }
     38    public string ActualName {
     39      get { return myActualName; }
     40      set {
     41        if (! myActualName.Equals(value)) {
     42          myActualName = value;
     43          OnActualNameChanged();
     44        }
     45      }
     46    }
     47    private string myFormalName;
     48    /// <summary>
     49    /// Gets the formal name of the current instance.
     50    /// </summary>
     51    public string FormalName {
     52      get { return myFormalName; }
    3953    }
    4054    private string myDescription;
    4155    /// <summary>
    42     /// Gets the description of the current instance.
    43     /// </summary>
     56    /// Gets or sets the description of the current instance.
     57    /// </summary>
     58    /// <remarks>Calls <see cref="OnDescriptionChanged"/> in the setter.</remarks>
    4459    public string Description {
    4560      get { return myDescription; }
    46     }
    47     private Type myDataType;
     61      set {
     62        if (! myDescription.Equals(value)) {
     63          myDescription = value;
     64          OnDescriptionChanged();
     65        }
     66      }
     67    }
    4868    /// <summary>
    4969    /// Gets the data type of the parameter.
    5070    /// </summary>
    5171    public Type DataType {
    52       get { return myDataType; }
     72      get { return typeof(T); }
    5373    }
    5474    private ParameterType myType;
     
    5878    public ParameterType Type {
    5979      get { return myType; }
     80    }
     81    private bool myConstant;
     82    /// <summary>
     83    /// Gets or sets, if the parameter is constant (only valid for input parameters).
     84    /// </summary>
     85    /// <remarks>Calls <see cref="OnConstantChanged"/> in the setter.</remarks>
     86    public bool Constant {
     87      get { return myConstant; }
     88      set {
     89        if (Type != ParameterType.In) throw new InvalidOperationException("only input parameters can be constant");
     90        if (myConstant != value) {
     91          myConstant = value;
     92          OnConstantChanged();
     93        }
     94      }
     95    }
     96    private bool myCached;
     97    /// <summary>
     98    /// Gets or sets, if the parameter should be cached by operators.
     99    /// </summary>
     100    /// <remarks>Calls <see cref="OnCachedChanged"/> in the setter.</remarks>
     101    public bool Cached {
     102      get { return myCached; }
     103      set {
     104        if (myCached != value) {
     105          myCached = value;
     106          OnCachedChanged();
     107        }
     108      }
     109    }
     110    private T myValue;
     111    /// <summary>
     112    /// Gets or sets the value of the parameter.
     113    /// </summary>
     114    public T Value {
     115      get { return myValue; }
     116      set {
     117        if (! myValue.Equals(value)) {
     118          myValue = value;
     119          OnValueChanged();
     120        }
     121      }
     122    }
     123    /// <summary>
     124    /// Gets or sets the value of the parameter.
     125    /// </summary>
     126    public IItem IParameter.Value {
     127      get { return myValue; }
     128      set { Value = (T)value; }
    60129    }
    61130
     
    66135    /// </summary>
    67136    public Parameter() {
    68       myName = "Anonymous";
     137      myActualName = "Anonymous";
     138      myFormalName = "Anonymous";
    69139      myDescription = "";
    70       myDataType = null;
    71140      myType = ParameterType.In;
     141      myConstant = false;
     142      myCached = false;
     143      myValue = null;
    72144    }
    73145    /// <summary>
    74146    /// Initializes a new instance of <see cref="Parameter"/> with the given parameters.
    75147    /// </summary>
    76     /// <remarks>Calls <see cref="Parameter()"/>.</remarks>
    77     /// <param name="name">The name of the current instance.</param>
     148    /// <remarks>Calls <see cref="Parameter()"/>.<br/>
     149    /// The formal name is assigned to the actual name, too.</remarks>
     150    /// <param name="formalName">The formal name of the current instance.</param>
    78151    /// <param name="description">The description of the current instance.</param>
    79     /// <param name="dataType">The data type of the parameter.</param>
    80     /// <param name="type">The type of the parameter.</param>
    81     public Parameter(string name, string description, Type dataType, ParameterType type)
     152    /// <param name="kind">The type of the parameter.</param>
     153    public Parameter(string formalName, string description, ParameterType type, bool constant, bool cached)
    82154      : this() {
    83       myName = name;
     155      myActualName = formalName;
     156      myFormalName = formalName;
    84157      myDescription = description;
    85       myDataType = dataType;
    86158      myType = type;
     159      myConstant = constant;
     160      myCached = cached;
    87161    }
    88162
     
    102176    /// <returns>The cloned object as <see cref="Parameter"/>.</returns>
    103177    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    104       Parameter clone = new Parameter();
     178      Parameter<T> clone = (Parameter<T>)base.Clone(clonedObjects);
    105179      clonedObjects.Add(Guid, clone);
    106       clone.myName = Name;
     180      clone.myActualName = ActualName;
     181      clone.myFormalName = FormalName;
    107182      clone.myDescription = Description;
    108       clone.myDataType = DataType;
    109183      clone.myType = Type;
     184      clone.myConstant = Constant;
     185      clone.myCached = Cached;
     186      clone.myValue = (T)Auxiliary.Clone(Value, clonedObjects);
    110187      return clone;
     188    }
     189
     190    /// <inheritdoc/>
     191    public event EventHandler ActualNameChanged;
     192    /// <summary>
     193    /// Fires a new <c>ActualNameChanged</c> event.
     194    /// </summary>
     195    protected virtual void OnActualNameChanged() {
     196      if (ActualNameChanged != null)
     197        ActualNameChanged(this, new EventArgs());
     198    }
     199    /// <inheritdoc />
     200    public event EventHandler DescriptionChanged;
     201    /// <summary>
     202    /// Fires a new <c>DescriptionChanged</c> event.
     203    /// </summary>
     204    protected virtual void OnDescriptionChanged() {
     205      if (DescriptionChanged != null)
     206        DescriptionChanged(this, new EventArgs());
     207    }
     208    public event EventHandler ConstantChanged;
     209    /// <summary>
     210    /// Fires a new <c>ConstantChanged</c> event.
     211    /// </summary>
     212    protected virtual void OnConstantChanged() {
     213      if (ConstantChanged != null)
     214        ConstantChanged(this, new EventArgs());
     215    }
     216    public event EventHandler CachedChanged;
     217    /// <summary>
     218    /// Fires a new <c>CachedChanged</c> event.
     219    /// </summary>
     220    protected virtual void OnCachedChanged() {
     221      if (CachedChanged != null)
     222        CachedChanged(this, new EventArgs());
     223    }
     224    public event EventHandler ValueChanged;
     225    /// <summary>
     226    /// Fires a new <c>ValueChanged</c> event.
     227    /// </summary>
     228    protected virtual void OnValueChanged() {
     229      if (ValueChanged != null)
     230        ValueChanged(this, new EventArgs());
    111231    }
    112232
     
    119239    /// <list type="bullet">
    120240    /// <item>
    121     /// <term>Name: </term>
    122     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Name</c>.</description>
     241    /// <term>ActualName: </term>
     242    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>ActualName</c>.</description>
     243    /// </item>
     244    /// <item>
     245    /// <term>FormalName: </term>
     246    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>FormalName</c>.</description>
    123247    /// </item>
    124248    /// <item>
     
    126250    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Description</c>.</description>
    127251    /// </item>
    128     /// <item><term>Data type: </term>
    129     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>DataType</c>.</description>
    130     /// </item>
    131252    /// <item>
    132253    /// <term>Type: </term>
    133254    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>ParameterType</c>.</description>
     255    /// </item>
     256    /// <item>
     257    /// <term>Constant: </term>
     258    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Constant</c>.</description>
     259    /// </item>
     260    /// <item>
     261    /// <term>Cached: </term>
     262    /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Cached</c>.</description>
     263    /// </item>
     264    /// <item>
     265    /// <term>Value: </term>
     266    /// <description>Saved as child node with tag name <c>Value</c>.</description>
    134267    /// </item>
    135268    /// </list></remarks>
     
    140273    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    141274      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    142       XmlAttribute nameAttribute = document.CreateAttribute("Name");
    143       nameAttribute.Value = Name;
    144       node.Attributes.Append(nameAttribute);
     275      XmlAttribute actualNameAttribute = document.CreateAttribute("ActualName");
     276      actualNameAttribute.Value = ActualName;
     277      node.Attributes.Append(actualNameAttribute);
     278
     279      XmlAttribute formalNameAttribute = document.CreateAttribute("FormalName");
     280      formalNameAttribute.Value = FormalName;
     281      node.Attributes.Append(formalNameAttribute);
    145282
    146283      XmlAttribute descriptionAttribute = document.CreateAttribute("Description");
     
    148285      node.Attributes.Append(descriptionAttribute);
    149286
    150       XmlAttribute dataTypeAttribute = document.CreateAttribute("DataType");
    151       dataTypeAttribute.Value = PersistenceManager.BuildTypeString(DataType);
    152       node.Attributes.Append(dataTypeAttribute);
    153 
    154287      XmlAttribute typeAttribute = document.CreateAttribute("ParameterType");
    155288      typeAttribute.Value = Type.ToString();
    156289      node.Attributes.Append(typeAttribute);
     290
     291      XmlAttribute constantAttribute = document.CreateAttribute("Constant");
     292      constantAttribute.Value = Constant.ToString();
     293      node.Attributes.Append(constantAttribute);
     294
     295      XmlAttribute cachedAttribute = document.CreateAttribute("Cached");
     296      cachedAttribute.Value = Cached.ToString();
     297      node.Attributes.Append(cachedAttribute);
     298
     299      if (myValue != null)
     300        node.AppendChild(PersistenceManager.Persist("Value", Value, document, persistedObjects));
    157301
    158302      return node;
     
    169313    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    170314      base.Populate(node, restoredObjects);
    171       myName = node.Attributes["ActualName"].Value;
     315      myActualName = node.Attributes["ActualName"].Value;
     316      myFormalName = node.Attributes["FormalName"].Value;
    172317      myDescription = node.Attributes["Description"].Value;
    173       myDataType = System.Type.GetType(node.Attributes["DataType"].Value, true);
    174318      myType = (ParameterType)Enum.Parse(typeof(ParameterType), node.Attributes["ParameterType"].Value);
     319      myConstant = bool.Parse(node.Attributes["Constant"].Value);
     320      myCached = bool.Parse(node.Attributes["Cached"].Value);
     321
     322      XmlNode valueNode = node.SelectSingleNode("Value");
     323      if (valueNode != null)
     324        myValue = (T)PersistenceManager.Restore(valueNode, restoredObjects);
    175325    }
    176326    #endregion
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/ParameterView.cs

    r2027 r2030  
    3030namespace HeuristicLab.Core {
    3131  /// <summary>
    32   /// The visual representation of <see cref="IVariableInfo"/>.
     32  /// The visual representation of <see cref="IParameter"/>.
    3333  /// </summary>
    3434  public partial class ParameterView : ViewBase {
Note: See TracChangeset for help on using the changeset viewer.