Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Data/3.3/BoolValue.cs @ 16437

Last change on this file since 16437 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 3.3 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[3306]23using System.Drawing;
[2]24using System.Text;
[3376]25using HeuristicLab.Common;
[2]26using HeuristicLab.Core;
[1853]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2]28
29namespace HeuristicLab.Data {
[3048]30  [Item("BoolValue", "Represents a boolean value.")]
[3017]31  [StorableClass]
[3054]32  public class BoolValue : ValueTypeValue<bool>, IComparable, IStringConvertibleValue {
[7201]33    public static new Image StaticItemImage {
[5287]34      get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
[3306]35    }
36
[4722]37    protected BoolValue(BoolValue original, Cloner cloner)
38      : base(original, cloner) {
39    }
[3048]40    public BoolValue() : base() { }
[4722]41    [StorableConstructor]
42    public BoolValue(bool value)
43      : base(value) {
44      //mkommend: Be aware that the base call refers to the storable ctor => the value is set explicitly in the ctor body.
45      //          This should not affect the persistence, because first the ctor is called and afterwards the values are set by reflection.
46      this.value = value;
47    }
[2]48
[2665]49    public override IDeepCloneable Clone(Cloner cloner) {
[4722]50      return new BoolValue(this, cloner);
[2]51    }
[2665]52
[3054]53    public virtual int CompareTo(object obj) {
[3048]54      BoolValue other = obj as BoolValue;
[2757]55      if (other != null)
56        return Value.CompareTo(other.Value);
57      else
58        return Value.CompareTo(obj);
59    }
60
[3054]61    protected virtual bool Validate(string value, out string errorMessage) {
[2694]62      bool val;
63      bool valid = bool.TryParse(value, out val);
64      errorMessage = string.Empty;
65      if (!valid) {
66        StringBuilder sb = new StringBuilder();
67        sb.Append("Invalid Value (Valid Value Format: \"");
68        sb.Append(FormatPatterns.GetBoolFormatPattern());
69        sb.Append("\")");
70        errorMessage = sb.ToString();
71      }
72      return valid;
[2676]73    }
[3054]74    protected virtual string GetValue() {
[2665]75      return Value.ToString();
76    }
[3054]77    protected virtual bool SetValue(string value) {
[2694]78      bool val;
79      if (bool.TryParse(value, out val)) {
80        Value = val;
[2665]81        return true;
82      } else {
83        return false;
84      }
85    }
[3054]86
87    #region IStringConvertibleValue Members
88    bool IStringConvertibleValue.Validate(string value, out string errorMessage) {
89      return Validate(value, out errorMessage);
90    }
91    string IStringConvertibleValue.GetValue() {
92      return GetValue();
93    }
94    bool IStringConvertibleValue.SetValue(string value) {
95      return SetValue(value);
96    }
[2676]97    #endregion
[2]98  }
99}
Note: See TracBrowser for help on using the repository browser.