Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.Core/3.3/VariableInfo.cs @ 6531

Last change on this file since 6531 was 1823, checked in by epitzer, 15 years ago

Namespace refactoring: rename formatters & decomposers -> primitive and composite serializers. (#603)

File size: 5.8 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace 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    /// 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>
138    public override IView CreateView() {
139      return new VariableInfoView(this);
140    }
141
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>
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
159    /// <inheritdoc/>
160    public event EventHandler ActualNameChanged;
161    /// <summary>
162    /// Fires a new <c>ActualNameChanged</c> event.
163    /// </summary>
164    protected virtual void OnActualNameChanged() {
165      if (ActualNameChanged != null)
166        ActualNameChanged(this, new EventArgs());
167    }
168    /// <inheritdoc />
169    public event EventHandler LocalChanged;
170    /// <summary>
171    /// Fires a new <c>LocalChanged</c> event.
172    /// </summary>
173    protected virtual void OnLocalChanged() {
174      if (LocalChanged != null)
175        LocalChanged(this, new EventArgs());
176    }
177  }
178}
Note: See TracBrowser for help on using the repository browser.