Changeset 2030 for branches/Operator Architecture Refactoring
- Timestamp:
- 06/08/09 02:02:21 (16 years ago)
- Location:
- branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IParameter.cs
r1994 r2030 27 27 namespace HeuristicLab.Core { 28 28 /// <summary> 29 /// Interface to store meta-information about parameters of operators.29 /// Interface to represent parameters of operators. 30 30 /// </summary> 31 31 public interface IParameter : IItem { 32 32 /// <summary> 33 /// Gets or sets the name of the current instance.33 /// Gets or sets the actual name of the parameter. 34 34 /// </summary> 35 string Name { get; }35 string ActualName { get; set; } 36 36 /// <summary> 37 /// Gets the description of the current instance.37 /// Gets or sets the formal name of the parameter. 38 38 /// </summary> 39 string Description { get; } 39 string FormalName { get; } 40 /// <summary> 41 /// Gets or sets the description of the current instance. 42 /// </summary> 43 string Description { get; set; } 40 44 /// <summary> 41 45 /// Gets the data type of the current instance. … … 46 50 /// </summary> 47 51 ParameterType Type { get; } 52 /// <summary> 53 /// Gets or sets, if the parameter is constant (only valid for input parameters). 54 /// </summary> 55 bool Constant { get; set; } 56 /// <summary> 57 /// Gets or sets, if the parameter should be cached by operators. 58 /// </summary> 59 bool Cached { get; set; } 60 /// <summary> 61 /// Gets or sets the value of the parameter. 62 /// </summary> 63 IItem Value { get; set; } 64 65 /// <summary> 66 /// Occurs when the actual name of the current instance has been changed. 67 /// </summary> 68 event EventHandler ActualNameChanged; 69 /// <summary> 70 /// Occurs when the description of the current instance has been changed. 71 /// </summary> 72 event EventHandler DescriptionChanged; 73 /// <summary> 74 /// Occurs when the constant flag of the current instance has been changed. 75 /// </summary> 76 event EventHandler ConstantChanged; 77 /// <summary> 78 /// Occurs when the cached flag of the current instance has been changed. 79 /// </summary> 80 event EventHandler CachedChanged; 81 /// <summary> 82 /// Occurs when the value of the current instance has been changed. 83 /// </summary> 84 event EventHandler ValueChanged; 85 86 } 87 88 /// <summary> 89 /// Generic interface to represent parameters of operators. 90 /// </summary> 91 /// <typeparam name="T">The data type of the parameter, which has to be an <see cref="IItem"/>.</typeparam> 92 public interface IParamter<T> : IParameter where T : class, IItem { 93 /// <summary> 94 /// Gets or sets the value of the parameter. 95 /// </summary> 96 T Value { get; set; } 48 97 } 49 98 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Parameter.cs
r2027 r2030 27 27 namespace HeuristicLab.Core { 28 28 /// <summary> 29 /// Class for storing meta-information about parametersof an operator.29 /// Represents a parameter of an operator. 30 30 /// </summary> 31 public class Parameter : ItemBase, IParameter { 32 private string myName; 33 /// <summary> 34 /// Gets or sets the name of the current instance. 31 /// <typeparam name="T">The data type of the parameter, which has to be an <see cref="IItem"/>.</typeparam> 32 public class Parameter<T> : ItemBase, IParameter, IParamter<T> where T : class, IItem { 33 private string myActualName; 34 /// <summary> 35 /// Gets or sets the actual name of the current instance. 35 36 /// </summary> 36 37 /// <remarks>Calls <see cref="OnActualNameChanged"/> in the setter.</remarks> 37 public string Name { 38 get { return myName; } 38 public string ActualName { 39 get { return myActualName; } 40 set { 41 if (! myActualName.Equals(value)) { 42 myActualName = value; 43 OnActualNameChanged(); 44 } 45 } 46 } 47 private string myFormalName; 48 /// <summary> 49 /// Gets the formal name of the current instance. 50 /// </summary> 51 public string FormalName { 52 get { return myFormalName; } 39 53 } 40 54 private string myDescription; 41 55 /// <summary> 42 /// Gets the description of the current instance. 43 /// </summary> 56 /// Gets or sets the description of the current instance. 57 /// </summary> 58 /// <remarks>Calls <see cref="OnDescriptionChanged"/> in the setter.</remarks> 44 59 public string Description { 45 60 get { return myDescription; } 46 } 47 private Type myDataType; 61 set { 62 if (! myDescription.Equals(value)) { 63 myDescription = value; 64 OnDescriptionChanged(); 65 } 66 } 67 } 48 68 /// <summary> 49 69 /// Gets the data type of the parameter. 50 70 /// </summary> 51 71 public Type DataType { 52 get { return myDataType; }72 get { return typeof(T); } 53 73 } 54 74 private ParameterType myType; … … 58 78 public ParameterType Type { 59 79 get { return myType; } 80 } 81 private bool myConstant; 82 /// <summary> 83 /// Gets or sets, if the parameter is constant (only valid for input parameters). 84 /// </summary> 85 /// <remarks>Calls <see cref="OnConstantChanged"/> in the setter.</remarks> 86 public bool Constant { 87 get { return myConstant; } 88 set { 89 if (Type != ParameterType.In) throw new InvalidOperationException("only input parameters can be constant"); 90 if (myConstant != value) { 91 myConstant = value; 92 OnConstantChanged(); 93 } 94 } 95 } 96 private bool myCached; 97 /// <summary> 98 /// Gets or sets, if the parameter should be cached by operators. 99 /// </summary> 100 /// <remarks>Calls <see cref="OnCachedChanged"/> in the setter.</remarks> 101 public bool Cached { 102 get { return myCached; } 103 set { 104 if (myCached != value) { 105 myCached = value; 106 OnCachedChanged(); 107 } 108 } 109 } 110 private T myValue; 111 /// <summary> 112 /// Gets or sets the value of the parameter. 113 /// </summary> 114 public T Value { 115 get { return myValue; } 116 set { 117 if (! myValue.Equals(value)) { 118 myValue = value; 119 OnValueChanged(); 120 } 121 } 122 } 123 /// <summary> 124 /// Gets or sets the value of the parameter. 125 /// </summary> 126 public IItem IParameter.Value { 127 get { return myValue; } 128 set { Value = (T)value; } 60 129 } 61 130 … … 66 135 /// </summary> 67 136 public Parameter() { 68 myName = "Anonymous"; 137 myActualName = "Anonymous"; 138 myFormalName = "Anonymous"; 69 139 myDescription = ""; 70 myDataType = null;71 140 myType = ParameterType.In; 141 myConstant = false; 142 myCached = false; 143 myValue = null; 72 144 } 73 145 /// <summary> 74 146 /// Initializes a new instance of <see cref="Parameter"/> with the given parameters. 75 147 /// </summary> 76 /// <remarks>Calls <see cref="Parameter()"/>.</remarks> 77 /// <param name="name">The name of the current instance.</param> 148 /// <remarks>Calls <see cref="Parameter()"/>.<br/> 149 /// The formal name is assigned to the actual name, too.</remarks> 150 /// <param name="formalName">The formal name of the current instance.</param> 78 151 /// <param name="description">The description of the current instance.</param> 79 /// <param name="dataType">The data type of the parameter.</param> 80 /// <param name="type">The type of the parameter.</param> 81 public Parameter(string name, string description, Type dataType, ParameterType type) 152 /// <param name="kind">The type of the parameter.</param> 153 public Parameter(string formalName, string description, ParameterType type, bool constant, bool cached) 82 154 : this() { 83 myName = name; 155 myActualName = formalName; 156 myFormalName = formalName; 84 157 myDescription = description; 85 myDataType = dataType;86 158 myType = type; 159 myConstant = constant; 160 myCached = cached; 87 161 } 88 162 … … 102 176 /// <returns>The cloned object as <see cref="Parameter"/>.</returns> 103 177 public override object Clone(IDictionary<Guid, object> clonedObjects) { 104 Parameter clone = new Parameter();178 Parameter<T> clone = (Parameter<T>)base.Clone(clonedObjects); 105 179 clonedObjects.Add(Guid, clone); 106 clone.myName = Name; 180 clone.myActualName = ActualName; 181 clone.myFormalName = FormalName; 107 182 clone.myDescription = Description; 108 clone.myDataType = DataType;109 183 clone.myType = Type; 184 clone.myConstant = Constant; 185 clone.myCached = Cached; 186 clone.myValue = (T)Auxiliary.Clone(Value, clonedObjects); 110 187 return clone; 188 } 189 190 /// <inheritdoc/> 191 public event EventHandler ActualNameChanged; 192 /// <summary> 193 /// Fires a new <c>ActualNameChanged</c> event. 194 /// </summary> 195 protected virtual void OnActualNameChanged() { 196 if (ActualNameChanged != null) 197 ActualNameChanged(this, new EventArgs()); 198 } 199 /// <inheritdoc /> 200 public event EventHandler DescriptionChanged; 201 /// <summary> 202 /// Fires a new <c>DescriptionChanged</c> event. 203 /// </summary> 204 protected virtual void OnDescriptionChanged() { 205 if (DescriptionChanged != null) 206 DescriptionChanged(this, new EventArgs()); 207 } 208 public event EventHandler ConstantChanged; 209 /// <summary> 210 /// Fires a new <c>ConstantChanged</c> event. 211 /// </summary> 212 protected virtual void OnConstantChanged() { 213 if (ConstantChanged != null) 214 ConstantChanged(this, new EventArgs()); 215 } 216 public event EventHandler CachedChanged; 217 /// <summary> 218 /// Fires a new <c>CachedChanged</c> event. 219 /// </summary> 220 protected virtual void OnCachedChanged() { 221 if (CachedChanged != null) 222 CachedChanged(this, new EventArgs()); 223 } 224 public event EventHandler ValueChanged; 225 /// <summary> 226 /// Fires a new <c>ValueChanged</c> event. 227 /// </summary> 228 protected virtual void OnValueChanged() { 229 if (ValueChanged != null) 230 ValueChanged(this, new EventArgs()); 111 231 } 112 232 … … 119 239 /// <list type="bullet"> 120 240 /// <item> 121 /// <term>Name: </term> 122 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Name</c>.</description> 241 /// <term>ActualName: </term> 242 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>ActualName</c>.</description> 243 /// </item> 244 /// <item> 245 /// <term>FormalName: </term> 246 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>FormalName</c>.</description> 123 247 /// </item> 124 248 /// <item> … … 126 250 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Description</c>.</description> 127 251 /// </item> 128 /// <item><term>Data type: </term>129 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>DataType</c>.</description>130 /// </item>131 252 /// <item> 132 253 /// <term>Type: </term> 133 254 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>ParameterType</c>.</description> 255 /// </item> 256 /// <item> 257 /// <term>Constant: </term> 258 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Constant</c>.</description> 259 /// </item> 260 /// <item> 261 /// <term>Cached: </term> 262 /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Cached</c>.</description> 263 /// </item> 264 /// <item> 265 /// <term>Value: </term> 266 /// <description>Saved as child node with tag name <c>Value</c>.</description> 134 267 /// </item> 135 268 /// </list></remarks> … … 140 273 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 141 274 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 142 XmlAttribute nameAttribute = document.CreateAttribute("Name"); 143 nameAttribute.Value = Name; 144 node.Attributes.Append(nameAttribute); 275 XmlAttribute actualNameAttribute = document.CreateAttribute("ActualName"); 276 actualNameAttribute.Value = ActualName; 277 node.Attributes.Append(actualNameAttribute); 278 279 XmlAttribute formalNameAttribute = document.CreateAttribute("FormalName"); 280 formalNameAttribute.Value = FormalName; 281 node.Attributes.Append(formalNameAttribute); 145 282 146 283 XmlAttribute descriptionAttribute = document.CreateAttribute("Description"); … … 148 285 node.Attributes.Append(descriptionAttribute); 149 286 150 XmlAttribute dataTypeAttribute = document.CreateAttribute("DataType");151 dataTypeAttribute.Value = PersistenceManager.BuildTypeString(DataType);152 node.Attributes.Append(dataTypeAttribute);153 154 287 XmlAttribute typeAttribute = document.CreateAttribute("ParameterType"); 155 288 typeAttribute.Value = Type.ToString(); 156 289 node.Attributes.Append(typeAttribute); 290 291 XmlAttribute constantAttribute = document.CreateAttribute("Constant"); 292 constantAttribute.Value = Constant.ToString(); 293 node.Attributes.Append(constantAttribute); 294 295 XmlAttribute cachedAttribute = document.CreateAttribute("Cached"); 296 cachedAttribute.Value = Cached.ToString(); 297 node.Attributes.Append(cachedAttribute); 298 299 if (myValue != null) 300 node.AppendChild(PersistenceManager.Persist("Value", Value, document, persistedObjects)); 157 301 158 302 return node; … … 169 313 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 170 314 base.Populate(node, restoredObjects); 171 myName = node.Attributes["ActualName"].Value; 315 myActualName = node.Attributes["ActualName"].Value; 316 myFormalName = node.Attributes["FormalName"].Value; 172 317 myDescription = node.Attributes["Description"].Value; 173 myDataType = System.Type.GetType(node.Attributes["DataType"].Value, true);174 318 myType = (ParameterType)Enum.Parse(typeof(ParameterType), node.Attributes["ParameterType"].Value); 319 myConstant = bool.Parse(node.Attributes["Constant"].Value); 320 myCached = bool.Parse(node.Attributes["Cached"].Value); 321 322 XmlNode valueNode = node.SelectSingleNode("Value"); 323 if (valueNode != null) 324 myValue = (T)PersistenceManager.Restore(valueNode, restoredObjects); 175 325 } 176 326 #endregion -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/ParameterView.cs
r2027 r2030 30 30 namespace HeuristicLab.Core { 31 31 /// <summary> 32 /// The visual representation of <see cref="I VariableInfo"/>.32 /// The visual representation of <see cref="IParameter"/>. 33 33 /// </summary> 34 34 public partial class ParameterView : ViewBase {
Note: See TracChangeset
for help on using the changeset viewer.