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 | 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 | }
|
---|