Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/ConstrainedValue.cs @ 5009

Last change on this file since 5009 was 5009, checked in by cneumuel, 13 years ago

#1215 worked on metaoptimization

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Data;
9
10namespace 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    private void RegisterEvents() {
35      this.value.ToStringChanged += new EventHandler(value_ToStringChanged);
36    }
37    private void DeregisterEvents() {
38      this.value.ToStringChanged -= new EventHandler(value_ToStringChanged);
39    }
40
41    #region constructors and cloning
42    public ConstrainedValue() { }
43    [StorableConstructor]
44    protected ConstrainedValue(bool deserializing) : base(deserializing) { }
45    public ConstrainedValue(IItem value, Type valueDataType) {
46      this.Value = value;
47      this.ValueDataType = valueDataType;
48    }
49    protected ConstrainedValue(ConstrainedValue original, Cloner cloner) : base(original, cloner) {
50      this.valueDataType = original.valueDataType;
51      this.Value = cloner.Clone(original.value);
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new ConstrainedValue(this, cloner);
55    }
56    [StorableHook(HookType.AfterDeserialization)]
57    private void AfterDeserialization() {
58      if (this.value != null) RegisterEvents();
59    }
60    #endregion
61
62    void value_ToStringChanged(object sender, EventArgs e) {
63      OnToStringChanged();
64    }
65
66    public override string ToString() {
67      return value != null ? value.ToString() : base.ToString();
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.