Changeset 776 for trunk/sources/HeuristicLab.Core/OperatorBase.cs
- Timestamp:
- 11/19/08 12:12:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/OperatorBase.cs
r76 r776 26 26 27 27 namespace HeuristicLab.Core { 28 /// <summary> 29 /// The base class for all operators. 30 /// </summary> 28 31 public abstract class OperatorBase : ConstrainedItemBase, IOperator { 29 32 private string myName; 33 /// <summary> 34 /// Gets or sets the name of the operator. 35 /// </summary> 36 /// <remarks>Calls <see cref="OnNameChanged"/> in the setter.</remarks> 30 37 public string Name { 31 38 get { return myName; } … … 37 44 } 38 45 } 46 /// <summary> 47 /// Gets the description of the current operator. 48 /// </summary> 49 /// <remarks>Returns "No operator description available" if the method is not overriden.</remarks> 39 50 public virtual string Description { 40 51 get { return "No operator description available."; } 41 52 } 42 53 /// <summary> 54 /// Flag whether the current instance has been canceled. 55 /// </summary> 43 56 protected bool myCanceled; 57 /// <inheritdoc/> 44 58 public bool Canceled { 45 59 get { return myCanceled; } 46 60 } 47 61 private bool myBreakpoint; 62 /// <inheritdoc/> 63 /// <remarks>Calls <see cref="OnBreakpointChanged"/> in the setter.</remarks> 48 64 public bool Breakpoint { 49 65 get { return myBreakpoint; } … … 57 73 58 74 private List<IOperator> mySubOperators; 75 /// <summary> 76 /// Gets a list of all suboperators. 77 /// <note type="caution"> Returns the suboperators read-only!</note> 78 /// </summary> 59 79 public virtual IList<IOperator> SubOperators { 60 80 get { return mySubOperators.AsReadOnly(); } 61 81 } 62 82 private Dictionary<string, IVariableInfo> myVariableInfos; 83 /// <inheritdoc/> 63 84 public virtual ICollection<IVariableInfo> VariableInfos { 64 85 get { return myVariableInfos.Values; } 65 86 } 66 87 private Dictionary<string, IVariable> myVariables; 88 /// <inheritdoc/> 67 89 public virtual ICollection<IVariable> Variables { 68 90 get { return myVariables.Values; } 69 91 } 70 92 93 /// <summary> 94 /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and 95 /// the canceled flag to <c>false</c> and the name of the operator to the type name. 96 /// </summary> 71 97 protected OperatorBase() { 72 98 myName = this.GetType().Name; … … 78 104 } 79 105 106 /// <summary> 107 /// Clones the current instance (deep clone). 108 /// </summary> 109 /// <remarks>Clones also sub operators, variables and variable infos.</remarks> 110 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 111 /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns> 80 112 public override object Clone(IDictionary<Guid, object> clonedObjects) { 81 113 OperatorBase clone = (OperatorBase)base.Clone(clonedObjects); … … 93 125 } 94 126 127 /// <summary> 128 /// Creates a new instance of <see cref="OperatorBaseView"/> to represent the current operator 129 /// visually. 130 /// </summary> 131 /// <returns>The created view as <see cref="OperatorBaseView"/>.</returns> 95 132 public override IView CreateView() { 96 133 return new OperatorBaseView(this); … … 98 135 99 136 #region SubOperator Methods 137 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator)"/> 138 /// <param name="subOperator">The sub operator to add.</param> 139 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 100 140 public virtual void AddSubOperator(IOperator subOperator) { 101 141 mySubOperators.Add(subOperator); 102 142 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1); 103 143 } 144 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/> 145 /// <param name="subOperator">The sub operator to add.</param> 146 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 104 147 public virtual bool TryAddSubOperator(IOperator subOperator) { 105 148 mySubOperators.Add(subOperator); … … 112 155 } 113 156 } 157 /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, 158 /// out System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/> 159 /// <param name="subOperator">The sub operator to add.</param> 160 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 114 161 public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) { 115 162 mySubOperators.Add(subOperator); … … 122 169 } 123 170 } 171 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/> 172 /// <param name="subOperator">The sub operator to add.</param> 173 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 124 174 public virtual void AddSubOperator(IOperator subOperator, int index) { 125 175 mySubOperators.Insert(index, subOperator); 126 176 OnSubOperatorAdded(subOperator, index); 127 177 } 178 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/> 179 /// <param name="subOperator">The sub operator to add.</param> 180 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 128 181 public virtual bool TryAddSubOperator(IOperator subOperator, int index) { 129 182 mySubOperators.Insert(index, subOperator); … … 136 189 } 137 190 } 191 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out 192 /// System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/> 193 /// <param name="subOperator">The sub operator to add.</param> 194 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks> 138 195 public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) { 139 196 mySubOperators.Insert(index, subOperator); … … 146 203 } 147 204 } 205 /// <inheritdoc/> 206 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> 148 207 public virtual void RemoveSubOperator(int index) { 149 208 IOperator op = mySubOperators[index]; … … 151 210 OnSubOperatorRemoved(op, index); 152 211 } 212 /// <inheritdoc/> 213 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> 153 214 public virtual bool TryRemoveSubOperator(int index) { 154 215 IOperator op = mySubOperators[index]; … … 162 223 } 163 224 } 225 /// <inheritdoc/> 226 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> 164 227 public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) { 165 228 IOperator op = mySubOperators[index]; … … 176 239 177 240 #region VariableInfo Methods 241 /// <inheritdoc/> 178 242 public virtual IVariableInfo GetVariableInfo(string formalName) { 179 243 IVariableInfo info; … … 183 247 return null; 184 248 } 249 /// <inheritdoc/> 250 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 185 251 public virtual void AddVariableInfo(IVariableInfo variableInfo) { 186 252 myVariableInfos.Add(variableInfo.FormalName, variableInfo); 187 253 OnVariableInfoAdded(variableInfo); 188 254 } 255 /// <inheritdoc/> 256 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 189 257 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) { 190 258 myVariableInfos.Add(variableInfo.FormalName, variableInfo); … … 197 265 } 198 266 } 267 /// <inheritdoc/> 268 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 199 269 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) { 200 270 myVariableInfos.Add(variableInfo.FormalName, variableInfo); … … 207 277 } 208 278 } 279 /// <inheritdoc/> 280 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 209 281 public virtual void RemoveVariableInfo(string formalName) { 210 282 IVariableInfo variableInfo; … … 214 286 } 215 287 } 288 /// <inheritdoc/> 289 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 216 290 public virtual bool TryRemoveVariableInfo(string formalName) { 217 291 IVariableInfo variableInfo; … … 228 302 return true; 229 303 } 304 /// <inheritdoc/> 305 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 230 306 public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) { 231 307 IVariableInfo variableInfo; … … 246 322 247 323 #region Variable Methods 324 /// <inheritdoc/> 248 325 public virtual IVariable GetVariable(string name) { 249 326 IVariable variable; … … 253 330 return null; 254 331 } 332 /// <inheritdoc/> 333 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 334 /// event handlers.</remarks> 255 335 public virtual void AddVariable(IVariable variable) { 256 336 myVariables.Add(variable.Name, variable); … … 259 339 OnVariableAdded(variable); 260 340 } 341 /// <inheritdoc/> 342 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 343 /// event handlers.</remarks> 261 344 public virtual bool TryAddVariable(IVariable variable) { 262 345 myVariables.Add(variable.Name, variable); … … 271 354 } 272 355 } 356 /// <inheritdoc/> 357 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 358 /// event handlers.</remarks> 273 359 public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) { 274 360 myVariables.Add(variable.Name, variable); … … 283 369 } 284 370 } 371 /// <inheritdoc/> 372 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 373 /// event handlers.</remarks> 285 374 public virtual void RemoveVariable(string name) { 286 375 IVariable variable; … … 292 381 } 293 382 } 383 /// <inheritdoc/> 384 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 385 /// event handlers.</remarks> 294 386 public virtual bool TryRemoveVariable(string name) { 295 387 IVariable variable; … … 308 400 return true; 309 401 } 402 /// <inheritdoc/> 403 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 404 /// event handlers.</remarks> 310 405 public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) { 311 406 IVariable variable; … … 338 433 myVariables.Add(variable.Name, variable); 339 434 } 435 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool)"/> 436 /// <remarks>Calls <see cref="GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 437 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 340 438 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem { 341 439 return GetVariableValue<T>(formalName, scope, recursiveLookup, true); 342 440 } 441 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 442 /// <remarks>Calls 443 /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks> 343 444 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem { 344 445 return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError); 345 446 } 447 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/> 448 /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 449 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 346 450 public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) { 347 451 return GetVariableValue(formalName, scope, recursiveLookup, true); 348 452 } 453 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 349 454 public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) { 350 455 IVariableInfo info = GetVariableInfo(formalName); … … 364 469 } 365 470 #endregion 366 471 /// <inheritdoc/> 367 472 public virtual IOperation Execute(IScope scope) { 368 473 myCanceled = false; … … 379 484 return next; 380 485 } 486 /// <inheritdoc/> 487 /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks> 381 488 public virtual void Abort() { 382 489 myCanceled = true; 383 490 } 384 491 /// <summary> 492 /// Performs the current operator on the specified <paramref name="scope"/>. 493 /// </summary> 494 /// <param name="scope">The scope where to execute the operator</param> 495 /// <returns><c>null</c>.</returns> 385 496 public virtual IOperation Apply(IScope scope) { 386 497 return null; 387 498 } 388 499 /// <inheritdoc/> 389 500 public event EventHandler NameChanged; 501 /// <summary> 502 /// Fires a new <c>NameChanged</c> event. 503 /// </summary> 390 504 protected virtual void OnNameChanged() { 391 505 if (NameChanged != null) { … … 393 507 } 394 508 } 509 /// <inheritdoc/> 395 510 public event EventHandler BreakpointChanged; 511 /// <summary> 512 /// Fires a new <c>BreakpointChanged</c> event. 513 /// </summary> 396 514 protected virtual void OnBreakpointChanged() { 397 515 if (BreakpointChanged != null) { … … 399 517 } 400 518 } 519 /// <inheritdoc/> 401 520 public event EventHandler<OperatorIndexEventArgs> SubOperatorAdded; 521 /// <summary> 522 /// Fires a new <c>SubOperatorAdded</c> event. 523 /// </summary> 524 /// <param name="subOperator">The sub operator that has been added.</param> 525 /// <param name="index">The position where the operator has been added.</param> 402 526 protected virtual void OnSubOperatorAdded(IOperator subOperator, int index) { 403 527 if (SubOperatorAdded != null) 404 528 SubOperatorAdded(this, new OperatorIndexEventArgs(subOperator, index)); 405 529 } 530 /// <inheritdoc/> 406 531 public event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved; 532 /// <summary> 533 /// Fires a new <c>SubOperatorRemoved</c> event. 534 /// </summary> 535 /// <param name="subOperator">The sub operator that has been removed.</param> 536 /// <param name="index">The position where the operator has been removed.</param> 407 537 protected virtual void OnSubOperatorRemoved(IOperator subOperator, int index) { 408 538 if (SubOperatorRemoved != null) 409 539 SubOperatorRemoved(this, new OperatorIndexEventArgs(subOperator, index)); 410 540 } 541 /// <inheritdoc/> 411 542 public event EventHandler<VariableInfoEventArgs> VariableInfoAdded; 543 /// <summary> 544 /// Fires a new <c>VariableInfoAdded</c> event. 545 /// </summary> 546 /// <param name="variableInfo">The variable info that has been added.</param> 412 547 protected virtual void OnVariableInfoAdded(IVariableInfo variableInfo) { 413 548 if (VariableInfoAdded != null) 414 549 VariableInfoAdded(this, new VariableInfoEventArgs(variableInfo)); 415 550 } 551 /// <inheritdoc/> 416 552 public event EventHandler<VariableInfoEventArgs> VariableInfoRemoved; 553 /// <summary> 554 /// Fires a new <c>VariableInfoRemoved</c> event. 555 /// </summary> 556 /// <param name="variableInfo">The variable info that has been removed.</param> 417 557 protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) { 418 558 if (VariableInfoRemoved != null) 419 559 VariableInfoRemoved(this, new VariableInfoEventArgs(variableInfo)); 420 560 } 561 /// <inheritdoc/> 421 562 public event EventHandler<VariableEventArgs> VariableAdded; 563 /// <summary> 564 /// Fires a new <c>VariableAdded</c> event. 565 /// </summary> 566 /// <param name="variable">The variable that has been added.</param> 422 567 protected virtual void OnVariableAdded(IVariable variable) { 423 568 if (VariableAdded != null) 424 569 VariableAdded(this, new VariableEventArgs(variable)); 425 570 } 571 /// <inheritdoc/> 426 572 public event EventHandler<VariableEventArgs> VariableRemoved; 573 /// <summary> 574 /// Fires a new <c>VariableRemoved</c> event. 575 /// </summary> 576 /// <param name="variable">The variable that has been removed</param> 427 577 protected virtual void OnVariableRemoved(IVariable variable) { 428 578 if (VariableRemoved != null) 429 579 VariableRemoved(this, new VariableEventArgs(variable)); 430 580 } 581 /// <inheritdoc/> 431 582 public event EventHandler Executed; 583 /// <summary> 584 /// Fires a new <c>Executed</c> event. 585 /// </summary> 432 586 protected virtual void OnExecuted() { 433 587 if (Executed != null) { … … 437 591 438 592 #region Persistence Methods 593 /// <summary> 594 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 595 /// </summary> 596 /// <remarks> 597 /// Calls <see cref="ConstrainedItemBase.GetXmlNode"/> of base class <see cref="ConstrainedItemBase"/>. 598 /// <br/>A quick overview how the single elements of the current instance are saved: 599 /// <list type="bullet"> 600 /// <item> 601 /// <term>Name: </term> 602 /// <description>Saved as an <see cref="XmlAttribute"/> with the name <c>Name</c>.</description> 603 /// </item> 604 /// <item> 605 /// <term>Breakpoint: </term> 606 /// <description>Is only saved if it set to <c>true</c>. 607 /// Saved as an <see cref="XmlAttribute"/> with the name <c>Breakpoint</c>.</description> 608 /// </item> 609 /// <item> 610 /// <term>Sub operators: </term> 611 /// <description>Saved as child node with tag name <c>SubOperators</c>. All sub operators are themselves 612 /// saved as child nodes.</description> 613 /// </item> 614 /// <item> 615 /// <term>Variable infos: </term> 616 /// <description>Saved as child node with tag name <c>VariableInfos</c>. All variable infos are themselves 617 /// saved as child nodes.</description> 618 /// </item> 619 /// <item> 620 /// <term>Variables: </term> 621 /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves 622 /// saved as child nodes.</description> 623 /// </item> 624 /// </list> 625 /// </remarks> 626 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 627 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param> 628 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 629 /// <returns>The saved <see cref="XmlNode"/>.</returns> 439 630 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 440 631 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 461 652 return node; 462 653 } 654 /// <summary> 655 /// Loads the persisted operation from the specified <paramref name="node"/>. 656 /// </summary> 657 /// <remarks>Calls <see cref="ConstrainedItemBase.Populate"/> of base class 658 /// <see cref="ConstrainedItemBase"/>. 659 /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks> 660 /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param> 661 /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param> 463 662 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 464 663 base.Populate(node, restoredObjects);
Note: See TracChangeset
for help on using the changeset viewer.