Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 282 was 40, checked in by swagner, 17 years ago

Worked on ticket #41

  • added generic ItemList<T>
File size: 5.1 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      dataTypeAttribute.Value = PersistenceManager.BuildTypeString(DataType);
127      node.Attributes.Append(dataTypeAttribute);
128
129      XmlAttribute kindAttribute = document.CreateAttribute("Kind");
130      kindAttribute.Value = Kind.ToString();
131      node.Attributes.Append(kindAttribute);
132
133      XmlAttribute localAttribute = document.CreateAttribute("Local");
134      localAttribute.Value = Local.ToString();
135      node.Attributes.Append(localAttribute);
136
137      return node;
138    }
139    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
140      myActualName = node.Attributes["ActualName"].Value;
141      myFormalName = node.Attributes["FormalName"].Value;
142      myDescription = node.Attributes["Description"].Value;
143      myDataType = Type.GetType(node.Attributes["DataType"].Value, true);
144      myKind = (VariableKind)Enum.Parse(typeof(VariableKind), node.Attributes["Kind"].Value);
145      myLocal = bool.Parse(node.Attributes["Local"].Value);
146    }
147    #endregion
148  }
149}
Note: See TracBrowser for help on using the repository browser.