Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/22/10 03:29:02 (14 years ago)
Author:
swagner
Message:

Continued work on adapting and refactoring HeuristicLab.Data according to the changes in HeuristicLab.Core (#95)

File:
1 edited

Legend:

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

    r2520 r2669  
    2525using System.Xml;
    2626using HeuristicLab.Core;
    27 using System.Globalization;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    3029namespace HeuristicLab.Data {
    31   /// <summary>
    32   /// The representation of an array of integer values.
    33   /// </summary>
    3430  [EmptyStorableClass]
    35   public class IntArrayData : ArrayDataBase {
    36     /// <summary>
    37     /// Gets or sets the int elements of the array.
    38     /// </summary>
    39     /// <remarks>Uses property <see cref="ArrayDataBase.Data"/> of base class <see cref="ArrayDataBase"/>.
    40     /// No own data storage present.</remarks>
    41     public new int[] Data {
    42       get { return (int[])base.Data; }
    43       set { base.Data = value; }
     31  [Item("IntArrayData", "Represents an array of integer values.")]
     32  [Creatable("Test")]
     33  public sealed class IntArrayData : ValueTypeArrayData<int>, IStringConvertibleArrayData {
     34    public IntArrayData() : base() { }
     35    public IntArrayData(int length) : base(length) { }
     36    public IntArrayData(IntArrayData elements) : base(elements) { }
     37    public IntArrayData(int[] elements) : base(elements) { }
     38
     39    public override IDeepCloneable Clone(Cloner cloner) {
     40      IntArrayData clone = new IntArrayData(this);
     41      cloner.RegisterClonedObject(this, clone);
     42      return clone;
    4443    }
    4544
    46     /// <summary>
    47     /// Initializes a new instance of <see cref="IntArrayData"/>.
    48     /// </summary>
    49     public IntArrayData() {
    50       Data = new int[0];
     45    int IStringConvertibleArrayData.Length {
     46      get { return Length; }
     47      set { Length = value; }
    5148    }
    52     /// <summary>
    53     /// Initializes a new instance of <see cref="IntArrayData"/>.
    54     /// <note type="caution"> No CopyConstructor! <paramref name="data"/> is not copied!</note>
    55     /// </summary>
    56     /// <param name="data">The array of integers to represent.</param>
    57     public IntArrayData(int[] data) {
    58       Data = data;
     49    string IStringConvertibleArrayData.GetValue(int index) {
     50      return this[index].ToString();
    5951    }
    60 
    61     /// <summary>
    62     /// The string representation of the array, formatted according to the given <paramref name="format"/>.
    63     /// </summary>
    64     /// <param name="format">The <see cref="NumberFormatInfo"></see> the single int values
    65     /// should be formatted accordingly.</param>
    66     /// <returns>The elements of the array as string, each element separated by a semicolon
    67     /// and formatted according to the parameter <paramref name="format"/>.</returns>
    68     private string ToString(NumberFormatInfo format) {
    69       StringBuilder builder = new StringBuilder();
    70       for (int i = 0; i < Data.Length; i++) {
    71         builder.Append(";");
    72         builder.Append(Data[i].ToString(format));
     52    bool IStringConvertibleArrayData.SetValue(string value, int index) {
     53      int i;
     54      if (int.TryParse(value, out i)) {
     55        this[index] = i;
     56        return true;
     57      } else {
     58        return false;
    7359      }
    74       if (builder.Length > 0) builder.Remove(0, 1);
    75       return builder.ToString();
    7660    }
    7761  }
Note: See TracChangeset for help on using the changeset viewer.