Free cookie consent management tool by TermsFeed Policy Generator

source: branches/StackingProblems/HeuristicLab.Data.MoveVectorData/3.3/MoveValue.cs @ 14278

Last change on this file since 14278 was 14278, checked in by mzehetho, 8 years ago

Initial Commit for ticket #2605

Implemented:

  • Encoding
  • Moves
  • Views
  • Blocks World Problem
  • Blocks Relocation Problem
  • Stacking Problem
File size: 2.1 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data.MoveVectorData.Interfaces;
4using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5
6namespace HeuristicLab.Data.MoveVectorData
7{
8    [Item("MoveValue", "Represents a move value.")]
9    [StorableClass]
10    public class MoveValue<T> : ValueTypeValue<T>, IStringConvertibleValue where T : struct, IMove
11    {
12
13        #region Cloning
14        [StorableConstructor]
15        protected MoveValue(bool deserializing) : base(deserializing) { }
16        protected MoveValue(MoveValue<T> original, Cloner cloner) : base(original, cloner) { }
17        public override IDeepCloneable Clone(Cloner cloner)
18        {
19            return new MoveValue<T>(this, cloner);
20        }
21        #endregion
22
23        public MoveValue() : base() { }
24        public MoveValue(T value) : base(value) { }
25
26        protected virtual bool Validate(string value, out string errorMessage)
27        {
28            T val = new T();
29            bool valid = val.TryParse(value);
30            errorMessage = string.Empty;
31            if (!valid)
32            {
33                errorMessage = "Invalid TwoPointMove Format";
34            }
35            return valid;
36        }
37
38        protected virtual string GetValue()
39        {
40            return Value.ToString();
41        }
42
43        protected virtual bool SetValue(string value)
44        {
45            T val = new T();
46            if (val.TryParse(value))
47            {
48                Value = val;
49                return true;
50            }
51            else {
52                return false;
53            }
54        }
55
56        #region IStringConvertibleValue Members
57        bool IStringConvertibleValue.Validate(string value, out string errorMessage)
58        {
59            return Validate(value, out errorMessage);
60        }
61        string IStringConvertibleValue.GetValue()
62        {
63            return GetValue();
64        }
65        bool IStringConvertibleValue.SetValue(string value)
66        {
67            return SetValue(value);
68        }
69        #endregion
70    }
71}
Note: See TracBrowser for help on using the repository browser.