Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215 worked on metaoptimization

File size: 1.8 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    public ConstrainedValue() { }
42    public ConstrainedValue(IItem value, Type valueDataType) {
43      this.Value = value;
44      this.ValueDataType = valueDataType;
45    }
46    protected ConstrainedValue(ConstrainedValue original, Cloner cloner) : base(original, cloner) {
47      this.valueDataType = original.valueDataType;
48      this.value = cloner.Clone(value);
49    }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new ConstrainedValue(this, cloner);
52    }
53
54    void value_ToStringChanged(object sender, EventArgs e) {
55      OnToStringChanged();
56    }
57
58    public override string ToString() {
59      return value != null ? value.ToString() : base.ToString();
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.