Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/Value.cs @ 13534

Last change on this file since 13534 was 13534, checked in by abeham, 8 years ago

#2560:

  • Updated clients (moving of all characteristic service methods to run creation service)
  • Adapted OKB problem view to display characteristic values for the instances
File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 System.Globalization;
24using System.Text.RegularExpressions;
25
26namespace HeuristicLab.Clients.OKB.RunCreation {
27  public partial class Value {
28    public static Value Create(string name, string strValue, string type) {
29      switch (type) {
30        case "BoolValue": return new BoolValue() {
31          Name = name,
32          Value = bool.Parse(strValue)
33        }; break;
34        case "IntValue": return new IntValue() {
35          Name = name,
36          Value = int.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
37        }; break;
38        case "LongValue": return new LongValue() {
39          Name = name,
40          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
41        }; break;
42        case "FloatValue": return new FloatValue() {
43          Name = name,
44          Value = float.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
45        }; break;
46        case "DoubleValue": return new DoubleValue() {
47          Name = name,
48          Value = double.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
49        }; break;
50        case "PercentValue": return new PercentValue() {
51          Name = name,
52          Value = double.Parse(Regex.Match(strValue, "[0-9.,]+").Value, CultureInfo.CurrentCulture.NumberFormat) / 100.0
53        }; break;
54        case "StringValue": return new StringValue() {
55          Name = name,
56          Value = strValue
57        }; break;
58        case "TimeSpanValue": return new TimeSpanValue() {
59          Name = name,
60          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
61        }; break;
62        default: throw new ArgumentException(string.Format("type {0} is unknown", type), "type");
63      }
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.