[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 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 |
|
---|
| 22 | using System;
|
---|
[3306] | 23 | using System.Drawing;
|
---|
[2] | 24 | using System.Text;
|
---|
[3376] | 25 | using HeuristicLab.Common;
|
---|
[2] | 26 | using HeuristicLab.Core;
|
---|
[14927] | 27 | using HeuristicLab.Persistence;
|
---|
[2] | 28 |
|
---|
| 29 | namespace HeuristicLab.Data {
|
---|
[3048] | 30 | [Item("BoolValue", "Represents a boolean value.")]
|
---|
[14927] | 31 | [StorableType("0f5f44a0-96a2-41a8-a61d-b6ae355f71c9")]
|
---|
[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() { }
|
---|
[15018] | 41 |
|
---|
[4722] | 42 | [StorableConstructor]
|
---|
[15018] | 43 | public BoolValue(StorableConstructorFlag deserializing) : base(deserializing) {
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public BoolValue(bool value) {
|
---|
[4722] | 47 | this.value = value;
|
---|
| 48 | }
|
---|
[2] | 49 |
|
---|
[2665] | 50 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 51 | return new BoolValue(this, cloner);
|
---|
[2] | 52 | }
|
---|
[2665] | 53 |
|
---|
[3054] | 54 | public virtual int CompareTo(object obj) {
|
---|
[3048] | 55 | BoolValue other = obj as BoolValue;
|
---|
[2757] | 56 | if (other != null)
|
---|
| 57 | return Value.CompareTo(other.Value);
|
---|
| 58 | else
|
---|
| 59 | return Value.CompareTo(obj);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[3054] | 62 | protected virtual bool Validate(string value, out string errorMessage) {
|
---|
[2694] | 63 | bool val;
|
---|
| 64 | bool valid = bool.TryParse(value, out val);
|
---|
| 65 | errorMessage = string.Empty;
|
---|
| 66 | if (!valid) {
|
---|
| 67 | StringBuilder sb = new StringBuilder();
|
---|
| 68 | sb.Append("Invalid Value (Valid Value Format: \"");
|
---|
| 69 | sb.Append(FormatPatterns.GetBoolFormatPattern());
|
---|
| 70 | sb.Append("\")");
|
---|
| 71 | errorMessage = sb.ToString();
|
---|
| 72 | }
|
---|
| 73 | return valid;
|
---|
[2676] | 74 | }
|
---|
[3054] | 75 | protected virtual string GetValue() {
|
---|
[2665] | 76 | return Value.ToString();
|
---|
| 77 | }
|
---|
[3054] | 78 | protected virtual bool SetValue(string value) {
|
---|
[2694] | 79 | bool val;
|
---|
| 80 | if (bool.TryParse(value, out val)) {
|
---|
| 81 | Value = val;
|
---|
[2665] | 82 | return true;
|
---|
| 83 | } else {
|
---|
| 84 | return false;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
[3054] | 87 |
|
---|
| 88 | #region IStringConvertibleValue Members
|
---|
| 89 | bool IStringConvertibleValue.Validate(string value, out string errorMessage) {
|
---|
| 90 | return Validate(value, out errorMessage);
|
---|
| 91 | }
|
---|
| 92 | string IStringConvertibleValue.GetValue() {
|
---|
| 93 | return GetValue();
|
---|
| 94 | }
|
---|
| 95 | bool IStringConvertibleValue.SetValue(string value) {
|
---|
| 96 | return SetValue(value);
|
---|
| 97 | }
|
---|
[2676] | 98 | #endregion
|
---|
[2] | 99 | }
|
---|
| 100 | }
|
---|