[13534] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13534] | 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;
|
---|
| 23 | using System.Globalization;
|
---|
| 24 | using System.Text.RegularExpressions;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Clients.OKB.RunCreation {
|
---|
| 27 | public partial class Value {
|
---|
[13550] | 28 | public virtual string GetValue() {
|
---|
| 29 | return string.Empty;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[13534] | 32 | public static Value Create(string name, string strValue, string type) {
|
---|
| 33 | switch (type) {
|
---|
| 34 | case "BoolValue": return new BoolValue() {
|
---|
| 35 | Name = name,
|
---|
| 36 | Value = bool.Parse(strValue)
|
---|
[13666] | 37 | };
|
---|
[13534] | 38 | case "IntValue": return new IntValue() {
|
---|
| 39 | Name = name,
|
---|
| 40 | Value = int.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
|
---|
[13666] | 41 | };
|
---|
[13534] | 42 | case "LongValue": return new LongValue() {
|
---|
| 43 | Name = name,
|
---|
| 44 | Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
|
---|
[13666] | 45 | };
|
---|
[13534] | 46 | case "FloatValue": return new FloatValue() {
|
---|
| 47 | Name = name,
|
---|
| 48 | Value = float.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
|
---|
[13666] | 49 | };
|
---|
[13534] | 50 | case "DoubleValue": return new DoubleValue() {
|
---|
| 51 | Name = name,
|
---|
| 52 | Value = double.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
|
---|
[13666] | 53 | };
|
---|
[13534] | 54 | case "PercentValue": return new PercentValue() {
|
---|
| 55 | Name = name,
|
---|
| 56 | Value = double.Parse(Regex.Match(strValue, "[0-9.,]+").Value, CultureInfo.CurrentCulture.NumberFormat) / 100.0
|
---|
[13666] | 57 | };
|
---|
[13534] | 58 | case "StringValue": return new StringValue() {
|
---|
| 59 | Name = name,
|
---|
| 60 | Value = strValue
|
---|
[13666] | 61 | };
|
---|
[13534] | 62 | case "TimeSpanValue": return new TimeSpanValue() {
|
---|
| 63 | Name = name,
|
---|
| 64 | Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
|
---|
[13666] | 65 | };
|
---|
[13534] | 66 | default: throw new ArgumentException(string.Format("type {0} is unknown", type), "type");
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|