Changeset 3430


Ignore:
Timestamp:
04/20/10 02:02:39 (11 years ago)
Author:
swagner
Message:

Added ReadOnly property to all items of HeuristicLab.Data (#969)

Location:
trunk/sources
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r3384 r3430  
    5757HeuristicLab.Random\3.3:HeuristicLab.Random-3.3.dll
    5858HeuristicLab.Selection\3.3:HeuristicLab.Selection-3.3.dll
    59 HeuristicLab.Selection.OffspringSelection\3.3:HeuristicLab.Selection.OffspringSelection-3.3.dll
    6059HeuristicLab.SequentialEngine\3.3:HeuristicLab.SequentialEngine-3.3.dll
    6160HeuristicLab.TestFunctions\3.3:HeuristicLab.TestFunctions-3.3.dll
  • trunk/sources/HeuristicLab.Data.Views/3.3/BoolValueView.cs

    r3362 r3430  
    3232      get { return (BoolValue)base.Content; }
    3333      set { base.Content = value; }
     34    }
     35
     36    public override bool ReadOnly {
     37      get {
     38        if ((Content != null) && Content.ReadOnly) return true;
     39        return base.ReadOnly;
     40      }
     41      set { base.ReadOnly = value; }
    3442    }
    3543
     
    8290
    8391    private void valueCheckBox_CheckedChanged(object sender, EventArgs e) {
    84       Content.Value = valueCheckBox.Checked;
     92      if (!Content.ReadOnly) Content.Value = valueCheckBox.Checked;
    8593    }
    8694  }
  • trunk/sources/HeuristicLab.Data.Views/3.3/ComparisonView.cs

    r3362 r3430  
    3232      get { return (Comparison)base.Content; }
    3333      set { base.Content = value; }
     34    }
     35
     36    public override bool ReadOnly {
     37      get {
     38        if ((Content != null) && Content.ReadOnly) return true;
     39        return base.ReadOnly;
     40      }
     41      set { base.ReadOnly = value; }
    3442    }
    3543
     
    8290
    8391    private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    84       if (Content != null) Content.Value = (ComparisonType)valueComboBox.SelectedItem;
     92      if ((Content != null) && !Content.ReadOnly) Content.Value = (ComparisonType)valueComboBox.SelectedItem;
    8593    }
    8694  }
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r3362 r3430  
    3535      get { return (IStringConvertibleArray)base.Content; }
    3636      set { base.Content = value; }
     37    }
     38
     39    public override bool ReadOnly {
     40      get {
     41        if ((Content != null) && Content.ReadOnly) return true;
     42        return base.ReadOnly;
     43      }
     44      set { base.ReadOnly = value; }
    3745    }
    3846
     
    133141    }
    134142    private void lengthTextBox_Validated(object sender, EventArgs e) {
    135       Content.Length = int.Parse(lengthTextBox.Text);
     143      if (!Content.ReadOnly) Content.Length = int.Parse(lengthTextBox.Text);
    136144      errorProvider.SetError(lengthTextBox, string.Empty);
    137145    }
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r3362 r3430  
    3434  [Content(typeof(IStringConvertibleMatrix), true)]
    3535  public partial class StringConvertibleMatrixView : AsynchronousContentView {
     36    private int[] virtualRowIndizes;
     37    private List<KeyValuePair<int, SortOrder>> sortedColumnIndizes;
     38    private RowComparer rowComparer;
     39
    3640    public new IStringConvertibleMatrix Content {
    3741      get { return (IStringConvertibleMatrix)base.Content; }
     
    3943    }
    4044
    41     private int[] virtualRowIndizes;
    42     private List<KeyValuePair<int, SortOrder>> sortedColumnIndizes;
    43     RowComparer rowComparer;
     45    public override bool ReadOnly {
     46      get {
     47        if ((Content != null) && Content.ReadOnly) return true;
     48        return base.ReadOnly;
     49      }
     50      set { base.ReadOnly = value; }
     51    }
    4452
    4553    public StringConvertibleMatrixView() {
     
    6674      base.DeregisterContentEvents();
    6775    }
    68 
    6976    protected override void RegisterContentEvents() {
    7077      base.RegisterContentEvents();
     
    7582      Content.ReadOnlyViewChanged += new EventHandler(Content_ReadOnlyViewChanged);
    7683    }
    77 
    7884
    7985    protected override void OnContentChanged() {
     
    204210    }
    205211    private void rowsTextBox_Validated(object sender, EventArgs e) {
    206       int textBoxValue = int.Parse(rowsTextBox.Text);
    207       if (textBoxValue != Content.Rows)
    208         Content.Rows = textBoxValue;
     212      if (!Content.ReadOnly) Content.Rows = int.Parse(rowsTextBox.Text);
    209213      errorProvider.SetError(rowsTextBox, string.Empty);
    210214    }
     
    226230    }
    227231    private void columnsTextBox_Validated(object sender, EventArgs e) {
    228       int textBoxValue = int.Parse(columnsTextBox.Text);
    229       if (textBoxValue != Content.Columns)
    230         Content.Columns = textBoxValue;
     232      if (!Content.ReadOnly) Content.Columns = int.Parse(columnsTextBox.Text);
    231233      errorProvider.SetError(columnsTextBox, string.Empty);
    232234    }
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleValueView.cs

    r3402 r3430  
    3333      get { return (IStringConvertibleValue)base.Content; }
    3434      set { base.Content = value; }
     35    }
     36
     37    public override bool ReadOnly {
     38      get {
     39        if ((Content != null) && Content.ReadOnly) return true;
     40        return base.ReadOnly;
     41      }
     42      set { base.ReadOnly = value; }
    3543    }
    3644
     
    103111    }
    104112    private void valueTextBox_Validated(object sender, EventArgs e) {
    105       Content.SetValue(valueTextBox.Text);
     113      if (!Content.ReadOnly) Content.SetValue(valueTextBox.Text);
    106114      errorProvider.SetError(valueTextBox, string.Empty);
    107115      valueTextBox.Text = Content.GetValue();
  • trunk/sources/HeuristicLab.Data/3.3/BoolArray.cs

    r3376 r3430  
    3737      cloner.RegisterClonedObject(this, clone);
    3838      clone.ReadOnlyView = ReadOnlyView;
     39      clone.readOnly = readOnly;
    3940      return clone;
    4041    }
  • trunk/sources/HeuristicLab.Data/3.3/BoolMatrix.cs

    r3376 r3430  
    3030  [StorableClass]
    3131  public class BoolMatrix : ValueTypeMatrix<bool>, IStringConvertibleMatrix {
    32         public BoolMatrix() : base() { }
     32    public BoolMatrix() : base() { }
    3333    public BoolMatrix(int rows, int columns) : base(rows, columns) { }
    3434    public BoolMatrix(int rows, int columns, IEnumerable<string> columnNames) : base(rows, columns, columnNames) { }
     
    3939
    4040    public override IDeepCloneable Clone(Cloner cloner) {
    41       BoolMatrix clone = new BoolMatrix(matrix);
     41      BoolMatrix clone = new BoolMatrix();
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
    44       clone.ColumnNames = new List<string>(ColumnNames);
    45       clone.RowNames = new List<string>(RowNames);
     44      clone.matrix = (bool[,])matrix.Clone();
     45      clone.columnNames = new List<string>(columnNames);
     46      clone.rowNames = new List<string>(rowNames);
     47      clone.sortableView = sortableView;
     48      clone.readOnly = readOnly;
    4649      return clone;
    4750    }
     
    8285      set { Columns = value; }
    8386    }
    84     IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    85       get { return this.ColumnNames; }
    86       set { this.ColumnNames = value; }
    87     }
    88     IEnumerable<string> IStringConvertibleMatrix.RowNames {
    89       get { return this.RowNames; }
    90       set { this.RowNames = value; }
    91     }
    92     bool IStringConvertibleMatrix.SortableView {
    93       get { return this.SortableView; }
    94       set { this.SortableView = value; }
    95     }
    9687    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    9788      return Validate(value, out errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/BoolValue.cs

    r3376 r3430  
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
     44      clone.readOnly = readOnly;
    4445      return clone;
    4546    }
  • trunk/sources/HeuristicLab.Data/3.3/Comparison.cs

    r3376 r3430  
    4141      cloner.RegisterClonedObject(this, clone);
    4242      clone.ReadOnlyView = ReadOnlyView;
     43      clone.readOnly = readOnly;
    4344      return clone;
    4445    }
  • trunk/sources/HeuristicLab.Data/3.3/DateTimeValue.cs

    r3376 r3430  
    3636      cloner.RegisterClonedObject(this, clone);
    3737      clone.ReadOnlyView = ReadOnlyView;
     38      clone.readOnly = readOnly;
    3839      return clone;
    3940    }
  • trunk/sources/HeuristicLab.Data/3.3/DoubleArray.cs

    r3376 r3430  
    3737      cloner.RegisterClonedObject(this, clone);
    3838      clone.ReadOnlyView = ReadOnlyView;
     39      clone.readOnly = readOnly;
    3940      return clone;
    4041    }
  • trunk/sources/HeuristicLab.Data/3.3/DoubleMatrix.cs

    r3376 r3430  
    3939
    4040    public override IDeepCloneable Clone(Cloner cloner) {
    41       DoubleMatrix clone = new DoubleMatrix(matrix);
     41      DoubleMatrix clone = new DoubleMatrix();
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
    44       clone.ColumnNames = new List<string>(ColumnNames);
    45       clone.RowNames = new List<string>(RowNames);
     44      clone.matrix = (double[,])matrix.Clone();
     45      clone.columnNames = new List<string>(columnNames);
     46      clone.rowNames = new List<string>(rowNames);
     47      clone.sortableView = sortableView;
     48      clone.readOnly = readOnly;
    4649      return clone;
    4750    }
     
    8285      set { Columns = value; }
    8386    }
    84     IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    85       get { return this.ColumnNames; }
    86       set { this.ColumnNames = value; }
    87     }
    88     IEnumerable<string> IStringConvertibleMatrix.RowNames {
    89       get { return this.RowNames; }
    90       set { this.RowNames = value; }
    91     }
    92     bool IStringConvertibleMatrix.SortableView {
    93       get { return this.SortableView; }
    94       set { this.SortableView = value; }
    95     }
    9687    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    9788      return Validate(value, out errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/DoubleValue.cs

    r3376 r3430  
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
     44      clone.readOnly = readOnly;
    4445      return clone;
    4546    }
  • trunk/sources/HeuristicLab.Data/3.3/IStringConvertibleArray.cs

    r3370 r3430  
    2727    int Length { get; set; }
    2828
     29    bool ReadOnly { get; }
     30
    2931    bool Validate(string value, out string errorMessage);
    3032    string GetValue(int index);
  • trunk/sources/HeuristicLab.Data/3.3/IStringConvertibleMatrix.cs

    r3370 r3430  
    3232
    3333    bool SortableView { get; set; }
     34    bool ReadOnly { get; }
    3435
    3536    bool Validate(string value, out string errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/IStringConvertibleValue.cs

    r3370 r3430  
    2525namespace HeuristicLab.Data {
    2626  public interface IStringConvertibleValue : IContent {
     27    bool ReadOnly { get; }
     28
    2729    bool Validate(string value, out string errorMessage);
    2830    string GetValue();
  • trunk/sources/HeuristicLab.Data/3.3/IntArray.cs

    r3376 r3430  
    3737      cloner.RegisterClonedObject(this, clone);
    3838      clone.ReadOnlyView = ReadOnlyView;
     39      clone.readOnly = readOnly;
    3940      return clone;
    4041    }
  • trunk/sources/HeuristicLab.Data/3.3/IntMatrix.cs

    r3376 r3430  
    3939
    4040    public override IDeepCloneable Clone(Cloner cloner) {
    41       IntMatrix clone = new IntMatrix(matrix);
     41      IntMatrix clone = new IntMatrix();
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
    44       clone.ColumnNames = new List<string>(ColumnNames);
    45       clone.RowNames = new List<string>(RowNames);
     44      clone.matrix = (int[,])matrix.Clone();
     45      clone.columnNames = new List<string>(columnNames);
     46      clone.rowNames = new List<string>(rowNames);
     47      clone.sortableView = sortableView;
     48      clone.readOnly = readOnly;
    4649      return clone;
    4750    }
     
    8285      set { Columns = value; }
    8386    }
    84     IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    85       get { return this.ColumnNames; }
    86       set { this.ColumnNames = value; }
    87     }
    88     IEnumerable<string> IStringConvertibleMatrix.RowNames {
    89       get { return this.RowNames; }
    90       set { this.RowNames = value; }
    91     }
    9287    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    9388      return Validate(value, out errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/IntValue.cs

    r3376 r3430  
    4242      cloner.RegisterClonedObject(this, clone);
    4343      clone.ReadOnlyView = ReadOnlyView;
     44      clone.readOnly = readOnly;
    4445      return clone;
    4546    }
  • trunk/sources/HeuristicLab.Data/3.3/PercentValue.cs

    r3402 r3430  
    3636      cloner.RegisterClonedObject(this, clone);
    3737      clone.ReadOnlyView = ReadOnlyView;
     38      clone.readOnly = readOnly;
    3839      return clone;
    3940    }
  • trunk/sources/HeuristicLab.Data/3.3/StringArray.cs

    r3317 r3430  
    4444      get { return array.Length; }
    4545      protected set {
     46        if (ReadOnly) throw new NotSupportedException("Length cannot be set. StringArray is read-only.");
    4647        if (value != Length) {
    4748          Array.Resize<string>(ref array, value);
     
    5354      get { return array[index]; }
    5455      set {
     56        if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringArray is read-only.");
    5557        if (value != array[index]) {
    5658          if ((value != null) || (array[index] != string.Empty)) {
     
    6264    }
    6365
     66    [Storable]
     67    protected bool readOnly;
     68    public virtual bool ReadOnly {
     69      get { return readOnly; }
     70    }
     71
    6472    public StringArray() {
    6573      array = new string[0];
     74      readOnly = false;
    6675    }
    6776    public StringArray(int length) {
     
    6978      for (int i = 0; i < array.Length; i++)
    7079        array[i] = string.Empty;
     80      readOnly = false;
    7181    }
    7282    public StringArray(string[] elements) {
     
    7585      for (int i = 0; i < array.Length; i++)
    7686        array[i] = elements[i] == null ? string.Empty : elements[i];
     87      readOnly = false;
    7788    }
    7889
     
    8293      clone.ReadOnlyView = ReadOnlyView;
    8394      clone.array = (string[])array.Clone();
     95      clone.readOnly = readOnly;
    8496      return clone;
     97    }
     98
     99    public virtual StringArray AsReadOnly() {
     100      StringArray readOnlyStringArray = (StringArray)this.Clone();
     101      readOnlyStringArray.readOnly = true;
     102      return readOnlyStringArray;
    85103    }
    86104
     
    97115    }
    98116
    99     public IEnumerator<string> GetEnumerator() {
     117    public virtual IEnumerator<string> GetEnumerator() {
    100118      return array.Cast<string>().GetEnumerator();
    101119    }
    102120
    103121    IEnumerator IEnumerable.GetEnumerator() {
    104       return array.GetEnumerator();
     122      return GetEnumerator();
    105123    }
    106124
  • trunk/sources/HeuristicLab.Data/3.3/StringMatrix.cs

    r3320 r3430  
    3333  [Item("StringMatrix", "Represents a matrix of strings.")]
    3434  [StorableClass]
    35   public class StringMatrix : Item, IEnumerable, IStringConvertibleMatrix {
     35  public class StringMatrix : Item, IEnumerable<string>, IStringConvertibleMatrix {
    3636    public override Image ItemImage {
    3737      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
     
    4242
    4343    [Storable]
    44     private List<string> columnNames;
    45     public IEnumerable<string> ColumnNames {
     44    protected List<string> columnNames;
     45    public virtual IEnumerable<string> ColumnNames {
    4646      get { return this.columnNames; }
    4747      set {
     48        if (ReadOnly) throw new NotSupportedException("ColumnNames cannot be set. StringMatrix is read-only.");
    4849        if (value == null || value.Count() == 0)
    4950          columnNames = new List<string>();
     
    5556    }
    5657    [Storable]
    57     private List<string> rowNames;
    58     public IEnumerable<string> RowNames {
     58    protected List<string> rowNames;
     59    public virtual IEnumerable<string> RowNames {
    5960      get { return this.rowNames; }
    6061      set {
     62        if (ReadOnly) throw new NotSupportedException("RowNames cannot be set. StringMatrix is read-only.");
    6163        if (value == null || value.Count() == 0)
    6264          rowNames = new List<string>();
     
    6870    }
    6971    [Storable]
    70     private bool sortableView;
    71     public bool SortableView {
     72    protected bool sortableView;
     73    public virtual bool SortableView {
    7274      get { return sortableView; }
    7375      set {
     76        if (ReadOnly) throw new NotSupportedException("SortableView cannot be set. StringMatrix is read-only.");
    7477        if (value != sortableView) {
    7578          sortableView = value;
     
    8285      get { return matrix.GetLength(0); }
    8386      protected set {
     87        if (ReadOnly) throw new NotSupportedException("Rows cannot be set. StringMatrix is read-only.");
    8488        if (value != Rows) {
    8589          string[,] newMatrix = new string[value, Columns];
     
    97101      get { return matrix.GetLength(1); }
    98102      protected set {
     103        if (ReadOnly) throw new NotSupportedException("Columns cannot be set. StringMatrix is read-only.");
    99104        if (value != Columns) {
    100105          string[,] newMatrix = new string[Rows, value];
     
    113118      get { return matrix[rowIndex, columnIndex]; }
    114119      set {
     120        if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringMatrix is read-only.");
    115121        if (value != matrix[rowIndex, columnIndex]) {
    116122          if ((value != null) || (matrix[rowIndex, columnIndex] != string.Empty)) {
     
    122128    }
    123129
     130    [Storable]
     131    protected bool readOnly;
     132    public virtual bool ReadOnly {
     133      get { return readOnly; }
     134    }
     135
    124136    public StringMatrix() {
    125137      matrix = new string[0, 0];
     
    127139      rowNames = new List<string>();
    128140      sortableView = false;
     141      readOnly = false;
    129142    }
    130143    public StringMatrix(int rows, int columns) {
     
    137150      rowNames = new List<string>();
    138151      sortableView = false;
     152      readOnly = false;
    139153    }
    140154    protected StringMatrix(int rows, int columns, IEnumerable<string> columnNames)
     
    156170      rowNames = new List<string>();
    157171      sortableView = false;
     172      readOnly = false;
    158173    }
    159174    protected StringMatrix(string[,] elements, IEnumerable<string> columnNames)
     
    170185      cloner.RegisterClonedObject(this, clone);
    171186      clone.ReadOnlyView = ReadOnlyView;
    172       clone.SortableView = SortableView;
    173187      clone.matrix = (string[,])matrix.Clone();
    174188      clone.columnNames = new List<string>(columnNames);
    175189      clone.rowNames = new List<string>(rowNames);
     190      clone.sortableView = sortableView;
     191      clone.readOnly = readOnly;
    176192      return clone;
     193    }
     194
     195    public virtual StringMatrix AsReadOnly() {
     196      StringMatrix readOnlyStringMatrix = (StringMatrix)this.Clone();
     197      readOnlyStringMatrix.readOnly = true;
     198      return readOnlyStringMatrix;
    177199    }
    178200
     
    192214    }
    193215
    194     public virtual IEnumerator GetEnumerator() {
    195       return matrix.GetEnumerator();
     216    public virtual IEnumerator<string> GetEnumerator() {
     217      return matrix.Cast<string>().GetEnumerator();
     218    }
     219
     220    IEnumerator IEnumerable.GetEnumerator() {
     221      return GetEnumerator();
    196222    }
    197223
     
    257283      set { Columns = value; }
    258284    }
    259     IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    260       get { return this.ColumnNames; }
    261       set { this.ColumnNames = value; }
    262     }
    263     IEnumerable<string> IStringConvertibleMatrix.RowNames {
    264       get { return this.RowNames; }
    265       set { this.RowNames = value; }
    266     }
    267     bool IStringConvertibleMatrix.SortableView {
    268       get { return this.SortableView; }
    269       set { this.SortableView = value; }
    270     }
    271285    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    272286      return Validate(value, out errorMessage);
  • trunk/sources/HeuristicLab.Data/3.3/StringValue.cs

    r3376 r3430  
    3939      get { return value; }
    4040      set {
     41        if (ReadOnly) throw new NotSupportedException("Value cannot be set. StringValue is read-only.");
    4142        if (value != this.value) {
    4243          if ((value != null) || (this.value != string.Empty)) {
     
    4849    }
    4950
     51    [Storable]
     52    protected bool readOnly;
     53    public virtual bool ReadOnly {
     54      get { return readOnly; }
     55    }
     56
    5057    public StringValue() {
    5158      this.value = string.Empty;
     59      this.readOnly = false;
    5260    }
    5361    public StringValue(string value) {
    5462      this.value = value != null ? value : string.Empty;
     63      this.readOnly = false;
    5564    }
    5665
     
    5968      cloner.RegisterClonedObject(this, clone);
    6069      clone.ReadOnlyView = ReadOnlyView;
     70      clone.readOnly = readOnly;
    6171      return clone;
     72    }
     73
     74    public virtual StringValue AsReadOnly() {
     75      StringValue readOnlyStringValue = (StringValue)this.Clone();
     76      readOnlyStringValue.readOnly = true;
     77      return readOnlyStringValue;
    6278    }
    6379
  • trunk/sources/HeuristicLab.Data/3.3/TimeSpanValue.cs

    r3376 r3430  
    3737      cloner.RegisterClonedObject(this, clone);
    3838      clone.ReadOnlyView = ReadOnlyView;
     39      clone.readOnly = readOnly;
    3940      return clone;
    4041    }
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r3306 r3430  
    2222using System;
    2323using System.Collections;
     24using System.Collections.Generic;
    2425using System.Drawing;
     26using System.Linq;
    2527using System.Text;
    2628using HeuristicLab.Common;
     
    3133  [Item("ValueTypeArray<T>", "An abstract base class for representing arrays of value types.")]
    3234  [StorableClass]
    33   public abstract class ValueTypeArray<T> : Item, IEnumerable where T : struct {
     35  public abstract class ValueTypeArray<T> : Item, IEnumerable<T> where T : struct {
    3436    public override Image ItemImage {
    3537      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
     
    4244      get { return array.Length; }
    4345      protected set {
     46        if (ReadOnly) throw new NotSupportedException("Length cannot be set. ValueTypeArray is read-only.");
    4447        if (value != Length) {
    4548          Array.Resize<T>(ref array, value);
     
    5154      get { return array[index]; }
    5255      set {
     56        if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    5357        if (!value.Equals(array[index])) {
    5458          array[index] = value;
     
    5862    }
    5963
     64    [Storable]
     65    protected bool readOnly;
     66    public virtual bool ReadOnly {
     67      get { return readOnly; }
     68    }
     69
    6070    protected ValueTypeArray() {
    6171      array = new T[0];
     72      readOnly = false;
    6273    }
    6374    protected ValueTypeArray(int length) {
    6475      array = new T[length];
     76      readOnly = false;
    6577    }
    6678    protected ValueTypeArray(T[] elements) {
    6779      if (elements == null) throw new ArgumentNullException();
    6880      array = (T[])elements.Clone();
     81      readOnly = false;
    6982    }
    7083
     
    7285      ValueTypeArray<T> clone = (ValueTypeArray<T>)base.Clone(cloner);
    7386      clone.array = (T[])array.Clone();
     87      clone.readOnly = readOnly;
    7488      return clone;
     89    }
     90
     91    public virtual ValueTypeArray<T> AsReadOnly() {
     92      ValueTypeArray<T> readOnlyValueTypeArray = (ValueTypeArray<T>)this.Clone();
     93      readOnlyValueTypeArray.readOnly = true;
     94      return readOnlyValueTypeArray;
    7595    }
    7696
     
    87107    }
    88108
    89     public virtual IEnumerator GetEnumerator() {
    90       return array.GetEnumerator();
     109    public virtual IEnumerator<T> GetEnumerator() {
     110      return array.Cast<T>().GetEnumerator();
     111    }
     112
     113    IEnumerator IEnumerable.GetEnumerator() {
     114      return GetEnumerator();
    91115    }
    92116
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeMatrix.cs

    r3320 r3430  
    3333  [Item("ValueTypeMatrix<T>", "An abstract base class for representing matrices of value types.")]
    3434  [StorableClass]
    35   public abstract class ValueTypeMatrix<T> : Item, IEnumerable where T : struct {
     35  public abstract class ValueTypeMatrix<T> : Item, IEnumerable<T> where T : struct {
    3636    public override Image ItemImage {
    3737      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
     
    4242
    4343    [Storable]
    44     private List<string> columnNames;
    45     public IEnumerable<string> ColumnNames {
     44    protected List<string> columnNames;
     45    public virtual IEnumerable<string> ColumnNames {
    4646      get { return this.columnNames; }
    4747      set {
     48        if (ReadOnly) throw new NotSupportedException("ColumnNames cannot be set. ValueTypeMatrix is read-only.");
    4849        if (value == null || value.Count() == 0)
    4950          columnNames = new List<string>();
     
    5556    }
    5657    [Storable]
    57     private List<string> rowNames;
    58     public IEnumerable<string> RowNames {
     58    protected List<string> rowNames;
     59    public virtual IEnumerable<string> RowNames {
    5960      get { return this.rowNames; }
    6061      set {
     62        if (ReadOnly) throw new NotSupportedException("RowNames cannot be set. ValueTypeMatrix is read-only.");
    6163        if (value == null || value.Count() == 0)
    6264          rowNames = new List<string>();
     
    6870    }
    6971    [Storable]
    70     private bool sortableView;
    71     public bool SortableView {
     72    protected bool sortableView;
     73    public virtual bool SortableView {
    7274      get { return sortableView; }
    7375      set {
     76        if (ReadOnly) throw new NotSupportedException("SortableView cannot be set. ValueTypeMatrix is read-only.");
    7477        if (value != sortableView) {
    7578          sortableView = value;
     
    8285      get { return matrix.GetLength(0); }
    8386      protected set {
     87        if (ReadOnly) throw new NotSupportedException("Rows cannot be set. ValueTypeMatrix is read-only.");
    8488        if (value != Rows) {
    8589          T[,] newArray = new T[value, Columns];
     
    97101      get { return matrix.GetLength(1); }
    98102      protected set {
     103        if (ReadOnly) throw new NotSupportedException("Columns cannot be set. ValueTypeMatrix is read-only.");
    99104        if (value != Columns) {
    100105          T[,] newArray = new T[Rows, value];
     
    113118      get { return matrix[rowIndex, columnIndex]; }
    114119      set {
     120        if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeMatrix is read-only.");
    115121        if (!value.Equals(matrix[rowIndex, columnIndex])) {
    116122          matrix[rowIndex, columnIndex] = value;
     
    118124        }
    119125      }
     126    }
     127
     128    [Storable]
     129    protected bool readOnly;
     130    public virtual bool ReadOnly {
     131      get { return readOnly; }
    120132    }
    121133
     
    125137      rowNames = new List<string>();
    126138      sortableView = false;
     139      readOnly = false;
    127140    }
    128141    protected ValueTypeMatrix(int rows, int columns) {
     
    131144      rowNames = new List<string>();
    132145      sortableView = false;
     146      readOnly = false;
    133147    }
    134148    protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames)
     
    136150      ColumnNames = columnNames;
    137151    }
    138     protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames,IEnumerable<string> rowNames)
     152    protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames)
    139153      : this(rows, columns, columnNames) {
    140154      RowNames = rowNames;
     
    146160      rowNames = new List<string>();
    147161      sortableView = false;
     162      readOnly = false;
    148163    }
    149164    protected ValueTypeMatrix(T[,] elements, IEnumerable<string> columnNames)
     
    158173    public override IDeepCloneable Clone(Cloner cloner) {
    159174      ValueTypeMatrix<T> clone = (ValueTypeMatrix<T>)base.Clone(cloner);
    160       clone.SortableView = SortableView;
    161175      clone.matrix = (T[,])matrix.Clone();
    162176      clone.columnNames = new List<string>(columnNames);
    163177      clone.rowNames = new List<string>(rowNames);
     178      clone.sortableView = sortableView;
     179      clone.readOnly = readOnly;
    164180      return clone;
     181    }
     182
     183    public virtual ValueTypeMatrix<T> AsReadOnly() {
     184      ValueTypeMatrix<T> readOnlyValueTypeMatrix = (ValueTypeMatrix<T>)this.Clone();
     185      readOnlyValueTypeMatrix.readOnly = true;
     186      return readOnlyValueTypeMatrix;
    165187    }
    166188
     
    180202    }
    181203
    182     public virtual IEnumerator GetEnumerator() {
    183       return matrix.GetEnumerator();
     204    public virtual IEnumerator<T> GetEnumerator() {
     205      return matrix.Cast<T>().GetEnumerator();
     206    }
     207
     208    IEnumerator IEnumerable.GetEnumerator() {
     209      return GetEnumerator();
    184210    }
    185211
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeValue.cs

    r3376 r3430  
    3939      get { return value; }
    4040      set {
     41        if (ReadOnly) throw new NotSupportedException("Value cannot be set. ValueTypeValue is read-only.");
    4142        if (!value.Equals(this.value)) {
    4243          this.value = value;
     
    4647    }
    4748
     49    [Storable]
     50    protected bool readOnly;
     51    public virtual bool ReadOnly {
     52      get { return readOnly; }
     53    }
     54
    4855    protected ValueTypeValue() {
    4956      this.value = default(T);
     57      this.readOnly = false;
    5058    }
    5159    protected ValueTypeValue(T value) {
    5260      this.value = value;
     61      this.readOnly = false;
    5362    }
    5463
     
    5665      ValueTypeValue<T> clone = (ValueTypeValue<T>)base.Clone(cloner);
    5766      clone.value = value;
     67      clone.readOnly = readOnly;
    5868      return clone;
     69    }
     70
     71    public virtual ValueTypeValue<T> AsReadOnly() {
     72      ValueTypeValue<T> readOnlyValueTypeValue = (ValueTypeValue<T>)this.Clone();
     73      readOnlyValueTypeValue.readOnly = true;
     74      return readOnlyValueTypeValue;
    5975    }
    6076
  • trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVector.cs

    r3376 r3430  
    4646      cloner.RegisterClonedObject(this, clone);
    4747      clone.ReadOnlyView = ReadOnlyView;
     48      clone.readOnly = readOnly;
    4849      return clone;
    4950    }
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs

    r3376 r3430  
    4646      cloner.RegisterClonedObject(this, clone);
    4747      clone.ReadOnlyView = ReadOnlyView;
     48      clone.readOnly = readOnly;
    4849      return clone;
    4950    }
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Permutation.cs

    r3376 r3430  
    6767      cloner.RegisterClonedObject(this, clone);
    6868      clone.ReadOnlyView = ReadOnlyView;
     69      clone.readOnly = readOnly;
    6970      return clone;
    7071    }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVector.cs

    r3376 r3430  
    4646      cloner.RegisterClonedObject(this, clone);
    4747      clone.ReadOnlyView = ReadOnlyView;
     48      clone.readOnly = readOnly;
    4849      return clone;
    4950    }
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3377 r3430  
    151151      get { return true; }
    152152      set { throw new NotSupportedException(); }
     153    }
     154    public bool ReadOnly {
     155      get { return false; }
    153156    }
    154157
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Dataset.cs

    r3377 r3430  
    291291    }
    292292
     293    public bool ReadOnly {
     294      get { return false; }
     295    }
     296
    293297    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    294298      get { return this.VariableNames; }
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs

    r3376 r3430  
    6868              dm[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]);
    6969          }
    70           DistanceMatrixParameter.ActualValue = dm;
     70          DistanceMatrixParameter.ActualValue = (DoubleMatrix)dm.AsReadOnly();
    7171        }
    7272
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r3340 r3430  
    168168    public override IDeepCloneable Clone(Cloner cloner) {
    169169      TravelingSalesmanProblem clone = (TravelingSalesmanProblem)base.Clone(cloner);
     170      clone.DistanceMatrixParameter.Value = DistanceMatrixParameter.Value;
    170171      clone.Initialize();
    171172      return clone;
Note: See TracChangeset for help on using the changeset viewer.