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;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Core {
|
---|
29 | /// <summary>
|
---|
30 | /// Class for storing meta-information about variables/parameters of an operator.
|
---|
31 | /// </summary>
|
---|
32 | public class VariableInfo : ItemBase, IVariableInfo {
|
---|
33 |
|
---|
34 | [Storable]
|
---|
35 | private string myActualName;
|
---|
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>
|
---|
40 | public string ActualName {
|
---|
41 | get { return myActualName; }
|
---|
42 | set {
|
---|
43 | if (myActualName != value) {
|
---|
44 | myActualName = value;
|
---|
45 | OnActualNameChanged();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [Storable]
|
---|
51 | private string myFormalName;
|
---|
52 | /// <summary>
|
---|
53 | /// Gets the formal name of the current instance.
|
---|
54 | /// </summary>
|
---|
55 | public string FormalName {
|
---|
56 | get { return myFormalName; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | [Storable]
|
---|
60 | private string myDescription;
|
---|
61 | /// <summary>
|
---|
62 | /// Gets the description of the current instance.
|
---|
63 | /// </summary>
|
---|
64 | public string Description {
|
---|
65 | get { return myDescription; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | [Storable]
|
---|
69 | private Type myDataType;
|
---|
70 | /// <summary>
|
---|
71 | /// Gets the data type of the parameter.
|
---|
72 | /// </summary>
|
---|
73 | public Type DataType {
|
---|
74 | get { return myDataType; }
|
---|
75 | }
|
---|
76 |
|
---|
77 | [Storable]
|
---|
78 | private VariableKind myKind;
|
---|
79 | /// <summary>
|
---|
80 | /// Gets the kind of the parameter (input parameter, output parameter,...).
|
---|
81 | /// </summary>
|
---|
82 | public VariableKind Kind {
|
---|
83 | get { return myKind; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | [Storable]
|
---|
87 | private bool myLocal;
|
---|
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>
|
---|
92 | public bool Local {
|
---|
93 | get { return myLocal; }
|
---|
94 | set {
|
---|
95 | if (myLocal != value) {
|
---|
96 | myLocal = value;
|
---|
97 | OnLocalChanged();
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
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>
|
---|
107 | public VariableInfo() {
|
---|
108 | myActualName = "Anonymous";
|
---|
109 | myFormalName = "Anonymous";
|
---|
110 | myDescription = "";
|
---|
111 | myDataType = null;
|
---|
112 | myKind = VariableKind.In;
|
---|
113 | myLocal = false;
|
---|
114 | }
|
---|
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>
|
---|
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 |
|
---|
133 | /// <summary>
|
---|
134 | /// Clones the current instance (deep clone).
|
---|
135 | /// </summary>
|
---|
136 | /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
137 | /// <returns>The cloned object as <see cref="VariableInfo"/>.</returns>
|
---|
138 | public override IItem Clone(ICloner cloner) {
|
---|
139 | VariableInfo clone = new VariableInfo();
|
---|
140 | cloner.RegisterClonedObject(this, clone);
|
---|
141 | clone.myActualName = ActualName;
|
---|
142 | clone.myFormalName = FormalName;
|
---|
143 | clone.myDescription = Description;
|
---|
144 | clone.myDataType = DataType;
|
---|
145 | clone.myKind = Kind;
|
---|
146 | clone.myLocal = Local;
|
---|
147 | return clone;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /// <inheritdoc/>
|
---|
151 | public event EventHandler ActualNameChanged;
|
---|
152 | /// <summary>
|
---|
153 | /// Fires a new <c>ActualNameChanged</c> event.
|
---|
154 | /// </summary>
|
---|
155 | protected virtual void OnActualNameChanged() {
|
---|
156 | if (ActualNameChanged != null)
|
---|
157 | ActualNameChanged(this, new EventArgs());
|
---|
158 | }
|
---|
159 | /// <inheritdoc />
|
---|
160 | public event EventHandler LocalChanged;
|
---|
161 | /// <summary>
|
---|
162 | /// Fires a new <c>LocalChanged</c> event.
|
---|
163 | /// </summary>
|
---|
164 | protected virtual void OnLocalChanged() {
|
---|
165 | if (LocalChanged != null)
|
---|
166 | LocalChanged(this, new EventArgs());
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|