Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Data/3.3/ValueTypeValue.cs @ 3054

Last change on this file since 3054 was 3054, checked in by swagner, 14 years ago

Refactored classes of HeuristicLab.Data and implemented encoding specific data classes (#909)

File size: 2.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Data {
27  [Item("ValueTypeValue<T>", "An abstract base class for representing values of value types.")]
28  [StorableClass]
29  public abstract class ValueTypeValue<T> : Item where T : struct {
30    [Storable]
31    protected T value;
32    public virtual T Value {
33      get { return value; }
34      set {
35        if (!value.Equals(this.value)) {
36          this.value = value;
37          OnValueChanged();
38        }
39      }
40    }
41
42    protected ValueTypeValue() {
43      this.value = default(T);
44    }
45    protected ValueTypeValue(T value) {
46      this.value = value;
47    }
48
49    public override IDeepCloneable Clone(Cloner cloner) {
50      ValueTypeValue<T> clone = (ValueTypeValue<T>)base.Clone(cloner);
51      clone.value = value;
52      return clone;
53    }
54
55    public override string ToString() {
56      return value.ToString();
57    }
58
59    public event EventHandler ValueChanged;
60    protected virtual void OnValueChanged() {
61      if (ValueChanged != null)
62        ValueChanged(this, EventArgs.Empty);
63      OnToStringChanged();
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.