Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/BoolArray.cs @ 17309

Last change on this file since 17309 was 17309, checked in by abeham, 5 years ago

#2521: Refactored maximization property for multi-objective problems

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Collections.Generic;
23using System.Text;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.Data {
29  [Item("BoolArray", "Represents an array of boolean values.")]
30  [StorableType("CBDDC242-3F94-4CA0-B2A8-E3B10F07DFB8")]
31  public class BoolArray : StringConvertibleArray<bool> {
32    [StorableConstructor]
33    protected BoolArray(StorableConstructorFlag _) : base(_) { }
34    protected BoolArray(BoolArray original, Cloner cloner)
35      : base(original, cloner) {
36    }
37    public BoolArray() : base() { }
38    public BoolArray(int length) : base(length) { }
39    public BoolArray(bool[] elements, bool @readonly = false) : base(elements, @readonly) { }
40    public BoolArray(IReadOnlyList<bool> elements) : base(elements) { }
41
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new BoolArray(this, cloner);
44    }
45
46    protected override bool Validate(string value, out string errorMessage) {
47      bool val;
48      bool valid = bool.TryParse(value, out val);
49      errorMessage = string.Empty;
50      if (!valid) {
51        StringBuilder sb = new StringBuilder();
52        sb.Append("Invalid Value (Valid Value Format: \"");
53        sb.Append(FormatPatterns.GetBoolFormatPattern());
54        sb.Append("\")");
55        errorMessage = sb.ToString();
56      }
57      return valid;
58    }
59    protected override string GetValue(int index) {
60      return this[index].ToString();
61    }
62    protected override bool SetValue(string value, int index) {
63      bool val;
64      if (bool.TryParse(value, out val)) {
65        this[index] = val;
66        return true;
67      } else {
68        return false;
69      }
70    }
71
72    public new BoolArray AsReadOnly() {
73      return (BoolArray)base.AsReadOnly();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.