Changeset 776 for trunk/sources/HeuristicLab.Core/ConstrainedItemBase.cs
- Timestamp:
- 11/19/08 12:12:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/ConstrainedItemBase.cs
r2 r776 26 26 27 27 namespace HeuristicLab.Core { 28 /// <summary> 29 /// Base class for all items that are subjects to restrictions. 30 /// </summary> 28 31 public abstract class ConstrainedItemBase : ItemBase, IConstrainedItem { 29 32 private List<IConstraint> myConstraints; 33 /// <summary> 34 /// Gets all current constraints. 35 /// <note type="caution"> The constraints are returned read-only.</note> 36 /// </summary> 30 37 public virtual ICollection<IConstraint> Constraints { 31 38 get { return myConstraints.AsReadOnly(); } 32 39 } 33 40 41 /// <summary> 42 /// Initializes a new instance of <see cref="ConstrainedItemBase"/>. 43 /// </summary> 34 44 protected ConstrainedItemBase() { 35 45 myConstraints = new List<IConstraint>(); 36 46 } 37 47 48 /// <summary> 49 /// Clones the current instance (deep clone). 50 /// </summary> 51 /// <remarks>Calls <see cref="StorableBase.Clone 52 /// (System.Collections.Generic.IDictionary<System.Guid, object>)"/> 53 /// of base class <see cref="ItemBase"/>.<br/> 54 /// Deep clone through <see cref="Auxiliary.Clone"/> method of helper class 55 /// <see cref="Auxiliary"/>.</remarks> 56 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 57 /// <returns>The cloned object as <see cref="ConstrainedItemBase"/>.</returns> 38 58 public override object Clone(IDictionary<Guid, object> clonedObjects) { 39 59 ConstrainedItemBase clone = (ConstrainedItemBase)base.Clone(clonedObjects); … … 44 64 } 45 65 66 /// <summary> 67 /// Adds the given <paramref name="constraint"/> to the current list. 68 /// </summary> 69 /// <remarks>Calls <see cref="OnConstraintAdded"/>.</remarks> 70 /// <param name="constraint">The constraint to add.</param> 46 71 public virtual void AddConstraint(IConstraint constraint) { 47 72 myConstraints.Add(constraint); 48 73 OnConstraintAdded(constraint); 49 74 } 75 /// <summary> 76 /// Removes the given <paramref name="constraint"/> from the current list. 77 /// </summary> 78 /// <remarks>Calls <see cref="OnConstraintRemoved"/> if the constraint can be successfully removed.</remarks> 79 /// <param name="constraint">The constraint to remove.</param> 50 80 public virtual void RemoveConstraint(IConstraint constraint) { 51 81 if (myConstraints.Remove(constraint)) … … 53 83 } 54 84 85 /// <summary> 86 /// Checks all constraints of the current instance. 87 /// </summary> 88 /// <returns><c>true</c> if all constraints could be fulfilled, <c>false</c> otherwise.</returns> 55 89 public bool IsValid() { 56 90 bool result = true; … … 59 93 return result; 60 94 } 95 /// <summary> 96 /// Checks all constraints of the current instance. 97 /// </summary> 98 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be 99 /// fulfilled.</param> 100 /// <returns><c>true</c> if all constraints could be fulfilled, <c>false</c> otherwise.</returns> 61 101 public bool IsValid(out ICollection<IConstraint> violatedConstraints) { 62 102 bool result = true; … … 71 111 } 72 112 113 /// <summary> 114 /// Creates an instance of <see cref="ConstrainedItemBaseView"/> 115 /// to represent the current instance visually. 116 /// </summary> 117 /// <returns>The created view as <see cref="ConstrainedItemBase"/>.</returns> 73 118 public override IView CreateView() { 74 119 return new ConstrainedItemBaseView(this); 75 120 } 76 121 122 /// <summary> 123 /// Occurs when a constraint is added. 124 /// </summary> 77 125 public event EventHandler<ConstraintEventArgs> ConstraintAdded; 126 /// <summary> 127 /// Fires a new <c>ConstraintAdded</c> event. 128 /// </summary> 129 /// <param name="constraint">The constraint that was added.</param> 78 130 protected virtual void OnConstraintAdded(IConstraint constraint) { 79 131 if (ConstraintAdded != null) 80 132 ConstraintAdded(this, new ConstraintEventArgs(constraint)); 81 133 } 134 /// <summary> 135 /// Occurs when a constraint is removed. 136 /// </summary> 82 137 public event EventHandler<ConstraintEventArgs> ConstraintRemoved; 138 /// <summary> 139 /// Fires a new <c>ConstraintRemoved</c> event. 140 /// </summary> 141 /// <param name="constraint">The constraint that was removed.</param> 83 142 protected virtual void OnConstraintRemoved(IConstraint constraint) { 84 143 if (ConstraintRemoved != null) … … 86 145 } 87 146 88 #region Persistence Methods 147 #region Persistence Methods 148 /// <summary> 149 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 150 /// </summary> 151 /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>. <br/> 152 /// For saving the constraints a child node is created having the tag name <c>Constraints</c>. Beyond this 153 /// child node all constraints are saved as child nodes themselves.</remarks> 154 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 155 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param> 156 /// <param name="persistedObjects">The dictionary of all already persisted objects. 157 /// (Needed to avoid cycles.)</param> 158 /// <returns>The saved <see cref="XmlNode"/>.</returns> 89 159 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 90 160 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 97 167 return node; 98 168 } 169 /// <summary> 170 /// Loads the persisted item from the specified <paramref name="node"/>. 171 /// </summary> 172 /// <remarks>See <see cref="GetXmlNode"/> to get information about how the constrained item must 173 /// be saved. <br/> 174 /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks> 175 /// <param name="node">The <see cref="XmlNode"/> where the constrained item is saved.</param> 176 /// <param name="restoredObjects">The dictionary of all already restored objects. 177 /// (Needed to avoid cycles.)</param> 99 178 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 100 179 base.Populate(node, restoredObjects);
Note: See TracChangeset
for help on using the changeset viewer.