[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Xml;
|
---|
[1823] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2] | 27 |
|
---|
| 28 | namespace HeuristicLab.Core {
|
---|
[776] | 29 | /// <summary>
|
---|
| 30 | /// Class for storing meta-information about variables/parameters of an operator.
|
---|
| 31 | /// </summary>
|
---|
[2] | 32 | public class VariableInfo : ItemBase, IVariableInfo {
|
---|
[1667] | 33 |
|
---|
| 34 | [Storable]
|
---|
[2] | 35 | private string myActualName;
|
---|
[776] | 36 | /// <summary>
|
---|
| 37 | /// Gets or sets the actual name of the current instance.
|
---|
| 38 | /// </summary>
|
---|
| 39 | /// <remarks>Calls <see cref="OnActualNameChanged"/> in the setter.</remarks>
|
---|
[2] | 40 | public string ActualName {
|
---|
| 41 | get { return myActualName; }
|
---|
| 42 | set {
|
---|
| 43 | if (myActualName != value) {
|
---|
| 44 | myActualName = value;
|
---|
| 45 | OnActualNameChanged();
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
[1667] | 49 |
|
---|
| 50 | [Storable]
|
---|
[2] | 51 | private string myFormalName;
|
---|
[776] | 52 | /// <summary>
|
---|
| 53 | /// Gets the formal name of the current instance.
|
---|
| 54 | /// </summary>
|
---|
[2] | 55 | public string FormalName {
|
---|
| 56 | get { return myFormalName; }
|
---|
| 57 | }
|
---|
[1667] | 58 |
|
---|
| 59 | [Storable]
|
---|
[2] | 60 | private string myDescription;
|
---|
[776] | 61 | /// <summary>
|
---|
| 62 | /// Gets the description of the current instance.
|
---|
| 63 | /// </summary>
|
---|
[2] | 64 | public string Description {
|
---|
| 65 | get { return myDescription; }
|
---|
| 66 | }
|
---|
[1667] | 67 |
|
---|
| 68 | [Storable]
|
---|
[2] | 69 | private Type myDataType;
|
---|
[776] | 70 | /// <summary>
|
---|
| 71 | /// Gets the data type of the parameter.
|
---|
| 72 | /// </summary>
|
---|
[2] | 73 | public Type DataType {
|
---|
| 74 | get { return myDataType; }
|
---|
| 75 | }
|
---|
[1667] | 76 |
|
---|
| 77 | [Storable]
|
---|
[2] | 78 | private VariableKind myKind;
|
---|
[776] | 79 | /// <summary>
|
---|
| 80 | /// Gets the kind of the parameter (input parameter, output parameter,...).
|
---|
| 81 | /// </summary>
|
---|
[2] | 82 | public VariableKind Kind {
|
---|
| 83 | get { return myKind; }
|
---|
| 84 | }
|
---|
[1667] | 85 |
|
---|
| 86 | [Storable]
|
---|
[2] | 87 | private bool myLocal;
|
---|
[776] | 88 | /// <summary>
|
---|
| 89 | /// Gets or sets a boolean value, whether the variable is a local one.
|
---|
| 90 | /// </summary>
|
---|
| 91 | /// <remarks>Calls <see cref="OnLocalChanged"/> in the setter.</remarks>
|
---|
[2] | 92 | public bool Local {
|
---|
| 93 | get { return myLocal; }
|
---|
| 94 | set {
|
---|
| 95 | if (myLocal != value) {
|
---|
| 96 | myLocal = value;
|
---|
| 97 | OnLocalChanged();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[776] | 102 | /// <summary>
|
---|
| 103 | /// Initializes a new instance of <see cref="VariableInfo"/> with actual and formal name "Anonymous",
|
---|
| 104 | /// no description, a <c>null</c> data type and the <c>local</c> flag set to <c>false</c>. The type of
|
---|
| 105 | /// the variable is an input parameter.
|
---|
| 106 | /// </summary>
|
---|
[2] | 107 | public VariableInfo() {
|
---|
| 108 | myActualName = "Anonymous";
|
---|
| 109 | myFormalName = "Anonymous";
|
---|
| 110 | myDescription = "";
|
---|
| 111 | myDataType = null;
|
---|
| 112 | myKind = VariableKind.In;
|
---|
| 113 | myLocal = false;
|
---|
| 114 | }
|
---|
[776] | 115 | /// <summary>
|
---|
| 116 | /// Initializes a new instance of <see cref="VariableInfo"/> with the given parameters.
|
---|
| 117 | /// </summary>
|
---|
| 118 | /// <remarks>Calls <see cref="VariableInfo()"/>.<br/>
|
---|
| 119 | /// The formal name is assigned to the actual name, too.</remarks>
|
---|
| 120 | /// <param name="formalName">The formal name of the current instance.</param>
|
---|
| 121 | /// <param name="description">The description of the current instance.</param>
|
---|
| 122 | /// <param name="dataType">The data type of the parameter.</param>
|
---|
| 123 | /// <param name="kind">The type of the parameter.</param>
|
---|
[2] | 124 | public VariableInfo(string formalName, string description, Type dataType, VariableKind kind)
|
---|
| 125 | : this() {
|
---|
| 126 | myActualName = formalName;
|
---|
| 127 | myFormalName = formalName;
|
---|
| 128 | myDescription = description;
|
---|
| 129 | myDataType = dataType;
|
---|
| 130 | myKind = kind;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[776] | 133 | /// <summary>
|
---|
| 134 | /// Creates a new instance of <see cref="VariableInfoView"/> to represent the current instance
|
---|
| 135 | /// visually.
|
---|
| 136 | /// </summary>
|
---|
| 137 | /// <returns>The created view as <see cref="VariableInfoView"/>.</returns>
|
---|
[2] | 138 | public override IView CreateView() {
|
---|
| 139 | return new VariableInfoView(this);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[776] | 142 | /// <summary>
|
---|
| 143 | /// Clones the current instance (deep clone).
|
---|
| 144 | /// </summary>
|
---|
| 145 | /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
| 146 | /// <returns>The cloned object as <see cref="VariableInfo"/>.</returns>
|
---|
[2] | 147 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 148 | VariableInfo clone = new VariableInfo();
|
---|
| 149 | clonedObjects.Add(Guid, clone);
|
---|
| 150 | clone.myActualName = ActualName;
|
---|
| 151 | clone.myFormalName = FormalName;
|
---|
| 152 | clone.myDescription = Description;
|
---|
| 153 | clone.myDataType = DataType;
|
---|
| 154 | clone.myKind = Kind;
|
---|
| 155 | clone.myLocal = Local;
|
---|
| 156 | return clone;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[776] | 159 | /// <inheritdoc/>
|
---|
[2] | 160 | public event EventHandler ActualNameChanged;
|
---|
[776] | 161 | /// <summary>
|
---|
| 162 | /// Fires a new <c>ActualNameChanged</c> event.
|
---|
| 163 | /// </summary>
|
---|
[2] | 164 | protected virtual void OnActualNameChanged() {
|
---|
| 165 | if (ActualNameChanged != null)
|
---|
| 166 | ActualNameChanged(this, new EventArgs());
|
---|
| 167 | }
|
---|
[776] | 168 | /// <inheritdoc />
|
---|
[2] | 169 | public event EventHandler LocalChanged;
|
---|
[776] | 170 | /// <summary>
|
---|
| 171 | /// Fires a new <c>LocalChanged</c> event.
|
---|
| 172 | /// </summary>
|
---|
[2] | 173 | protected virtual void OnLocalChanged() {
|
---|
| 174 | if (LocalChanged != null)
|
---|
| 175 | LocalChanged(this, new EventArgs());
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | }
|
---|