Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/VariableInfo.cs @ 2

Last change on this file since 2 was 2, checked in by swagner, 16 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 5.2 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;
26
27namespace HeuristicLab.Core {
28  public class VariableInfo : ItemBase, IVariableInfo {
29    private string myActualName;
30    public string ActualName {
31      get { return myActualName; }
32      set {
33        if (myActualName != value) {
34          myActualName = value;
35          OnActualNameChanged();
36        }
37      }
38    }
39    private string myFormalName;
40    public string FormalName {
41      get { return myFormalName; }
42    }
43    private string myDescription;
44    public string Description {
45      get { return myDescription; }
46    }
47    private Type myDataType;
48    public Type DataType {
49      get { return myDataType; }
50    }
51    private VariableKind myKind;
52    public VariableKind Kind {
53      get { return myKind; }
54    }
55    private bool myLocal;
56    public bool Local {
57      get { return myLocal; }
58      set {
59        if (myLocal != value) {
60          myLocal = value;
61          OnLocalChanged();
62        }
63      }
64    }
65
66    public VariableInfo() {
67      myActualName = "Anonymous";
68      myFormalName = "Anonymous";
69      myDescription = "";
70      myDataType = null;
71      myKind = VariableKind.In;
72      myLocal = false;
73    }
74    public VariableInfo(string formalName, string description, Type dataType, VariableKind kind)
75      : this() {
76      myActualName = formalName;
77      myFormalName = formalName;
78      myDescription = description;
79      myDataType = dataType;
80      myKind = kind;
81    }
82
83    public override IView CreateView() {
84      return new VariableInfoView(this);
85    }
86
87    public override object Clone(IDictionary<Guid, object> clonedObjects) {
88      VariableInfo clone = new VariableInfo();
89      clonedObjects.Add(Guid, clone);
90      clone.myActualName = ActualName;
91      clone.myFormalName = FormalName;
92      clone.myDescription = Description;
93      clone.myDataType = DataType;
94      clone.myKind = Kind;
95      clone.myLocal = Local;
96      return clone;
97    }
98
99    public event EventHandler ActualNameChanged;
100    protected virtual void OnActualNameChanged() {
101      if (ActualNameChanged != null)
102        ActualNameChanged(this, new EventArgs());
103    }
104    public event EventHandler LocalChanged;
105    protected virtual void OnLocalChanged() {
106      if (LocalChanged != null)
107        LocalChanged(this, new EventArgs());
108    }
109
110    #region Persistence Methods
111    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
112      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
113      XmlAttribute actualNameAttribute = document.CreateAttribute("ActualName");
114      actualNameAttribute.Value = ActualName;
115      node.Attributes.Append(actualNameAttribute);
116
117      XmlAttribute formalNameAttribute = document.CreateAttribute("FormalName");
118      formalNameAttribute.Value = FormalName;
119      node.Attributes.Append(formalNameAttribute);
120
121      XmlAttribute descriptionAttribute = document.CreateAttribute("Description");
122      descriptionAttribute.Value = Description;
123      node.Attributes.Append(descriptionAttribute);
124
125      XmlAttribute dataTypeAttribute = document.CreateAttribute("DataType");
126      string typeString = DataType.AssemblyQualifiedName;
127      string[] tokens = typeString.Split(new string[] { ", " }, StringSplitOptions.None);
128      typeString = tokens[0] + ", " + tokens[1];
129      dataTypeAttribute.Value = typeString;
130      node.Attributes.Append(dataTypeAttribute);
131
132      XmlAttribute kindAttribute = document.CreateAttribute("Kind");
133      kindAttribute.Value = Kind.ToString();
134      node.Attributes.Append(kindAttribute);
135
136      XmlAttribute localAttribute = document.CreateAttribute("Local");
137      localAttribute.Value = Local.ToString();
138      node.Attributes.Append(localAttribute);
139
140      return node;
141    }
142    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
143      myActualName = node.Attributes["ActualName"].Value;
144      myFormalName = node.Attributes["FormalName"].Value;
145      myDescription = node.Attributes["Description"].Value;
146      myDataType = Type.GetType(node.Attributes["DataType"].Value, true);
147      myKind = (VariableKind)Enum.Parse(typeof(VariableKind), node.Attributes["Kind"].Value);
148      myLocal = bool.Parse(node.Attributes["Local"].Value);
149    }
150    #endregion
151  }
152}
Note: See TracBrowser for help on using the repository browser.