[5112] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Common;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 8 | using HeuristicLab.Data;
|
---|
| 9 |
|
---|
| 10 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
| 11 | [StorableClass]
|
---|
| 12 | public class ConstrainedValue : Item {
|
---|
| 13 | [Storable]
|
---|
| 14 | protected Type valueDataType;
|
---|
| 15 | public Type ValueDataType {
|
---|
| 16 | get { return this.valueDataType; }
|
---|
| 17 | protected set { this.valueDataType = value; }
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | [Storable]
|
---|
| 21 | protected IItem value;
|
---|
| 22 | public IItem Value {
|
---|
| 23 | get { return value; }
|
---|
| 24 | set {
|
---|
| 25 | if (this.value != value) {
|
---|
| 26 | if(this.value != null) DeregisterEvents();
|
---|
| 27 | this.value = value;
|
---|
| 28 | if(this.value != null) RegisterEvents();
|
---|
| 29 | OnToStringChanged();
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | [Storable]
|
---|
[5231] | 35 | protected IItemSet<IItem> validValues;
|
---|
| 36 | public IItemSet<IItem> ValidValues {
|
---|
| 37 | get { return validValues; }
|
---|
[5112] | 38 | protected set {
|
---|
[5231] | 39 | if (this.validValues != value) {
|
---|
| 40 | this.validValues = value;
|
---|
[5112] | 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | [Storable]
|
---|
| 46 | protected bool isNullable;
|
---|
| 47 | public bool IsNullable {
|
---|
| 48 | get { return isNullable; }
|
---|
| 49 | protected set {
|
---|
| 50 | if (this.isNullable != value) {
|
---|
| 51 | this.isNullable = value;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private void RegisterEvents() {
|
---|
| 57 | this.value.ToStringChanged += new EventHandler(value_ToStringChanged);
|
---|
| 58 | }
|
---|
| 59 | private void DeregisterEvents() {
|
---|
| 60 | this.value.ToStringChanged -= new EventHandler(value_ToStringChanged);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | #region constructors and cloning
|
---|
| 64 | public ConstrainedValue() { }
|
---|
| 65 | [StorableConstructor]
|
---|
| 66 | protected ConstrainedValue(bool deserializing) : base(deserializing) { }
|
---|
[5231] | 67 | public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable) {
|
---|
[5112] | 68 | this.Value = value;
|
---|
| 69 | this.ValueDataType = valueDataType;
|
---|
[5231] | 70 | this.ValidValues = validValues;
|
---|
[5112] | 71 | this.isNullable = isNullable;
|
---|
| 72 | }
|
---|
| 73 | protected ConstrainedValue(ConstrainedValue original, Cloner cloner) : base(original, cloner) {
|
---|
| 74 | this.valueDataType = original.valueDataType;
|
---|
| 75 | this.Value = cloner.Clone(original.value);
|
---|
[5231] | 76 | if(original.ValidValues != null) this.ValidValues = cloner.Clone(original.ValidValues);
|
---|
[5112] | 77 | this.isNullable = original.isNullable;
|
---|
| 78 | }
|
---|
| 79 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 80 | return new ConstrainedValue(this, cloner);
|
---|
| 81 | }
|
---|
| 82 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 83 | private void AfterDeserialization() {
|
---|
| 84 | if (this.value != null) RegisterEvents();
|
---|
| 85 | }
|
---|
| 86 | #endregion
|
---|
| 87 |
|
---|
[5522] | 88 | private void value_ToStringChanged(object sender, EventArgs e) {
|
---|
[5112] | 89 | OnToStringChanged();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public override string ToString() {
|
---|
| 93 | return value != null ? value.ToString() : base.ToString();
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|