Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13695


Ignore:
Timestamp:
03/14/16 14:57:02 (8 years ago)
Author:
mkommend
Message:

#2589: Added resizable option in ValueTypeArray and refactored the array implementations and interfaces.

Location:
trunk/sources
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r13570 r13695  
    8080      lengthTextBox.Enabled = Content != null;
    8181      dataGridView.Enabled = Content != null;
    82       lengthTextBox.ReadOnly = ReadOnly;
     82      lengthTextBox.ReadOnly = ReadOnly || (Content != null && !Content.Resizable);
    8383      dataGridView.ReadOnly = ReadOnly;
    8484    }
  • trunk/sources/HeuristicLab.Data/3.3/BoolArray.cs

    r12012 r13695  
    2828  [Item("BoolArray", "Represents an array of boolean values.")]
    2929  [StorableClass]
    30   public class BoolArray : ValueTypeArray<bool>, IStringConvertibleArray {
     30  public class BoolArray : StringConvertibleArray<bool> {
    3131    [StorableConstructor]
    3232    protected BoolArray(bool deserializing) : base(deserializing) { }
     
    4242    }
    4343
    44     protected virtual bool Validate(string value, out string errorMessage) {
     44    protected override bool Validate(string value, out string errorMessage) {
    4545      bool val;
    4646      bool valid = bool.TryParse(value, out val);
     
    5555      return valid;
    5656    }
    57     protected virtual string GetValue(int index) {
     57    protected override string GetValue(int index) {
    5858      return this[index].ToString();
    5959    }
    60     protected virtual bool SetValue(string value, int index) {
     60    protected override bool SetValue(string value, int index) {
    6161      bool val;
    6262      if (bool.TryParse(value, out val)) {
     
    6767      }
    6868    }
    69 
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
    74     }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8569  }
    8670}
  • trunk/sources/HeuristicLab.Data/3.3/DoubleArray.cs

    r12432 r13695  
    2828  [Item("DoubleArray", "Represents an array of double values.")]
    2929  [StorableClass]
    30   public class DoubleArray : ValueTypeArray<double>, IStringConvertibleArray {
     30  public class DoubleArray : StringConvertibleArray<double> {
    3131    [StorableConstructor]
    3232    protected DoubleArray(bool deserializing) : base(deserializing) { }
     
    4242    }
    4343
    44     protected virtual bool Validate(string value, out string errorMessage) {
     44    protected override bool Validate(string value, out string errorMessage) {
    4545      double val;
    4646      bool valid = double.TryParse(value, out val);
     
    5555      return valid;
    5656    }
    57     protected virtual string GetValue(int index) {
     57    protected override string GetValue(int index) {
    5858      return this[index].ToString("r");
    5959    }
    60     protected virtual bool SetValue(string value, int index) {
     60    protected override bool SetValue(string value, int index) {
    6161      double val;
    6262      if (double.TryParse(value, out val)) {
     
    6767      }
    6868    }
    69 
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
    74     }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8569  }
    8670}
  • trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj

    r12037 r13695  
    124124    <Compile Include="ComparisonType.cs" />
    125125    <Compile Include="EnumValue.cs" />
     126    <Compile Include="Interfaces\IValueTypeArray.cs" />
    126127    <Compile Include="Path Types\DirectoryValue.cs" />
    127128    <Compile Include="Path Types\FileValue.cs" />
     
    148149    <Compile Include="Properties\AssemblyInfo.cs" />
    149150    <Compile Include="StringArray.cs" />
     151    <Compile Include="StringConvertibleArray.cs" />
    150152    <Compile Include="StringMatrix.cs" />
    151153    <Compile Include="StringValue.cs" />
  • trunk/sources/HeuristicLab.Data/3.3/IntArray.cs

    r12012 r13695  
    2828  [Item("IntArray", "Represents an array of integer values.")]
    2929  [StorableClass]
    30   public class IntArray : ValueTypeArray<int>, IStringConvertibleArray {
     30  public class IntArray : StringConvertibleArray<int> {
    3131    [StorableConstructor]
    3232    protected IntArray(bool deserializing) : base(deserializing) { }
     
    4242    }
    4343
    44     protected virtual bool Validate(string value, out string errorMessage) {
     44    protected override bool Validate(string value, out string errorMessage) {
    4545      int val;
    4646      bool valid = int.TryParse(value, out val);
     
    5555      return valid;
    5656    }
    57     protected virtual string GetValue(int index) {
     57    protected override string GetValue(int index) {
    5858      return this[index].ToString();
    5959    }
    60     protected virtual bool SetValue(string value, int index) {
     60    protected override bool SetValue(string value, int index) {
    6161      int val;
    6262      if (int.TryParse(value, out val)) {
     
    6767      }
    6868    }
    69 
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
    74     }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8569  }
    8670}
  • trunk/sources/HeuristicLab.Data/3.3/Interfaces/IStringConvertibleArray.cs

    r12012 r13695  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Common;
    2523
    2624namespace HeuristicLab.Data {
    27   public interface IStringConvertibleArray : IContent {
    28     int Length { get; set; }
    29     IEnumerable<string> ElementNames { get; set; }
    30 
    31     bool ReadOnly { get; }
    32 
     25  public interface IStringConvertibleArray : IContent, IValueTypeArray {
    3326    bool Validate(string value, out string errorMessage);
    3427    string GetValue(int index);
    3528    bool SetValue(string value, int index);
    36 
    37     event EventHandler ElementNamesChanged;
    38     event EventHandler<EventArgs<int>> ItemChanged;
    39     event EventHandler Reset;
    4029  }
    4130}
  • trunk/sources/HeuristicLab.Data/3.3/StringArray.cs

    r12012 r13695  
    6161    public virtual int Length {
    6262      get { return array.Length; }
    63       protected set {
     63      set {
    6464        if (ReadOnly) throw new NotSupportedException("Length cannot be set. StringArray is read-only.");
    6565        if (value != Length) {
     
    7272      }
    7373    }
     74    [Storable]
     75    protected bool resizable = true;
     76    public bool Resizable {
     77      get { return resizable; }
     78      set {
     79        if (resizable != value) {
     80          resizable = value;
     81          OnResizableChanged();
     82        }
     83      }
     84    }
     85
    7486    public virtual string this[int index] {
    7587      get { return array[index]; }
     
    102114      this.array = (string[])original.array.Clone();
    103115      this.readOnly = original.readOnly;
     116      this.resizable = original.resizable;
    104117      this.elementNames = new List<string>(original.elementNames);
    105118    }
     
    107120      array = new string[0];
    108121      readOnly = false;
     122      resizable = true;
    109123      elementNames = new List<string>();
    110124    }
     
    114128        array[i] = string.Empty;
    115129      readOnly = false;
     130      resizable = true;
    116131      elementNames = new List<string>();
    117132    }
     
    122137        array[i] = elements[i] == null ? string.Empty : elements[i];
    123138      readOnly = false;
     139      resizable = true;
    124140      elementNames = new List<string>();
    125141    }
     
    133149      readOnlyStringArray.readOnly = true;
    134150      return readOnlyStringArray;
     151    }
     152    IValueTypeArray IValueTypeArray.AsReadOnly() {
     153      return AsReadOnly();
    135154    }
    136155
     
    155174      return array.Cast<string>().GetEnumerator();
    156175    }
    157 
    158176    IEnumerator IEnumerable.GetEnumerator() {
    159177      return GetEnumerator();
     
    181199    }
    182200
     201    public event EventHandler ResizableChanged;
     202    protected virtual void OnResizableChanged() {
     203      EventHandler handler = ResizableChanged;
     204      if (handler != null)
     205        handler(this, EventArgs.Empty);
     206    }
    183207    public event EventHandler ElementNamesChanged;
    184208    protected virtual void OnElementNamesChanged() {
     
    187211        handler(this, EventArgs.Empty);
    188212    }
    189 
    190213    public event EventHandler<EventArgs<int>> ItemChanged;
    191214    protected virtual void OnItemChanged(int index) {
     
    203226
    204227    #region IStringConvertibleArray Members
    205     int IStringConvertibleArray.Length {
    206       get { return Length; }
    207       set { Length = value; }
    208     }
    209228    bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    210229      return Validate(value, out errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r12012 r13695  
    3333  [Item("ValueTypeArray", "An abstract base class for representing arrays of value types.")]
    3434  [StorableClass]
    35   public abstract class ValueTypeArray<T> : Item, IEnumerable<T> where T : struct {
     35  public abstract class ValueTypeArray<T> : Item, IValueTypeArray<T> where T : struct {
    3636    private const int maximumToStringLength = 100;
    3737
     
    7575      #endregion
    7676    }
     77
     78    [Storable]
     79    protected bool resizable = true;
     80    public bool Resizable {
     81      get { return resizable; }
     82      set {
     83        if (resizable != value) {
     84          resizable = value;
     85          OnResizableChanged();
     86        }
     87      }
     88    }
     89
     90
    7791    public virtual T this[int index] {
    7892      get { return array[index]; }
     
    103117      this.array = (T[])original.array.Clone();
    104118      this.readOnly = original.readOnly;
     119      this.resizable = original.resizable;
    105120      this.elementNames = new List<string>(original.elementNames);
    106121    }
     
    108123      array = new T[0];
    109124      readOnly = false;
     125      resizable = true;
    110126      elementNames = new List<string>();
    111127    }
     
    113129      array = new T[length];
    114130      readOnly = false;
     131      resizable = true;
    115132      elementNames = new List<string>();
    116133    }
     
    119136      array = (T[])elements.Clone();
    120137      readOnly = false;
     138      resizable = true;
    121139      elementNames = new List<string>();
    122140    }
    123141
    124     public virtual ValueTypeArray<T> AsReadOnly() {
     142    public virtual IValueTypeArray AsReadOnly() {
    125143      ValueTypeArray<T> readOnlyValueTypeArray = (ValueTypeArray<T>)this.Clone();
    126144      readOnlyValueTypeArray.readOnly = true;
     
    153171    }
    154172
     173    public event EventHandler ResizableChanged;
     174    protected virtual void OnResizableChanged() {
     175      EventHandler handler = ResizableChanged;
     176      if (handler != null)
     177        handler(this, EventArgs.Empty);
     178    }
    155179    public event EventHandler ElementNamesChanged;
    156180    protected virtual void OnElementNamesChanged() {
Note: See TracChangeset for help on using the changeset viewer.