- Timestamp:
- 05/04/10 13:38:35 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3/Constraints
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Constraints/Constraint.cs
r3601 r3602 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Core;27 26 using HeuristicLab.Common; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab. Data{29 namespace HeuristicLab.Core { 31 30 [StorableClass] 32 31 public abstract class Constraint : Item, IConstraint { 33 /// <summary>34 /// Protected default constructor for constructor chaining, cloning and persisting of constraints.35 /// </summary>32 protected Constraint() { 33 this.Active = false; 34 } 36 35 [StorableConstructor] 37 protected Constraint() { 38 this.Active = true; 36 protected Constraint(bool deserializing) { 39 37 } 40 41 public Constraint(IItem constrainedValue,ComparisonOperation comparisonOperation, object comparisonValue) 38 protected Constraint(IItem constrainedValue, ConstraintOperation comparisonOperation, object comparisonValue) 42 39 : this() { 43 40 this.ConstrainedValue = constrainedValue; 44 this.ComparisonOperation = comparisonOperation; 45 this.ComparisonValue = comparisonValue; 41 this.ConstraintOperation = comparisonOperation; 42 this.ConstraintData = comparisonValue; 43 } 44 protected Constraint(IItem constrainedValue, ConstraintOperation comparisonOperation, object comparisonValue, bool active) { 45 this.ConstrainedValue = constrainedValue; 46 this.ConstraintOperation = comparisonOperation; 47 this.ConstraintData = comparisonValue; 48 this.Active = active; 46 49 } 47 50 … … 73 76 74 77 [Storable] 75 private object co mparisonValue;76 public object Co mparisonValue{77 get { return this.co mparisonValue; }78 private object constraintData; 79 public object ConstraintData { 80 get { return this.constraintData; } 78 81 set { 79 if (this.co mparisonValue!= value) {80 this.co mparisonValue= value;81 this.OnCo mparisonValueChanged();82 if (this.constraintData != value) { 83 this.constraintData = value; 84 this.OnConstraintDataChanged(); 82 85 this.OnToStringChanged(); 83 86 } … … 85 88 } 86 89 87 public abstract IEnumerable<Co mparisonOperation> AllowedComparisonOperations { get; }90 public abstract IEnumerable<ConstraintOperation> AllowedConstraintOperations { get; } 88 91 [Storable] 89 private Co mparisonOperation comparisonOperation;90 public Co mparisonOperation ComparisonOperation {91 get { return this.co mparisonOperation; }92 private ConstraintOperation constraintOperation; 93 public ConstraintOperation ConstraintOperation { 94 get { return this.constraintOperation; } 92 95 set { 93 96 if (value == null) 94 97 throw new ArgumentNullException("Comparison operation cannot be null."); 95 if (!AllowedCo mparisonOperations.Contains(value))98 if (!AllowedConstraintOperations.Contains(value)) 96 99 throw new ArgumentException("Comparison operation is not contained in the allowed ComparisonOperations."); 97 if (this.co mparisonOperation != value) {98 this.co mparisonOperation = value;99 this.OnCo mparisonOperationChanged();100 if (this.constraintOperation != value) { 101 this.constraintOperation = value; 102 this.OnConstraintOperationChanged(); 100 103 this.OnToStringChanged(); 101 104 } … … 119 122 protected abstract bool Check(object constrainedMember); 120 123 124 public bool Check(out string errorMessage) { 125 errorMessage = string.Empty; 126 if (!Active) 127 return true; 128 129 IItem constrainedMember = this.GetConstrainedMember(); 130 return this.Check(constrainedMember, out errorMessage); 131 } 132 133 protected abstract bool Check(object constrainedMember, out string errorMessage); 134 121 135 #region events 122 136 public event EventHandler ActiveChanged; … … 127 141 } 128 142 129 public event EventHandler Co mparisonValueChanged;130 protected virtual void OnCo mparisonValueChanged() {131 EventHandler handler = Co mparisonValueChanged;143 public event EventHandler ConstraintDataChanged; 144 protected virtual void OnConstraintDataChanged() { 145 EventHandler handler = ConstraintDataChanged; 132 146 if (handler != null) 133 147 ActiveChanged(this, EventArgs.Empty); 134 148 } 135 149 136 public event EventHandler Co mparisonOperationChanged;137 protected virtual void OnCo mparisonOperationChanged() {138 EventHandler handler = Co mparisonOperationChanged;150 public event EventHandler ConstraintOperationChanged; 151 protected virtual void OnConstraintOperationChanged() { 152 EventHandler handler = ConstraintOperationChanged; 139 153 if (handler != null) 140 154 ActiveChanged(this, EventArgs.Empty); … … 151 165 return "Could not determine constraint value."; 152 166 153 s += " " + comparisonOperation.ToString() + " ";167 s += " " + ConstraintOperation.ToString() + " "; 154 168 155 if (co mparisonValue!= null)156 s += co mparisonValue.ToString();169 if (constraintData != null) 170 s += constraintData.ToString(); 157 171 else 158 172 s += "null"; … … 166 180 clone.constrainedValue = (IItem)cloner.Clone(this.constrainedValue); 167 181 168 IItem comparisonItem = this.comparisonValue as IItem; 169 if (comparisonItem != null) 170 clone.comparisonValue = (IItem)cloner.Clone(comparisonItem); 182 IItem constraintDataItem = this.constraintData as IItem; 183 ICloneable constraintDataCloneable = this.constraintData as ICloneable; 184 if (constraintDataItem != null) 185 clone.constraintData = cloner.Clone(constraintDataItem); 186 else if (constraintDataCloneable != null) 187 clone.constraintData = constraintDataCloneable.Clone(); 171 188 else 172 clone.comparisonValue = comparisonValue; 173 clone.comparisonOperation = this.comparisonOperation; 189 clone.constraintData = constraintData; 190 191 clone.constraintOperation = this.constraintOperation; 174 192 175 193 return clone;
Note: See TracChangeset
for help on using the changeset viewer.